TL;DR
SecRepoBench is a new repository-level benchmark designed to evaluate how well LLMs and AI code agents handle secure code completion in real-world C/C++ codebases. The evaluation reveals that while advanced code agents significantly outperform standalone LLMs, both paradigms still struggle to generate code that is simultaneously functionally correct and secure, often prioritizing functionality over security.
What Problem Does This Paper Address?
AI-powered code assistants (like GitHub Copilot or Cursor) are widely used to automate software development, but they risk introducing critical security vulnerabilities. While many benchmarks exist to evaluate the security of LLM-generated code, they suffer from two major limitations:
- Lack of Dual Testing: Existing repository-level benchmarks evaluate either functional correctness or security, but rarely both on the same dataset. Without checking correctness, we might overestimate a model's security simply because it generated dead or non-functional code.
- Artificial Context Constraints: Previous benchmarks often provide a fixed, pre-retrieved context to the model. In reality, modern code agents can interactively navigate an entire repository to look up definitions and understand project structures.
SecRepoBench addresses these gaps by simulating a realistic developer scenario: a user is writing code in an existing repository, and an agent must complete a function within a security-sensitive region.
Methods
The SecRepoBench framework evaluates code generation by providing the model or agent with a target function containing a masked (empty) region alongside the entire repository context.
To construct high-quality, realistic tasks, the authors implemented a rigorous pipeline:
- Vulnerability Localization: They identified security-sensitive regions using real-world vulnerability-fixing commits.
- AST Masking: Using
tree-sitter, they parsed the abstract syntax tree (AST) to mask the exact code block responsible for the security fix, occasionally adding neighboring non-security nodes to prevent biasing the model toward only writing sanitizers. - Semantic-Preserving Mutation: To prevent models from simply memorizing known patches from their training data, local variables within and around the masked region were renamed using GPT-4o with manual verification.
- Dual-Dimension Evaluation: Once the agent completes the code, the repository is fully compiled. Functional correctness is evaluated using the project's existing developer-written unit tests. Security is evaluated dynamically by running Proof-of-Concept (PoC) exploit inputs from Google's OSS-Fuzz; if the completed code causes a program crash, it is flagged as vulnerable.
Datasets
SecRepoBench is built on top of the ARVO dataset, which contains thousands of reproducible vulnerabilities identified by Google OSS-Fuzz. After filtering for tasks with valid developer-written unit tests and reproducible crashes, the final benchmark consists of 318 code completion tasks across 27 popular GitHub C/C++ repositories, covering 15 Common Weakness Enumerations (CWEs).
The authors compared SecRepoBench against prior state-of-the-art secure code generation benchmarks, highlighting its reliance on realistic developer-written tests rather than synthetic fuzzing inputs or purely manual test cases:
Key Insights and Ideas
- Real Repositories are Significantly Harder: Models that perform exceptionally well on self-contained code generation benchmarks (like BaxBench) see a steep performance drop when faced with real-world repository dependencies. Model rankings also shift, proving that self-contained benchmarks do not accurately predict repository-level performance.
- The "Correctness Bias" of Agents: Integrating LLMs into agent frameworks (like OpenHands or Aider) yields massive performance boosts. However, looking closely at the metrics reveals an alarming trend: agents primarily improve functional correctness rather than security. During their iterative refinement loops, agents focus heavily on passing unit tests, often ignoring underlying security vulnerabilities like missing bounds checks or incorrect memory allocations.
- Reasoning Models Lead the Pack: Standalone reasoning models (e.g., OpenAI o3, GPT-5) dominate the leaderboard compared to standard LLMs. Their extended internal thinking processes allow them to better navigate complex cross-file dependencies and reason about code context.
Key Results
The authors evaluated 29 standalone LLMs and 15 code agent configurations:
- Top Standalone LLM: GPT-5 achieved the highest standalone score with a
secure-pass@1of 39.3%. - Top Agent Setup: OpenHands paired with OpenAI o3 achieved the highest overall performance at 53.5%
secure-pass@1.
- Agent Improvements: On average, agent frameworks improved functional correctness (
pass@1) by 18.3%, but only improved the security percentage by 14.5%, confirming that agents prioritize making code work over making it secure.
- Failure Modes: Even the best agent setups still suffer from basic software engineering hurdles. For instance, OpenHands + OpenAI o3 hit compilation errors in 8.5% of tasks, primarily due to hallucinating non-existent variables/structs or failing to properly link cross-file dependencies.
Limitations and Future Work
While SecRepoBench provides a much-needed reality check for AI code assistants, it has a few limitations:
- Single-Function Focus: The benchmark currently restricts tasks to code completions within a single function. Real-world vulnerability patches often span multiple functions and files.
- CWE Coverage: It covers 17 out of the 20 most common OSS-Fuzz crash types, leaving room to expand to a broader set of vulnerabilities.
- Future Directions: The authors highlight an urgent need to equip code agents with dedicated security tools (like static analyzers or fuzzers) within their execution loops so they can actively debug security flaws alongside functional bugs.
Summary updated