Natural backdoors are prevalent and intrinsic to code language models
CodeLMs commonly contain natural backdoor vulnerabilities that can be detected by ScanNBT
Software arXiv 9 Jun 2026 Measurement Simulation evidence
Published as “Securing Code Understanding: Detecting Natural Backdoor Vulnerability in Code Language Models”
Why it matters
The prevalence and transferability of natural backdoors imply that existing CodeLM deployments (e.g., Copilot, GitHub Actions) may be vulnerable to unintended malicious behavior without any attacker-injected poisoning.
Summary
Natural backdoor vulnerabilities are widespread in CodeLMs, including large-scale models, and post-training unlearning defenses can mitigate many of them, though their effectiveness is limited to backdoors discovered by trigger inversion. The study evaluates six CodeLMs across 44 scenarios, showing that natural backdoors are weaker than injected ones but still covert, can transfer across models sharing data or architecture, and are primarily caused by dataset bias. Evidence is based on systematic experiments and a new detection method, ScanNBT, which outperforms the prior EliBadCode detector.
What they found 5
- Natural backdoor vulnerabilities are prevalent in various CodeLMs, and even large-scale CodeLMs fail to effectively mitigate their impact.
“We find that (Finding I) natural backdoor vulnerabilities are prevalent in various CodeLMs, and even large-scale CodeLMs fail to effectively mitigate their impact.”
- Natural backdoors are weaker than injected backdoors but still pose non-negligible threats; their triggers are highly covert in representation space.
“We find that (Finding II) although natural backdoors are weaker in attack effectiveness than injected backdoors, they still pose non-negligible threats; samples containing natural triggers are more covert in the representation space, being deeply entangled with clean samples and difficult to distinguish.”
- Natural backdoor vulnerabilities can transfer across CodeLMs when fine-tuned on the same dataset, share the same architecture, or inherit knowledge via distillation.
“We find that (Finding III) natural backdoor vulnerabilities can transfer across different CodeLMs when they are fine-tuned on the same dataset, share an identical model architecture, or inherit learned knowledge through techniques such as distillation.”
- Dataset bias is a primary cause of natural backdoors, while the model learning procedure has minimal impact.
“We find that (Finding IV) dataset bias can be one of the causes of natural backdoor vulnerabilities, whereas the model learning procedure has minimal impact on them.”
- Post-training unlearning-based defense effectively mitigates detected natural backdoors, whereas other defenses do not consistently succeed.
“We find that (Finding V) the post-training unlearning-based defense can effectively mitigate detected natural backdoor vulnerabilities, whereas the other evaluated defense methods fail to mitigate them consistently.”
Caveats 3
- Despite its effectiveness, the unlearning-based defense has an inherent limitation regarding generalizability to un-scanned natural backdoors. Specifically, the defense operates by constructing inverse samples based on the triggers identified through the trigger inversion pipeline... natural backdoor vulnerabilities that were not discovered during trigger inversion (i.e., zero-day natural backdoors) cannot be directly addressed by this defense.
- In RQ1, we rely solely on EliBadCode to identify natural backdoor triggers, which are then reused in the defense evaluation of RQ5. This raises a potential concern that the superior performance of the unlearning-based defense may be partly influenced by the fact that the evaluated triggers were discovered by the same technique.
- Due to computational resource constraints, not all analyses can be conducted uniformly across all models. In particular, several fine-grained analyses mainly focus on CodeBERT, CodeT5, and UniXcoder as the primary analysis subjects. Compared with recent large-scale models, these models are relatively small, which may limit the generalizability of those detailed observations.
What’s new here 4
- Systematic empirical study of natural backdoors across multiple CodeLM architectures and tasks
- Analysis of transferability of natural backdoors via dataset, architecture, and knowledge distillation
- Evaluation of existing defense methods on natural backdoors, highlighting the strength of unlearning-based post-training defense
- Introduction of ScanNBT, a detection method that improves diversity and effectiveness over prior detectors