用安全宪章提前约束AI生成代码,让漏洞无处可藏。
Constitutional Spec-Driven Development: Enforcing Security by Construction in AI-Assisted Code Generation
- 在需求层嵌入安全规则,代码生成时自动遵守
- 实测减少73%安全缺陷,速度不降
- 适合金融等高安全要求领域的开发团队
AI辅助编程虽提升效率,却因大模型侧重功能正确性而引入严重安全风险。本文提出宪法式规范驱动开发方法,将不可妥协的安全原则写入可机器读取的规范文档中,确保代码从生成起就符合安全要求。该方法基于通用弱点枚举(CWE)和MITRE Top 25漏洞库构建‘宪法’,覆盖10个关键安全漏洞,并实现从原则到代码位置的全程可追溯。以银行微服务系统为案例,涵盖客户管理、账户操作与交易处理,验证其在严格监管环境下的有效性。结果表明,相比传统无约束生成方式,该方法降低73%安全缺陷,同时保持开发者效率。研究贡献包括一套形式化安全框架、完整开发流程及实证证据,证明主动规范优于事后检查。
原文摘要 · Abstract (English)
The proliferation of AI-assisted "vibe coding" enables rapid software development but introduces significant security risks, as Large Language Models (LLMs) prioritize functional correctness over security. We present Constitutional Spec-Driven Development, a methodology that embeds non-negotiable security principles into the specification layer, ensuring AI-generated code adheres to security requirements by construction rather than inspection. Our approach introduces a Constitution: a versioned, machine-readable document encoding security constraints derived from Common Weakness Enumeration (CWE)/MITRE Top 25 vulnerabilities and regulatory frameworks. We demonstrate the methodology through a banking microservices application, selected as a representative example domain due to its stringent regulatory and security requirements, implementing customer management, account operations, and transaction processing. The methodology itself is domain-agnostic. The implementation addresses 10 critical CWE vulnerabilities through constitutional constraints with full traceability from principles to code locations. Our case study shows that constitutional constraints reduce security defects by 73% compared to unconstrained AI generation while maintaining developer velocity. We contribute a formal framework for constitutional security, a complete development methodology, and empirical evidence that proactive security specification outperforms reactive security verification in AI-assisted development workflows.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。