paperbot · PL 论文追踪

全部论文 待读 收藏

P2 Show Me Your Code! Kill Code Poisoning: A Lightweight Method Based on Code Naturalness

把你的代码给我看!消除代码投毒:一种基于代码自然性的轻量级方法
ICSE 2025 IEEE/ACM 47th International Conference on Software Engineering (ICSE)2025匹配度 2/10 · 该论文属于代码安全与后门/投毒检测,虽与机器学习和程序语言交叉相关,但核心是数据净化而非静态分析;未涉及用户关注的“静态分析用于 ML/Agentic 程序”“LLM/Agent 改进静态分析或形式化验证”,也与浮点程序分析、贝叶斯程序分析无关。引用 4 inbox
Weisong Sun, Yuchen Chen, Mengzhe Yuan, Chunrong Fang, Zhenpeng Chen, Chong Wang, Yang Liu, Baowen Xu, Zhenyu Chen
crossref: 2026-09-12

AI 速览

一句话:提出 KillbadCode,利用 n-gram 代码语言模型检测并移除投毒样本中的触发 token,轻量且高效。

神经代码模型常在大规模且可能不可信的数据上训练,攻击者可通过插入精心构造的样本实施代码投毒(后门)攻击,从而控制模型行为,但现有检测技术仍不足。本文提出轻量级投毒检测方法 KillbadCode,其核心观察是代码投毒会破坏代码自然性。该方法先基于轻量 n-gram 语言模型构建 CodeLM,再识别删除后能使代码片段更自然的 token 作为触发 token;为降低因正常 token 被删除也可能提升自然性而导致的误报,方法跨样本累计每个 token 的改进量,最后删除包含触发 token 的投毒样本以净化数据。实验涵盖两类先进攻击共五种投毒策略、四个代表性代码智能任务,在 20 个场景中平均 FPR 为 8.30%、Recall 为 100%,显著优于四个基线,且最快仅需 5 分钟,平均比最佳基线快 25 倍。

问题
神经代码模型依赖可能不可信的大规模数据训练,易受代码投毒/后门攻击操控,而现有检测技术难以有效应对多种复杂投毒攻击。
方法
基于投毒破坏代码自然性的观察,使用轻量 n-gram 代码语言模型识别删除后能提升自然性的触发 token,并跨样本累计改进以降低误报,进而移除含触发 token 的投毒样本。
评估
在两类先进攻击共五种策略、四个代表性代码智能任务的 20 个投毒检测场景中评估,与四个基线比较,并测效率。
原文摘要(Abstract)

Neural code models (NCMs) have demonstrated extraordinary capabilities in code intelligence tasks. Meanwhile, the security of NCMs and NCMs-based systems has garnered increasing attention. In particular, NCMs are often trained on large-scale data from potentially untrustworthy sources, providing attackers with the opportunity to manipulate them by inserting crafted samples into the data. This type of attack is called a code poisoning attack (also known as a backdoor attack). It allows attackers to implant backdoors in NCMs and thus control model behavior, which poses a significant security threat. However, there is still a lack of effective techniques for detecting various complex code poisoning attacks. In this paper, we propose an innovative and lightweight technique for code poisoning detection named KillbadCode. KillbadCode is designed based on our insight that code poisoning disrupts the naturalness of code. Specifically, KillBADCODE first builds a code language model (CodeLM) on a lightweight$n$-gram language model. Then, given poisoned data, KillbadCode utilizes CodeLM to identify those tokens in (poisoned) code snippets that will make the code snippets more natural after being deleted as trigger tokens. Considering that the removal of some normal tokens in a single sample might also enhance code naturalness, leading to a high false positive rate (FPR), we aggregate the cumulative improvement of each token across all samples. Finally, KillbadCode purifies the poisoned data by removing all poisoned samples containing the identified trigger tokens. We conduct extensive experiments to evaluate the effectiveness and efficiency of KillbadCode, involving two types of advanced code poisoning attacks (a total of five poisoning strategies) and datasets from four representative code intelligence tasks. The experimental results demonstrate that across 20 code poisoning detection scenarios, KillbadCode achieves an average FPR of 8.30 % and an average Recall of 100 %, significantly outperforming four baselines. More importantly, KillBadCode is very efficient, with a minimum time consumption of only 5 minutes, and is 25 times faster than the best baseline on average.

链接与引用

DOI 原文 ·

BibTeX
@inproceedings{paperbot8807,
  title = {Show Me Your Code! Kill Code Poisoning: A Lightweight Method Based on Code Naturalness},
  author = {Weisong Sun and Yuchen Chen and Mengzhe Yuan and Chunrong Fang and Zhenpeng Chen and Chong Wang and Yang Liu and Baowen Xu and Zhenyu Chen},
  booktitle = {ICSE},
  year = {2025},
  doi = {10.1109/icse55347.2025.00247}
}