更新更大,但更安全吗?LLM生成代码中功能-安全差距的纵向研究 Newer and Bigger, but Safer? A Longitudinal Study of the Functionality-Security Gap in LLM-Generated Code 预印本

⚠️ 本文为 预印本(arXiv 公开版本),尚未经过正式同行评审。作者自发公开,结论未经期刊审稿验证,阅读时请知悉。
发布时间:2026-10-06
⬇️ 3 次下载
👁️ 预览文献
💡 AI 中文简介
研究追踪了7个模型家族(5个开源)的32个大语言模型,用119个编程任务和31种漏洞类型测试其生成代码的安全性。发现新模型绝对安全性提升,但功能与安全之间的差距并未消除;开源模型差距缩小,而Gemini 3.1 Pro差距仍大;紧凑模型通常更不安全。提醒开发者升级模型后需重跑安全检查。
领域软件工程 / 代码安全与大语言模型
适合谁读需要一定专业背景(软件安全或LLM代码生成领域)
核心贡献首次对7个模型家族(含5个开源)进行跨32个LLM的纵向安全差距分析,覆盖旗舰与紧凑模型;发现开源模型显著缩小差距,而部分闭源模型差距仍大,并揭示同一CWE在不同语言中风险差异显著。
关键数据32个LLM、7个家族、119个任务、5种语言、31种CWE;新模型绝对安全性提升但无家族消除差距;开源家族差距显著缩小;Gemini 3.1 Pro差距与Llama相当;紧凑模型通常更不安全(Gemini 3.7 Flash例外);持续存在日志注入(CWE-117)和HTTP响应拆分(CWE-113)等弱点。
推荐理由如果你以为模型升级就等于更安全,这项研究用32个模型的数据告诉你:不一定,甚至可能更危险。
关键词["大语言模型", "代码生成", "安全漏洞", "功能-安全差距", "纵向研究", "CWE"]

原文摘要

查看英文原文摘要

Large Language Models (LLMs) are widely used to generate code. Although their functional plausibility keeps improving, the generated code often contains security vulnerabilities. The functionality-security gap captures code that passes functional tests but fails security tests. A recent longitudinal study of three model families concluded that LLMs become smarter but not safer, with the only considered open-weight family stagnating. Whether this holds for other (open-weight) families and particularly for compact models remains open. We present a longitudinal study of the gap across 32 LLMs from seven model families (five open-weight), covering three successive releases per family in flagship and compact variants. Using CWEval with 119 tasks in five programming languages and 31 CWEs, we compare trajectories across families, model sizes, and languages. Newer models do become safer in absolute terms, although no family closes the gap. Unlike prior work, we find that openness does not separate the families: every considered open-weight family narrows the gap significantly, while Gemini 3.1 Pro keeps a gap as wide as the one reported for Llama. Compact models usually produce less secure code than their flagship counterparts, with notable exceptions (e.g., Gemini 3.7 Flash). At the CWE level, we confirm persistent weaknesses such as log injection (CWE-117) and HTTP response splitting (CWE-113) and regressions in the newest proprietary models on memory and integer weaknesses, and show that the same CWE carries very different risk across languages. From these results, we derive implications for LLM vendors, researchers, and developers. In particular, developers should assume neither that upgrades improve security nor that proprietary models are more secure; they should rerun security checks after each model change and provide secure APIs in the model's context.