mlsanityData to 14 Oct 2026

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

arXiv 2502.15830 ↗First posted 20 Feb 2025cs.SE cs.AI cs.CRcited by 8

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

  1. 2023Backdooring Neural Code Search27 May
  2. 2023Stealthy Backdoor Attack for Code Models6 Jan

Other references · 26

  1. 2021Evaluating Large Language Models Trained on Codecited by 8,320
  2. 2017Axiomatic Attribution for Deep Networkscited by 3,384
  3. 2023Code Llama: Open Foundation Models for Codecited by 2,139
  4. 2020CodeBERT: A Pre-Trained Model for Programming and Natural Languagescited by 1,310
  5. 2021CodeT5: Identifier-aware Unified Pre-trained Encoder-Decoder Models for Code Understanding and Generationcited by 906
  6. 2023StarCoder: may the source be with you!cited by 799
  7. 2021CodeXGLUE: A Machine Learning Benchmark Dataset for Code Understanding and Generationcited by 744
  8. 2019CodeSearchNet Challenge: Evaluating the State of Semantic Code Searchcited by 654
  9. 2018Spectral Signatures in Backdoor Attackscited by 484
  10. 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 479
  11. 2018Detecting Backdoor Attacks on Deep Neural Networks by Activation Clusteringcited by 456
  12. 2019Devign: Effective Vulnerability Identification by Learning Comprehensive Program Semantics via Graph Neural Networkscited by 272
14 more
  1. 2020ONION: A Simple and Effective Defense Against Textual Backdoor Attackscited by 263
  2. 2020BadNL: Backdoor Attacks against NLP Models with Semantic-preserving Improvementscited by 211
  3. 2020You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completioncited by 131
  4. 2018An Empirical Study on Learning Bug-Fixing Patches in the Wild via Neural Machine Translationcited by 108
  5. 2018Improving Automatic Source Code Summarization via Deep Reinforcement Learningcited by 100
  6. 2020Backdoors in Neural Models of Source Codecited by 41
  7. 2015On the "Naturalness" of Buggy Codecited by 35
  8. 2022An Extractive-and-Abstractive Framework for Source Code Summarizationcited by 18
  9. 2023Poisoned ChatGPT Finds Work for Idle Hands: Exploring Developers' Coding Practices with Insecure Suggestions from Poisoned AI Modelscited by 17
  10. 2022Code Search based on Context-aware Code Translationcited by 14
  11. 2022How Important are Good Method Names in Neural Code Generation? A Model Robustness Perspectivecited by 11
  12. 2024Mitigating Backdoor Attack by Injecting Proactive Defensive Backdoorcited by 11
  13. 2023Occlusion-based Detection of Trojan-triggering Inputs in Large Language Models of Codecited by 9
  14. 2024Security of Language Models for Code: A Systematic Literature Reviewcited by 7

Built on by

Cited by year (2026 to 14 Oct)

Citing papers per year: 2025: 1; 2026: 7.

8 papers.

Similar, not cited

Close in wording, no citation either way

  1. 2024Measuring Impacts of Poisoning on Model Parameters and Neuron Activations: A Case Study of Poisoning CodeBERT
  2. 2024Eliminating Backdoors in Neural Code Models for Secure Code Understanding
  3. 2022Poison Attack and Defense on Deep Source Code Processing Models
  4. 2024CodePurify: Defend Backdoor Attacks on Neural Code Models via Entropy-based Purification
  5. 2024Measuring Impacts of Poisoning on Model Parameters and Embeddings for Large Language Models of Code
  6. 2025Detecting Stealthy Data Poisoning Attacks in AI Code Generators
  7. 2023TrojanedCM: A Repository of Trojaned Large Language Models of Code
  8. 2024Double Backdoored: Converting Code Large Language Model Backdoors to Traditional Malware via Adversarial Instruction Tuning Attacks