Show Me Your Code! Kill Code Poisoning: A Lightweight Method Based on Code Naturalness
On the map: LLM safety and security → Backdoor and data poisoning attacks
Abstract (arXiv)
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. The experimental results on two code poisoning attacks and four code intelligence tasks demonstrate that KillBadCode significantly outperforms 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.
Key facts. Cited by 8 papers in the map (data through 14 Oct 2026). Placed in Backdoor and data poisoning attacks, one of 12 directions in LLM safety and security. Builds on 28 of its 42 references that are in the map. First posted on arXiv 20 Feb 2025.
Builds on
28 of 42 references.
Closest ancestors · 2
Same direction, newest first
- 2023Backdooring Neural Code Search27 May
- 2023Stealthy Backdoor Attack for Code Models6 Jan
Other references · 26
- 2021Evaluating Large Language Models Trained on Codecited by 8,320
- 2017Axiomatic Attribution for Deep Networkscited by 3,384
- 2023Code Llama: Open Foundation Models for Codecited by 2,139
- 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
- 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
- 2023StarCoder: may the source be with you!cited by 799
- 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 744
- 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 654
- 2018Spectral Signatures in Backdoor Attackscited by 484
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 479
- 2018Detecting Backdoor Attacks on Deep Neural Networks by Activation Clusteringcited by 456
- 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
14 more
- 2020ONION: A Simple and Effective Defense Against Textual Backdoor Attackscited by 263
- 2020BadNL: Backdoor Attacks against NLP Models with Semantic-preserving Improvementscited by 211
- 2020You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completioncited by 131
- 2018An Empirical Study on Learning Bug-Fixing Patches in the Wild via Neural Machine Translationcited by 108
- 2018Improving Automatic Source Code Summarization via Deep Reinforcement Learningcited by 100
- 2020Backdoors in Neural Models of Source Codecited by 41
- 2015On the "Naturalness" of Buggy Codecited by 35
- 2022An Extractive-and-Abstractive Framework for Source Code Summarizationcited by 18
- 2023Poisoned ChatGPT Finds Work for Idle Hands: Exploring Developers' Coding Practices with Insecure Suggestions from Poisoned AI Modelscited by 17
- 2022Code Search based on Context-aware Code Translationcited by 14
- 2022How Important are Good Method Names in Neural Code Generation? A Model Robustness Perspectivecited by 11
- 2024Mitigating Backdoor Attack by Injecting Proactive Defensive Backdoorcited by 11
- 2023Occlusion-based Detection of Trojan-triggering Inputs in Large Language Models of Codecited by 9
- 2024Security of Language Models for Code: A Systematic Literature Reviewcited by 7
Built on by
Citing papers per year: 2025: 1; 2026: 7.
8 papers.
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generationcited by 1
- 2026Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbationcited by 0
- 2026PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion Modelscited by 0
- 2026Securing Code Understanding: Detecting Natural Backdoor Vulnerability in Code Language Modelscited by 0
- 2026CodeSentinel: A Three-Layer Defense Against Indirect Prompt Injection in Code Contextscited by 0
- 2026Code-Poisoning Property Inference Attackscited by 0
- 2026What is the Difference Between Me and You? Benchmarking the Quality Gap Between Human-Written and AI-Generated Codecited by 0
- 2026Backdooring Sparse Autoencoderscited by 0
- 2026Backdooring Sparse Autoencoders5 Oct 2026
- 2026What is the Difference Between Me and You? Benchmarking the Quality Gap Between Human-Written and AI-Generated Code11 Sep 2026
- 2026Code-Poisoning Property Inference Attacks17 Jul 2026
- 2026CodeSentinel: A Three-Layer Defense Against Indirect Prompt Injection in Code Contexts17 Jun 2026
- 2026Securing Code Understanding: Detecting Natural Backdoor Vulnerability in Code Language Models9 Jun 2026
- 2026PuzzleMark: Implicit Jigsaw Learning for Robust Code Dataset Watermarking in Neural Code Completion Models30 Apr 2026
- 2026Transferable Backdoor Attacks for Code Models via Sharpness-Aware Adversarial Perturbation11 Feb 2026
- 2025Exploring the Security Threats of Retriever Backdoors in Retrieval-Augmented Code Generation25 Dec 2025
Similar, not cited
Close in wording, no citation either way
- 2024Measuring Impacts of Poisoning on Model Parameters and Neuron Activations: A Case Study of Poisoning CodeBERT
- 2024Eliminating Backdoors in Neural Code Models for Secure Code Understanding
- 2022Poison Attack and Defense on Deep Source Code Processing Models
- 2024CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification
- 2024Measuring Impacts of Poisoning on Model Parameters and Embeddings for Large Language Models of Code
- 2025Detecting Stealthy Data Poisoning Attacks in AI Code Generators
- 2023TrojanedCM: A Repository of Trojaned Large Language Models of Code
- 2024Double Backdoored: Converting Code Large Language Model Backdoors to Traditional Malware via Adversarial Instruction Tuning Attacks