TL;DR
RealSec-bench is a new evaluation benchmark designed to test whether Large Language Models (LLMs) can generate code that is simultaneously functionally correct and secure within real-world software repositories. Testing five state-of-the-art LLMs reveals a worrying reality: composite success rates (SecurePass@1) sit below 6% across the board, and standard remedies like Retrieval-Augmented Generation (RAG) or security prompting often fail to help or even degrade performance.
What Problem Does This Paper Address?
While LLMs have become remarkably adept at writing code, evaluating their ability to write secure code has been bottlenecked by unrealistic benchmarks. Most existing evaluations suffer from what the authors call the context-isolated phenomenon—they rely on synthetic vulnerabilities or isolated code snippets.
In the real world, security flaws rarely live in a vacuum; they emerge from complex, inter-procedural dataflows that span multiple functions, classes, and files. By ignoring these repository-level dependencies, existing benchmarks oversimplify the problem space and create an inflated perception of an LLM's coding competence while masking critical integration failures and cross-module security risks.
Methods
The authors built a rigorous, multi-stage pipeline to construct RealSec-bench from real-world software, ensuring both high fidelity and practical reproducibility:
- High-Risk Repository Selection: They screened the top 4,000 most-starred Java projects on GitHub, filtering for Maven-based projects, and used CodeQL to run a Static Application Security Testing (SAST) audit to identify 532 high-risk repositories with high vulnerability density.
- Vulnerability Data Collection & Filtering: They extracted over 20,000 raw security findings. To ensure reproducibility, they filtered out any code that didn't compile or lack executable unit tests.
- False Positive Elimination: They used a hybrid workflow combining GPT-4.1 with manual validation by independent security engineers to filter out SAST noise.
- Docstring Rewriting: To prevent data leakage (the model guessing the vulnerability from the prompt), they used LLMs to rewrite Javadoc comments into security-neutral descriptions, which were then verified by professional programmers.
To evaluate the models, they introduced a composite metric called SecurePass@k, which requires a generated code sample to pass all functional unit tests and clear a two-stage security evaluation (CodeQL scan followed by a multi-LLM adjudication panel).
Datasets
The paper introduces RealSec-bench, which consists of:
- 105 instances grounded in 30 real-world Java repositories.
- Coverage across 19 distinct Common Weakness Enumeration (CWE) types (e.g., Log Injection, Path Traversal, Hard-coded Credentials, and Broken Cryptographic Algorithms).
- Complex data flows, including long-tail vulnerabilities featuring up to 34-hop inter-procedural dependencies.
Key Insights and Ideas
- The Functionality-Security Disconnect: Functional correctness does not equal security. Models frequently generate code that perfectly satisfies unit tests but introduces severe vulnerabilities.
- RAG is Not a Security Silver Bullet: While RAG significantly boosts functional correctness (helping code compile and pass tests), it provides negligible security benefits. Interestingly, highly targeted dataflow RAG (which focuses strictly on the vulnerability path) often underperforms compared to broader text-based RAG because it starves the LLM of necessary structural context (like utility functions or class hierarchies).
- The "Security Tax" on Prompts: Explicitly injecting general security guidelines into prompts yields highly unpredictable results. For some models, it slightly improves security; for others (like Claude-3.7-Sonnet), it triggers a severe drop in functional correctness (from 16.2% to 9.5%) because the added constraints cause compilation failures.
Key Results
The authors evaluated five prominent models: Claude-3.7-Sonnet, DeepSeek-V3, Qwen3-235B, GPT-4.1, and GPT-4.1-mini.
- Low Overall Success: The composite
SecurePass@1metric remained below 6% across all tested models. Claude-3.7-Sonnet achieved the highest functional pass rate (Pass@1of 16.19%) but itsSecurePass@1was only 4.76%. - Total Failure in Complex Domains: While models handled localized code quality issues relatively well, they suffered a 0.00% success rate in complex domains like cryptography and web security.
- The Multi-Hop Dropoff: Models performed best on "0-hop" tasks where the vulnerability was entirely local. Performance plummeted when moving to 1-hop tasks, showing that current LLMs struggle to maintain security context across function boundaries.
Limitations and Future Work
The authors acknowledge two primary limitations:
- Internal Validity: The benchmark relies on SAST tools (CodeQL) and LLM judges to evaluate security, which introduces a risk of false positives. Future work will look into incorporating dynamic analysis to enhance verification precision.
- External Validity: RealSec-bench is currently limited to open-source, Maven-based Java repositories. The authors plan to expand their methodology to support a wider range of programming languages, build systems, and proprietary software.
Summary updated