arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2605.08382cs.CRcs.CLcs.CY
收藏

SecureForge:通过提示优化发现并防止LLM生成代码中的漏洞

SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization

Stanford University(斯坦福大学)

Houjun Liu, Lisa Einstein, John Yang, Joachim Baumann, Duncan Eddy, Christopher D. Manning, Mykel Kochenderfer, Diyi Yang

AI总结:

本文提出SecureForge框架,通过自动化流程发现并减少LLM生成代码中的安全漏洞,提升代码安全性的同时保持单元测试性能,实验显示漏洞减少达48%。

摘要:

LLM代码代理如今能够以空前的规模生成代码,但LLM生成的代码会在没有人类参与的情况下向代码库引入网络安全漏洞。即使前沿模型被明确要求编写安全的生产代码并避免特定弱点,我们发现它们在250个良性编码提示语料库中仍平均有23%的时间产生可验证的漏洞。我们引入SecureForge,一个自动化流程,既能审计前沿模型的安全风险,又能生成受审计影响的安全系统提示,从而减少输出的安全漏洞同时保持单元测试性能。SecureForge首先识别出产生静态可检测漏洞的良性提示,然后使用马尔可夫采样技术将其放大为一个包含多样化场景的大型合成提示语料库,以共同维护错误率和提示多样性。该语料库随后用于迭代优化系统提示以减少输出的安全漏洞。在前沿模型上,SecureForge在单元测试成功率和输出安全性方面实现了统计显著的帕累托改进,输出漏洞减少高达48%。所得到的系统提示能够零样本转移到实际编码代理提示中,且在优化过程中不接触任何真实的用户提示分布。

英文摘要:

LLM coding agents now generate code at an unprecedented scale, yet LLM-generated code introduces cybersecurity vulnerabilities into codebases without human involvement. Even when frontier models are explicitly asked to write secure production code with relevant weaknesses to avoid in context, we find that they still produce verifiable vulnerabilities on average 23% of the time across a corpus of 250 benign coding prompts. We introduce SecureForge, an automated pipeline that both audits security risks of frontier models and produces auditing-informed secure system prompts that reduce output security vulnerabilities while maintaining unit test performance. SecureForge first identifies benign prompts that produce statically detectable vulnerabilities, and then amplifies them into a large synthetic prompt corpus of diverse scenarios using a Markovian sampling technique to jointly maintain error rates and prompt diversity. This corpus is then used to iteratively optimize the system prompts to reduce output security vulnerabilities. On frontier models, SecureForge yields a statistically significant Pareto improvement in both unit test success and output security, with output vulnerabilities reduced by up to 48%. The resulting system prompts transfer zero-shot to in-the-wild coding agent prompts, without any exposure to real user prompt distributions during optimization.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑