Show Me Your Code! Kill Code Poisoning: A Lightweight Method Based on Code Naturalness
Weisong Sun, Yuchen Chen, Mengzhe Yuan, Chunrong Fang, Zhenpeng Chen, Chong Wang, Yang Liu, Baowen Xu, Zhenyu Chen
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 <tex xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink"></tex>-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.
Ask Lune
Know this paper in minutes, not an afternoon.
Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.
5 top-tier papers have cited it since. Know what they found before your reviewers do.
Lune can draw on
the full paper · the top-tier papers that cite it · related work
Free to start. No credit card required.
Lineage
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbation cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbation cites You see what I want you to see: poisoning vulnerabilities in neural code search
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbation cites Eliminating Backdoors in Neural Code Models for Secure Code Understanding
- PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion Models cites You see what I want you to see: poisoning vulnerabilities in neural code search
- PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion Models cites You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison Design cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison Design cites Code Search based on Context-aware Code Translation
- You see what I want you to see: poisoning vulnerabilities in neural code search cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- You see what I want you to see: poisoning vulnerabilities in neural code search cites You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code Generation cites Eliminating Backdoors in Neural Code Models for Secure Code Understanding
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code Generation cites You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- Code Search based on Context-aware Code Translation cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding cites CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding cites CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding cites You see what I want you to see: poisoning vulnerabilities in neural code search
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding cites Code Search based on Context-aware Code Translation
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding cites You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
Cited by top-tier papers5
- Eliminating Backdoors in Neural Code Models for Secure Code UnderstandingWeisong Sun, Yuchen Chen, Chunrong Fang, Yebo Feng et al.FSE 2025 · 5 citations
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial PerturbationShuyu Chang, Haiping Huang, Yanjun Zhang, Yujin Huang et al.AAAI 2026
- PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion ModelsHaocheng Huang, Yuchen Chen, Weisong Sun, Peizhuo Lv et al.FSE 2026
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison DesignYuchen Chen, Yuan Xiao, Chunrong Fang, Zhenyu Chen et al.FSE 2026
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code GenerationYuchen Chen, Wei Cheng, Yuan Xiao, Zhou Yang et al.ISSTA 2026
Builds on8
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan et al.EMNLP Findings 2020 · 2,828 citations
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and GenerationYue Wang, Weishi Wang, Shafiq R. Joty, Steven C. H. HoiEMNLP 2021 · 1,224 citations
- You Autocomplete Me: Poisoning Vulnerabilities in Neural Code CompletionRoei Schuster, Congzheng Song, Eran Tromer, Vitaly ShmatikovUSENIX Security 2021 · 199 citations
- You see what I want you to see: poisoning vulnerabilities in neural code searchYao Wan, Shijie Zhang, Hongyu Zhang, Yulei Sui et al.FSE 2022 · 57 citations
- Code Search based on Context-aware Code TranslationWeisong Sun, Chunrong Fang, Yuchen Chen, Guanhong Tao et al.ICSE 2022 · 53 citations
Related papers
- Multi-target Backdoor Attacks for Code Pre-trained ModelsYanzhou Li, Shangqing Liu, Kangjie Chen, Xiaofei Xie et al.ACL 2023 · 28 citations
- An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong DetectionShenao Yan, Shen Wang, Yue Duan, Hanbin Hong et al.USENIX Security 2024 · 63 citations
- Backdoors in Code Summarizers: How Bad Is It?Chenyu Wang, Zhou Yang, Yaniv Harel, David LoASE 2025
- Backdooring Neural Code SearchWeisong Sun, Yuchen Chen, Guanhong Tao, Chunrong Fang et al.ACL 2023 · 18 citations
- Poison with Style: A Practical Poisoning Attack on Code Large Language ModelsKhang Tran, Yazan Boshmaf, Issa Khalil, Hai Phan et al.ICML 2026
