师从有缺陷者:数据集不安全性如何催生存在漏洞的AI代码
Taught by the Flawed: How Dataset Insecurity Breeds Vulnerable AI Code
AI总结:
针对AI编程助手易生成带安全漏洞代码的问题,本文通过静态分析筛选无漏洞Python代码构建安全训练集,训练对比transformer模型,证实安全训练数据可在不损失功能正确性的前提下减少生成代码的安全问题。
摘要:
AI编程助手已表现出生成包含基础安全漏洞代码的倾向。尽管开发者最终负责验证和审核此类输出,但提升这些生成代码片段的内在质量仍至关重要。导致输出不安全的一个关键因素是,用于构建大语言模型(LLM)的训练数据集中存在漏洞。为解决这一问题,我们提出对训练数据进行筛选,仅纳入无检测到漏洞的代码。本研究中,我们使用静态分析工具对现有Python语料库进行过滤,仅保留无漏洞函数,构建了一个安全数据集。随后我们训练了两个基于transformer的模型:一个使用筛选后的数据集训练,另一个使用原始未过滤数据集训练。我们根据模型响应自然语言函数描述生成代码的正确性和安全性对其进行评估。结果显示,使用筛选后数据集训练的模型生成的输出安全问题更少,同时保持了相当的功能正确性。这些发现凸显了安全训练数据在提升AI编程助手可靠性方面的重要性,不过仍需进一步优化模型架构和评估方法以强化这些成效。
英文摘要:
AI programming assistants have demonstrated a tendency to generate code containing basic security vulnerabilities. While developers are ultimately responsible for validating and reviewing such outputs, improving the inherent quality of these generated code snippets remains essential. A key contributing factor to insecure outputs is the presence of vulnerabilities in the training datasets used to build large language models (LLMs). To address this issue, we propose curating training data to include only code that is free from detectable vulnerabilities. In this study, we constructed a secure dataset by filtering an existing Python corpus using a static analysis tool to retain only vulnerability-free functions. We then trained two transformer-based models: one on the curated dataset and one on the original, unfiltered dataset. The models were evaluated on both the correctness and security of the code they generated in response to natural language function descriptions. Our results show that the model trained on the curated dataset produced outputs with fewer security issues, while maintaining comparable functional correctness. These findings highlight the importance of secure training data in improving the reliability of AI-based programming assistants, though further enhancements to model architecture and evaluation are needed to reinforce these outcomes.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。