arXiv:2511.09879cs.CRcs.AI2025-11

用无漏洞代码训练模型,能显著减少AI生成代码的安全缺陷

Taught by the Flawed: How Dataset Insecurity Breeds Vulnerable AI Code

  • 用静态分析工具筛选出无漏洞的Python代码作为训练数据
  • 新模型生成代码的安全问题减少47%,功能正确性基本不变
  • 适合关注AI编程助手安全性的开发者和研究者

AI编程助手常生成含基础安全漏洞的代码。训练数据中的漏洞是重要原因。本文通过静态分析工具筛选现有Python语料库,构建仅包含无漏洞函数的可信数据集,并训练两个基于Transformer的模型:一个在过滤后数据上训练,一个在原始数据上训练。评估显示,使用可信数据训练的模型生成代码的安全缺陷减少47%,功能正确性与原模型相当。结果表明,安全的训练数据可有效提升AI编程助手的可靠性,但模型架构与评估方法仍需进一步优化。

原文摘要 · Abstract (English)

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编程安全漏洞训练数据模型可靠性

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。