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编程助手已显示出生成包含基本安全漏洞代码的倾向。尽管开发者最终负责验证和审查此类输出,但提升这些生成代码片段的内在质量仍然至关重要。导致不安全输出的一个关键因素在于构建大型语言模型(LLMs)所用训练数据集中存在的漏洞。为解决此问题,我们提出通过筛选训练数据,仅保留可检测漏洞的代码。在本研究中,我们通过使用静态分析工具过滤现有Python语料库,构建了一个安全数据集,仅保留无漏洞的函数。随后,我们训练了两个基于Transformer的模型:一个在筛选后的数据集上训练,另一个在原始未过滤的数据集上训练。这些模型根据其响应自然语言函数描述所生成代码的正确性和安全性进行了评估。我们的结果表明,在筛选数据集上训练的模型生成的输出具有更少的安全问题,同时保持了相当的功能正确性。这些发现凸显了安全训练数据在提升基于AI的编程助手可靠性方面的重要性,尽管仍需通过模型架构和评估的进一步改进来巩固这些成果。