arXiv:2602.08422cs.CRcs.AI2026-02

用约束生成替代事后检测,让大模型写出更安全的代码。

LLMs + Security = Trouble

  • 在生成阶段施加安全约束,而非事后检查修复。
  • 扩散式代码模型可实现分层安全控制,兼顾效率与安全性。
  • 适合追求高安全性的开发团队和自动化构建流程。

我们认为,当前利用概率性AI检查器或攻击者来保障由AI生成代码的安全性,本质上是“以火攻火”,无法应对安全漏洞的长尾问题。系统仍可能暴露于零日漏洞之下,尤其面对资源更丰富或更具持续性的攻击者。尽管将大语言模型(LLMs)与形式化方法结合的神经符号方法在理论上吸引人,但其难以融入常见的“直觉编程”工作流:除非端到端验证流程完全自动化,否则开发者需反复验证规格、解决歧义并裁决失败,导致人为介入成为薄弱环节,破坏“安全构建”的保证。本文主张,更强的安全保障应通过在代码生成阶段强制实施安全约束(如受限解码)实现,而非依赖事后检测与修复。这一方向对扩散风格的代码模型尤为有前景,其架构天然支持模块化、分层的安全控制,使低延迟生成技术与安全构建代码得以结合。

原文摘要 · Abstract (English)

We argue that when it comes to producing secure code with AI, the prevailing "fighting fire with fire" approach -- using probabilistic AI-based checkers or attackers to secure probabilistically generated code -- fails to address the long tail of security bugs. As a result, systems may remain exposed to zero-day vulnerabilities that can be discovered by better-resourced or more persistent adversaries. While neurosymbolic approaches that combine LLMs with formal methods are attractive in principle, we argue that they are difficult to reconcile with the "vibe coding" workflow common in LLM-assisted development: unless the end-to-end verification pipeline is fully automated, developers are repeatedly asked to validate specifications, resolve ambiguities, and adjudicate failures, making the human-in-the-loop a likely point of weakness, compromising secure-by-construction guarantees. In this paper we argue that stronger security guarantees can be obtained by enforcing security constraints during code generation (e.g., via constrained decoding), rather than relying solely on post-hoc detection and repair. This direction is particularly promising for diffusion-style code models, whose approach provides a natural elegant opportunity for modular, hierarchical security enforcement, allowing us to combine lower-latency generation techniques with generating secure-by-construction code.

代码安全生成模型约束解码

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