arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.10495cs.SEcs.AI
收藏

大型语言模型作为Python端到端安全代码智能体的表现如何?

How Well Do Large Language Models Serve as End-to-End Secure Code Agents for Python?

School of Computer Science and Engineering, Beihang University(北京航空航天大学计算机科学与工程学院);State Key Laboratory of Software Development Environment(软件开发环境国家重点实验室);Zhongguancun Laboratory(中关村实验室);Tsinghua University(清华大学)

Jianian Gong, Nachuan Duan, Ziheng Tao, Zhaohui Gong, Yuan Yuan, Minlie Huang

AI总结:

本研究系统探究了GPT-3.5、GPT-4等LLM生成安全Python代码的能力,发现其存在安全风险认知不足、自修复盲区等问题,进而开发出带语义分析的迭代修复轻量工具,大幅提升代码安全修复成功率。

摘要:

GPT-4等大型语言模型(LLM)的快速发展彻底改变了软件工程格局,使这些模型成为现代开发实践的核心。随着我们预期这些模型将发展为软件开发中主要且可信赖的工具,确保其生成代码的安全性变得至关重要。LLM作为端到端安全代码生成器的表现究竟如何?本文对LLM生成低漏洞代码的固有潜力展开了系统研究。具体而言,我们研究了GPT-3.5和GPT-4识别并修复四款主流LLM(包括其自身:GPT-3.5、GPT-4、Code Llama和CodeGeeX2)生成代码中漏洞的能力。通过人工或自动审查4900段代码,本研究发现:(1)大型语言模型缺乏对场景相关安全风险的认知,导致其在SecurityEval基准上生成的代码中超过75%存在漏洞;(2)GPT-3.5和GPT-4等LLM无法精准识别自身生成代码中的漏洞;(3)GPT-3.5和GPT-4修复上述4款LLM生成的不安全代码的成功率可达33.2%~59.6%,但二者在修复自身生成的代码时表现均较差,存在自修复“盲区”。为解决单轮修复的局限性,基于本研究得出的洞见,我们开发了一款轻量级工具,通过迭代修复流程引导LLM构建更安全的源代码。实验表明,在语义分析引擎的辅助下,我们的工具将修复成功率显著提升至65.9%~85.5%。

英文摘要:

The rapid advancement of large language models (LLMs) such as GPT-4 has revolutionized the landscape of software engineering, positioning these models at the core of modern development practices. As we anticipate these models to evolve into the primary and trustworthy tools used in software development, ensuring the security of the code they produce becomes paramount. How well can LLMs serve as end-to-end secure code producers? This paper presents a systematic investigation into LLMs' inherent potential to generate code with fewer vulnerabilities. Specifically, We studied GPT-3.5 and GPT-4's capability to identify and repair vulnerabilities in the code generated by four popular LLMs including themselves (GPT-3.5, GPT-4, Code Llama, and CodeGeeX2). By manually or automatically reviewing 4,900 pieces of code, our study reveals that: (1) large language models lack awareness of scenario-relevant security risks, which leads to the generation of over 75% vulnerable code on the SecurityEval benchmark; (2) LLMs such as GPT-3.5 and GPT-4 are unable to precisely identify vulnerabilities in the code they generated; (3) GPT-3.5 and GPT-4 can achieve 33.2%~59.6% success rates in repairing the insecure code produced by the 4 LLMs, but they both perform poorly when repairing self-produced code, indicating self-repair "blind spots". To address the limitation of a single round of repair, we developed a lightweight tool that prompts LLMs to construct safer source code through an iterative repair procedure based on the insights gained from our study. Experiments show that assisted by semantic analysis engines, our tool significantly improves the success rates of repair to 65.9%~85.5%.

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

↑