arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2510.22944cs.CRcs.AI
收藏

你的提示污染代码了吗?缺陷诱导率与安全缓解策略

Is Your Prompt Poisoning Code? Defect Induction Rates and Security Mitigation Strategies

Organization(机构)

Bin Wang, YiLu Zhong, MiDi Wan, WenJie Yu, YuanBing Ouyang, Yenan Huang, Hui Li

AI总结:

研究探讨了低质量提示对生成代码安全性的负面影响,提出评估框架和基准数据集,并展示高级提示技术可缓解安全风险。

摘要:

大型语言模型(LLMs)已成为自动化代码生成不可或缺的工具,但其输出质量和安全性仍受关注。现有研究多集中于对抗攻击或模型固有缺陷,而本文关注良性但表述不佳的提示对生成代码安全性的潜在影响。我们提出包含目标清晰度、信息完整性和逻辑一致性三个维度的评估框架,并构建并公开发布CWE-BENCH-PYTHON基准数据集,包含四个规范性等级(L0-L3)的任务。对多个先进LLMs的实验表明,随着提示规范性降低,生成不安全代码的可能性显著增加。进一步表明,链式推理和自我校正等高级提示技术可有效缓解低质量提示带来的安全风险,显著提升代码安全性。研究发现,提升用户提示质量是增强AI生成代码安全性的关键有效策略。

英文摘要:

Large language models (LLMs) have become indispensable for automated code generation, yet the quality and security of their outputs remain a critical concern. Existing studies predominantly concentrate on adversarial attacks or inherent flaws within the models. However, a more prevalent yet underexplored issue concerns how the quality of a benign but poorly formulated prompt affects the security of the generated code. To investigate this, we first propose an evaluation framework for prompt quality encompassing three key dimensions: goal clarity, information completeness, and logical consistency. Based on this framework, we construct and publicly release CWE-BENCH-PYTHON, a large-scale benchmark dataset containing tasks with prompts categorized into four distinct levels of normativity (L0-L3). Extensive experiments on multiple state-of-the-art LLMs reveal a clear correlation: as prompt normativity decreases, the likelihood of generating insecure code consistently and markedly increases. Furthermore, we demonstrate that advanced prompting techniques, such as Chain-of-Thought and Self-Correction, effectively mitigate the security risks introduced by low-quality prompts, substantially improving code safety. Our findings highlight that enhancing the quality of user prompts constitutes a critical and effective strategy for strengthening the security of AI-generated code.

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

↑