arXiv:2608.16187cs.CRcs.AI2026-08

自动化检测修复AI生成代码漏洞,结合威胁情报提升安全性。

Securing AI-Generated Code: A Just-in-Time Vulnerability Detection and Remediation Pipeline

论文配图:Securing AI-Generated Code: A Just-in-Time Vulnerability Detection and Remediation Pipeline
图 1 · 摘自论文原文
  • 构建端到端安全评估流水线,融合多工具并行扫描与智能修复。
  • 流水线配置P2使漏洞减少最多达69%,显著优于基础版本。
  • 修复虽引入新漏洞(15%-22%),但整体安全性和一致性更优,适合开发者快速集成。

AI辅助开发工具生成的代码存在显著安全漏洞,但缺乏能以开发速度自动检测、增强、修复并验证问题的机制,尤其缺乏基于真实威胁情境的修复方案。本文提出一个自动化安全评估流水线:从LLMSecEval提示生成Python代码,通过CodeQL和Bandit并行扫描漏洞,并由独立的Code Validator LLM进行验证;将验证结果结合MITRE ATT&CK技术、CWE实际案例及Python最佳实践进行增强;再由Code Generation LLM生成修复方案,并重新使用CodeQL和Bandit扫描验证。对比两种配置:仅使用增强验证结果的P1,以及额外接收初始分析结果的P2。在四个Claude模型(Opus 4.8、Sonnet 4.6、Sonnet 5、Haiku 4.5)上运行80次,覆盖26个LLMSecEval提示和9类CWE。P1在所有模型中均降低静态分析发现数,降幅为-9%(Opus 4.8)至-54%(Sonnet 5);P2进一步提升,降幅达-29%(Opus 4.8)至-69%(Haiku 4.5),且对所有模型表现均优于P1。判决一致性平均约81%模态一致,P2略稳定。修复引入新漏洞比例为15%-22%,其中约70%仅新增一处缺陷;P2在三款模型上减少修复“噪声”,唯独Sonnet 5例外。值得注意的是,最佳代码生成模型(Opus 4.8)并非最优流水线表现者,反而是Sonnet 4.6在经过P2修复后达到最低残余漏洞数和最高通过率,表明流水线效能与初稿安全性是两个独立属性。

原文摘要 · Abstract (English)

AI-assisted development tools generate vulnerable code at significant rates, yet few automated mechanisms exist to detect, enrich, fix, and verify security issues at development velocity, particularly ones that ground remediation in real-world threat context. This paper presents an automated security evaluation pipeline that generates Python code from LLMSecEval prompts, scans for vulnerabilities using CodeQL and Bandit in parallel with an independent Code Validator LLM, enriches the Code Validator findings with MITRE ATT&CK techniques, CWE Observed Examples, and Python best practice guidelines, generates fixes via the Code Generation LLM, and re-scans with CodeQL and Bandit to verify outcomes. Two pipeline configurations were evaluated: Pipeline 1 (P1), using enriched Code Validator findings only, and Pipeline 2 (P2), where it additionally receives the initial CodeQL and Bandit findings. Both configurations were run across four Claude models: Opus 4.8, Sonnet 4.6, Sonnet 5, and Haiku 4.5, producing 80 runs against 26 LLMSecEval prompts covering 9 CWE categories. P1 reduced static analyzer findings across all four models, ranging from -9% (Opus 4.8) to -54% (Sonnet 5). P2 deepened these reductions further, ranging from -29% (Opus 4.8) to -69% (Haiku 4.5), with P2 outperforming P1 for every model. Verdict consistency averaged approximately 81% modal agreement across all configurations, with P2 marginally more stable than P1. Remediation introduced new vulnerabilities in 15-22% of cases: roughly 70% involved a single new finding, and P2 reduced churn for three of four models, with Sonnet 5 as the sole exception. Notably, the best Code Generation LLM (Opus 4.8) was not the best pipeline performer, as Sonnet 4.6 produced the lowest residual findings and highest pass rate after P2 remediation, suggesting that pipeline effectiveness and first-draft security are distinct properties.

AI安全代码生成漏洞检测自动化修复

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。