arXiv:2606.25195cs.CRcs.AI2026-06

AI生成代码的安全性有进步,但懂原理却做不好,仍需改进。

SoK: AI Secure Code Generation: Progress, Pitfalls, and Paths Forward

  • 构建三层次框架,评估模型对安全编码的理解与执行能力。
  • 发现模型理解安全原则强,但实际生成代码时仍常出错。
  • 适合关注AI编程安全的开发者与研究者阅读。

AI用于代码生成日益普及,但其生成代码的安全性如何?现有研究探索了提示、微调、强化学习和智能体工作流,但对这些方法提升安全性的机制及失败原因仍缺乏系统理解。本文提出一个三层次框架,衡量模型对安全编码原则的自然语言理解、生成过程中的代码级执行能力,以及两者间的知识-执行差距。在涵盖函数级与全应用级安全的多个基准上评估不同模型与智能体,结果表明:安全原则的理解能力是代码功能正确性、安全性及联合正确性的强预测因子;然而显著的知识-执行差距依然存在——模型能识别安全原则,却无法有效转化为安全且正确的代码。该研究为当前AI安全代码生成的现状提供了以原则为中心的解释,并指明通过原则引导生成、评估、基准测试和智能体工作流等路径推动发展。

原文摘要 · Abstract (English)

The increasing use of AI systems for code generation raises a central security question: what can today's models and coding agents actually do to produce secure code, where do they still fail, and what would move the field forward? Existing work has explored prompting, fine-tuning, reinforcement learning, and agentic workflows for secure code generation, but the field still lacks a systematic understanding of how these techniques improve security and why substantial failures persist. In this SoK, we systematize the progress, pitfalls, and paths forward for AI secure code generation. We introduce a three-level framework that measures models' natural-language understanding of secure coding principles, their code-level actuation of those principles during generation, and the knowledge--actuation gaps between the two. We instantiate this framework across models and coding agents on benchmarks covering both isolated function-level security and full web-application security. Our results show that secure-coding-principle understanding is a statistically strong predictor of code-level outcomes, including functional correctness, security, and joint functional-security correctness. Yet substantial knowledge--actuation gaps remain: models can recognize relevant security principles but still fail to translate them into secure and functional code. These findings offer a principle-centered account of where AI secure code generation stands today and identify concrete paths forward through principle-guided generation, evaluation, benchmarking, and agentic workflows.

代码生成AI安全智能体

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