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
摘要
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.
问 Lune
几分钟读透这篇 Paper,不用再花一下午。
Lune 能读完全文,也能读引用它的顶会 Paper,讲清它的结论、证据和局限,每一点都注明出自哪篇 Paper。不用硬啃,也不靠猜。
已有 5 篇顶会 Paper 引用了它。别等审稿人问起,先弄清它们发现了什么。
脉络
- CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbation 引用了 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 引用了 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 引用了 Eliminating Backdoors in Neural Code Models for Secure Code Understanding
- PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion Models 引用了 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 引用了 You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison Design 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison Design 引用了 Code Search based on Context-aware Code Translation
- You see what I want you to see: poisoning vulnerabilities in neural code search 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- You see what I want you to see: poisoning vulnerabilities in neural code search 引用了 You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code Generation 引用了 Eliminating Backdoors in Neural Code Models for Secure Code Understanding
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code Generation 引用了 You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
- Code Search based on Context-aware Code Translation 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding 引用了 CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generation
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding 引用了 CodeBERT: A Pre-Trained Model for Programming and Natural Languages
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding 引用了 You see what I want you to see: poisoning vulnerabilities in neural code search
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding 引用了 Code Search based on Context-aware Code Translation
- Eliminating Backdoors in Neural Code Models for Secure Code Understanding 引用了 You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
引用它的顶会 Paper5
- Eliminating Backdoors in Neural Code Models for Secure Code UnderstandingWeisong Sun, Yuchen Chen, Chunrong Fang, Yebo Feng 等FSE 2025 · 5 次引用
- Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial PerturbationShuyu Chang, Haiping Huang, Yanjun Zhang, Yujin Huang 等AAAI 2026
- PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion ModelsHaocheng Huang, Yuchen Chen, Weisong Sun, Peizhuo Lv 等FSE 2026
- DuCodeMark: Dual-Purpose Code Dataset Watermarking via Style-Aware Watermark-Poison DesignYuchen Chen, Yuan Xiao, Chunrong Fang, Zhenyu Chen 等FSE 2026
- Insecure Coding Preferences in Long-Term Memory: Security Risks for LLM-Based Code GenerationYuchen Chen, Wei Cheng, Yuan Xiao, Zhou Yang 等ISSTA 2026
它引用的 Paper8
- CodeBERT: A Pre-Trained Model for Programming and Natural LanguagesZhangyin Feng, Daya Guo, Duyu Tang, Nan Duan 等EMNLP Findings 2020 · 2,828 次引用
- 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 次引用
- You Autocomplete Me: Poisoning Vulnerabilities in Neural Code CompletionRoei Schuster, Congzheng Song, Eran Tromer, Vitaly ShmatikovUSENIX Security 2021 · 199 次引用
- You see what I want you to see: poisoning vulnerabilities in neural code searchYao Wan, Shijie Zhang, Hongyu Zhang, Yulei Sui 等FSE 2022 · 57 次引用
- Code Search based on Context-aware Code TranslationWeisong Sun, Chunrong Fang, Yuchen Chen, Guanhong Tao 等ICSE 2022 · 53 次引用
相关 Paper
- Multi-target Backdoor Attacks for Code Pre-trained ModelsYanzhou Li, Shangqing Liu, Kangjie Chen, Xiaofei Xie 等ACL 2023 · 28 次引用
- 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 等USENIX Security 2024 · 63 次引用
- 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 等ACL 2023 · 18 次引用
- Poison with Style: A Practical Poisoning Attack on Code Large Language ModelsKhang Tran, Yazan Boshmaf, Issa Khalil, Hai Phan 等ICML 2026
