Large Language Models (LLMs) are widely used for automated code generation. Their reliance on infrequently updated pretraining data leaves them unaware of newly discovered vulnerabilities and evolving security standards, making them prone to producing insecure code. In contrast, developer communities on Stack Overflow (SO) provide an ever-evolving repository of knowledge, where security vulnerabilities are actively discussed and addressed through collective expertise. These community-driven insights remain largely untapped by LLMs. This paper introduces SOSecure, a Retrieval-Augmented Generation (RAG) system that leverages the collective security expertise found in SO discussions to improve the security of LLM-generated code. We build a security-focused knowledge base by extracting SO answers and comments that explicitly identify vulnerabilities. Unlike common uses of RAG, SOSecure triggers after code has been generated to find discussions that identify flaws in similar code. These are used in a prompt to an LLM to consider revising the code. Evaluation across three datasets (SALLM, LLMSecEval, and LMSys) show that SOSecure achieves strong fix rates of 71.7%, 91.3%, and 96.7% respectively, compared to prompting GPT-4 without relevant discussions (49.1%, 56.5%, and 37.5%), and outperforms multiple other baselines. SOSecure operates as a language-agnostic complement to existing LLMs, without requiring retraining or fine-tuning, making it easy to deploy. Our results underscore the importance of maintaining active developer forums, which have dropped substantially in usage with LLM adoptions.


翻译:大型语言模型(LLM)被广泛用于自动化代码生成。然而,它们依赖于更新频率较低的预训练数据,导致其无法及时了解新发现的漏洞和不断演进的安全标准,从而容易生成不安全的代码。相比之下,Stack Overflow(SO)上的开发者社区提供了一个持续演进的知识库,其中通过集体专业知识积极讨论和解决安全漏洞问题。这些社区驱动的洞见在很大程度上尚未被LLM所利用。本文介绍了SOSecure,一个检索增强生成(RAG)系统,它利用SO讨论中蕴含的集体安全专业知识来提升LLM生成代码的安全性。我们通过提取明确识别漏洞的SO答案和评论,构建了一个专注于安全的知识库。与RAG的常见用法不同,SOSecure在代码生成后触发,以查找识别类似代码缺陷的讨论。这些信息被整合到提示中,供LLM参考以考虑修订代码。在三个数据集(SALLM、LLMSecEval和LMSys)上的评估表明,SOSecure分别实现了71.7%、91.3%和96.7%的高修复率,而相比之下,在没有相关讨论的情况下直接提示GPT-4的修复率仅为49.1%、56.5%和37.5%,并且SOSecure的表现优于多个其他基线方法。SOSecure作为现有LLM的语言无关补充,无需重新训练或微调,易于部署。我们的结果强调了维护活跃开发者论坛的重要性,尽管随着LLM的采用,这些论坛的使用量已大幅下降。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
生成式人工智能大型语言模型的安全性:概述
专知会员服务
35+阅读 · 2024年7月30日
《大型语言模型代码生成》综述
专知会员服务
70+阅读 · 2024年6月4日
高效的文本生成方法 — LaserTagger 现已开源
TensorFlow
30+阅读 · 2020年2月27日
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
6+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
VIP会员
最新内容
Palantir AIP平台:连接智能体与决策
专知会员服务
4+阅读 · 今天1:22
《美海军软件测试战略》90页slides
专知会员服务
6+阅读 · 今天1:00
面向具身智能与机器人仿真的三维生成:综述
专知会员服务
6+阅读 · 4月30日
相关基金
国家自然科学基金
4+阅读 · 2017年12月31日
国家自然科学基金
18+阅读 · 2017年12月31日
国家自然科学基金
6+阅读 · 2017年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
31+阅读 · 2015年12月31日
国家自然科学基金
2+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员