AI-based code generators have become pivotal in assisting developers in writing software starting from natural language (NL). However, they are trained on large amounts of data, often collected from unsanitized online sources (e.g., GitHub, HuggingFace). As a consequence, AI models become an easy target for data poisoning, i.e., an attack that injects malicious samples into the training data to generate vulnerable code. To address this threat, we investigate the security of AI code generators by devising a targeted data poisoning strategy. We poison the training data by injecting increasing amounts of code containing security vulnerabilities and assess the attack's success on different state-of-the-art models for code generation. Our study shows that AI code generators are vulnerable to even a small amount of poison. Notably, the attack success strongly depends on the model architecture and poisoning rate, whereas it is not influenced by the type of vulnerabilities. Moreover, since the attack does not impact the correctness of code generated by pre-trained models, it is hard to detect. Lastly, our work offers practical insights into understanding and potentially mitigating this threat.
翻译:基于人工智能的代码生成器已成为协助开发者从自然语言(NL)出发编写软件的关键工具。然而,这些模型依赖于海量数据进行训练,而这些数据通常来自未经处理的在线来源(如GitHub、HuggingFace)。因此,AI模型容易成为数据投毒攻击的目标——即通过向训练数据中注入恶意样本,诱使模型生成存在漏洞的代码。为应对这一威胁,我们通过设计一种定向数据投毒策略,探究了AI代码生成器的安全性。我们向训练数据中注入含有安全漏洞的代码样本,并逐步增加注入量,评估该攻击对多种最先进的代码生成模型的效果。研究表明,AI代码生成器极易受到即使是少量投毒样本的攻击。值得注意的是,攻击成效在很大程度上取决于模型架构和投毒率,而非漏洞类型。此外,由于该攻击不影响预训练模型所生成代码的正确性,因此难以被察觉。最后,我们的工作为理解并潜在缓解这一威胁提供了实践性见解。