arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2407.07064cs.SEcs.AIcs.CRcs.LG
收藏

安全代码生成的提示技术:一项系统性研究

Prompting Techniques for Secure Code Generation: A Systematic Investigation

Hamburg University of Technology(汉堡工业大学)

Catherine Tony, Nicolás E. Díaz Ferreyra, Markus Mutas, Salem Dhiff, Riccardo Scandariato

AI总结:

本研究系统调查了不同提示技术对LLM生成代码安全性的影响,在GPT-3、GPT-3.5和GPT-4上评估了多种技术,发现递归批评与改进(RCI)能有效减少安全弱点。

摘要:

大型语言模型(LLMs)在软件开发领域正日益受到重视,通过提示驱动编程,开发人员能够根据自然语言(NL)指令生成代码。然而,已有研究对其生成安全代码的能力以及由此产生的提示生成软件的质量提出了质疑。与此同时,各种精心定制提示的提示技术也应运而生,旨在从LLMs中引出最优响应。尽管如此,这些提示策略与安全代码生成之间的相互作用仍未得到充分探索,亟需进一步研究。目的:在本研究中,我们考察了不同提示技术对LLMs根据自然语言指令生成代码的安全性的影响。方法:首先,我们进行了一项系统性文献综述,以识别可用于代码生成任务的现有提示技术。随后,我们在GPT-3、GPT-3.5和GPT-4模型上评估了这些技术中的一部分,用于安全代码生成。为此,我们使用了一个包含150个与安全相关的自然语言代码生成提示的现有数据集。结果:我们的工作(i)对潜在的代码生成提示技术进行了分类,(ii)调整并评估了所识别技术中的一部分用于安全代码生成任务,以及(iii)观察到在测试的LLMs中安全弱点有所减少,尤其是在使用一种名为“递归批评与改进”(RCI)的现有技术之后,为关于LLM生成代码安全性的持续讨论贡献了有价值的见解。

英文摘要:

Large Language Models (LLMs) are gaining momentum in software development with prompt-driven programming enabling developers to create code from natural language (NL) instructions. However, studies have questioned their ability to produce secure code and, thereby, the quality of prompt-generated software. Alongside, various prompting techniques that carefully tailor prompts have emerged to elicit optimal responses from LLMs. Still, the interplay between such prompting strategies and secure code generation remains under-explored and calls for further investigations. OBJECTIVE: In this study, we investigate the impact of different prompting techniques on the security of code generated from NL instructions by LLMs. METHOD: First we perform a systematic literature review to identify the existing prompting techniques that can be used for code generation tasks. A subset of these techniques are evaluated on GPT-3, GPT-3.5, and GPT-4 models for secure code generation. For this, we used an existing dataset consisting of 150 NL security-relevant code-generation prompts. RESULTS: Our work (i) classifies potential prompting techniques for code generation (ii) adapts and evaluates a subset of the identified techniques for secure code generation tasks and (iii) observes a reduction in security weaknesses across the tested LLMs, especially after using an existing technique called Recursive Criticism and Improvement (RCI), contributing valuable insights to the ongoing discourse on LLM-generated code security.

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

↑