NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios

Lixun Ma, Ruolong Ma, Bei Wang, Feng Wei, Zhenguang Liu, Lorenzo Cavallaro, Wentao ChenarXiv 2026

TL;DR

Standard benchmarks evaluate LLM code security using explicit instructions, but real-world developer prompts are often vague, incomplete, or conflicted. This paper introduces a new benchmark based on three realistic risk scenarios and reveals that eight leading LLMs generate vulnerable code over 56% of the time by default. Fortunately, the authors show that "security-aware prompting" can significantly mitigate these risks, reducing vulnerabilities by up to 45%.

What Problem Does This Paper Address?

Most existing code security benchmarks evaluate Large Language Models (LLMs) using the Common Weakness Enumeration (CWE) taxonomy. These benchmarks typically provide explicit security requirements or explicitly mention vulnerabilities in the prompt.

However, real-world software development is messy. Developers often write prompts that are ambiguous, omit critical deployment context, or prioritize fast functionality over secure coding practices. This paper addresses the gap between idealized benchmark assumptions and actual developer behavior by evaluating how LLMs handle implicit security choices under realistic, risk-prone conditions.

Methods

The authors define three representative real-world risk scenarios:

  1. Ambiguous Requirements (SC1): Vague functional specifications where security decisions are implicitly delegated to the LLM (e.g., "implement a login API" without specifying password hashing).
  2. Under-Specified Operational Context (SC2): Prompts that omit deployment details, forcing the LLM to default to potentially insecure or outdated configurations.
  3. Security–Functionality Conflict (SC3): Prompts where the user explicitly requests functionality that conflicts with security best practices (e.g., disabling certificate validation for convenience).

To evaluate these scenarios, they developed a two-round measurement framework:

  • Baseline Round: The LLM generates code using a "risk-inducing prompt" reflecting one of the three scenarios.
  • Mitigation Round: The LLM generates code using a "security-aware prompt" that injects specific safety guidance while preserving the original functional intent.
Fig. 2: Overview of the measurement framework.

Vulnerabilities in the generated code were detected using static analysis tools (like CodeQL and Clang Static Analyzer) paired with an expert review process assisted by GPT-5.

Datasets

The authors constructed a new large-scale benchmark consisting of 2,700 test cases.

  • It spans the 3 risk scenarios across 9 popular programming languages (Python, Java, C++, JavaScript, Go, PHP, SQL, HTML, and Bash).
  • It contains 50 prompt pairs (baseline vs. mitigation) per scenario-language combination.
  • The prompts were curated from real-world sources, including GitHub issues, Stack Overflow posts, and anonymized internal developer logs, supplemented by manual CWE-guided expansions.
Fig. 1: Examples of Ambiguous-Requirement Risk Scenario Prompts.

Key Insights and Ideas

  • LLMs Lack "Security-by-Default": When prompts are ambiguous, LLMs consistently prioritize functional completion over security, leading to high vulnerability rates.
  • Context Omission Breeds Insecurity: Omitted environment details (SC2) frequently cause models to fall back on insecure defaults, such as weak validation or overly permissive file access.
  • The Conflict Dilemma: Scenarios where functionality directly clashes with security (SC3) are the hardest to fix. Forcing security constraints into these prompts can cause "regressions," where the model either breaks the requested functionality or fails to properly implement the security fix.

Key Results

  • High Baseline Vulnerability: Across all eight evaluated models (including frontier models like GPT-5, Claude-Sonnet-4, and Gemini-2.5-Pro), the average baseline vulnerability rate exceeded 56%, peaking at 66% in ambiguous requirement scenarios (SC1).
  • Prompting as a Powerful Shield: Security-aware prompting consistently reduced vulnerabilities. Claude-Sonnet-4 saw the highest vulnerability reduction (45%), while the smaller Qwen3-4B saw the lowest, yet still substantial, improvement (37%).
  • Mitigation Hardness: Security-Functionality Conflicts (SC3) proved highly resistant to prompting fixes, yielding a low Net Safety Gain of just 0.12 and regression rates reaching 19%.
Fig. 3: Overall results of the experimental evaluation. SC1–SC3 correspond to three risk scenarios: SC1 (Ambiguous Requirements), SC2 (Under-Specified Op- erational Context), and SC3 (Security–Functionality Conflict).

Limitations and Future Work

The authors note that their study is limited in its model coverage, the scope of the risk scenarios, and the mitigation techniques explored (focusing primarily on prompt engineering).

For future work, they plan to expand the benchmark to a broader range of LLMs and risk types. They also aim to explore how more advanced intervention techniques—such as Retrieval-Augmented Generation (RAG), fine-tuning, and skill-based model augmentations—can be leveraged to build inherently safer AI coding assistants.

Summary updated

BibTeX
@misc{ma2026poster,
  author = {Lixun Ma and Ruolong Ma and Bei Wang and Feng Wei and Zhenguang Liu and Lorenzo Cavallaro and Wentao Chen},
  title = {{Poster: Rethinking Security in LLM Code Generation through Real-World Risk Scenarios}},
  year = {2026},
  eprint = {2607.23088},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2607.23088},
}
Figure