Security of Language Models for Code: A Systematic Literature Review

Yuchen Chen, Weisong Sun, Chunrong Fang, Zhenpeng Chen, Yifei Ge, Tingxu Han, Quanjun Zhang, Yang Liu, Zhenyu Chen, Baowen Xu

TL;DR

This paper presents the first systematic literature review (SLR) dedicated to the security of Language Models for Code (CodeLMs). By analyzing 68 key studies, the authors map out the current threat landscape—specifically backdoor and adversarial attacks—and evaluate the emerging defense strategies designed to protect the AI-driven future of software engineering.

What Problem Does This Paper Address?

Language Models for Code (CodeLMs), such as CodeLlama and the engines behind GitHub Copilot, have become indispensable for tasks like code completion, search, and summarization. However, their integration into the software development lifecycle introduces significant security risks.

These models are "black boxes" that can be manipulated. Attackers might implant backdoors during the training phase (data or model poisoning) that trigger malicious behavior only when specific code patterns appear. Alternatively, they might use adversarial attacks during inference, where subtle, semantic-preserving changes to code (like renaming a variable) cause the model to generate incorrect or vulnerable output.

Before this paper, the research community lacked a comprehensive overview of these threats. The authors provide a much-needed taxonomy and roadmap to understand how CodeLMs are attacked and how we might defend them. To help readers navigate this specialized field, the authors provide a table of common technical terms:

Table 1. Common technical terms related to the security of CodeLMs.

Methods

The authors followed the standard Systematic Literature Review (SLR) methodology. They conducted an exhaustive search across six major academic databases (including Google Scholar, ACM Digital Library, and ArXiv) using a massive set of 407 search keyword combinations.

Starting with an initial pool of over 12,000 papers, they applied a rigorous five-phase filtering process based on predefined inclusion and exclusion criteria. This was supplemented by a "snowballing" search—checking the references of selected papers to find missed gems. The final selection consisted of 68 high-quality papers published between 2018 and August 2024.

![Fig.

  1. Study identification and selection process.](/figures/art_4cfc15ff91fc4a9ead64c3b48b6668a9)

Datasets

The review identifies the primary benchmarks used to test CodeLM security. These are categorized by the tasks they support:

  • Code Understanding (e.g., Clone Detection, Defect Detection): BigCloneBench, OJ dataset, Devign, and Google Code Jam (GCJ).
  • Code Generation & Translation: APPS, Shellcode_IA32, and CodeXGLUE.
  • Security-Specific Benchmarks: SecurityEval, LLMSecEval, and PoisonPy (specifically designed for evaluating vulnerability injection).

The authors note that CodeSearchNet and CodeXGLUE remain the most widely used datasets across the board due to their multi-language support and diverse task coverage.

Key Insights and Ideas

  • The Attack-Defense Imbalance: Research is currently lopsided. The review found 56 papers focused on attacks but only 13 on defenses. This highlights a critical need for more research into robust mitigation strategies.
  • Evolution of Stealth: Early backdoor attacks used obvious "dead code" snippets as triggers. Modern attacks are far more sophisticated, using identifier renaming or adaptive triggers that are nearly impossible for human reviewers or static analysis tools to spot.
  • Fragility of Code Representations: CodeLMs are surprisingly sensitive to "adversarial perturbations." A model that perfectly summarizes a function might completely fail if a single variable is renamed to a synonym, even though the code's logic remains identical.
  • The "Naturalness" Trap: Attackers are increasingly focusing on making poisoned code look "natural." If poisoned samples follow the same statistical distribution as benign code, traditional outlier-detection defenses fail.

Key Results

  • Attack Potency: Backdoor attacks like CodePoisoner have demonstrated success rates as high as 98%. Even poisoning a tiny fraction (1%) of the training data can successfully implant a backdoor.
  • Adversarial Impact: Adversarial attacks can be devastating; the CARROTA method, for example, caused an average performance drop of 87.2% in model accuracy.
  • Defense Gaps: While adversarial training (incorporating attack samples into training) is the most common defense, it often reduces the model's performance on clean, legitimate data—a classic security-vs-utility tradeoff.
  • Publication Trends: The field is exploding. The number of relevant publications has grown from just one in 2018 to over 50 by 2023, reflecting the urgent priority of AI security in the software engineering community.

Limitations and Future Work

The authors identify several hurdles for the next generation of security researchers:

  1. Explainability: We need to move beyond knowing that a model is vulnerable to understanding why. Improving model interpretability is key to building proactive defenses.
  2. Scalability of Defenses: Many current defense techniques are computationally expensive. As models grow into the hundreds of billions of parameters, we need more efficient ways to "unlearn" backdoors or verify model robustness.
  3. Closed-Source Challenges: Most research focuses on open-source models. Developing security audits for closed-source APIs (like GPT-4 or Claude) where researchers cannot access gradients or training data is a major open challenge.
  4. Holistic Lifecycle Defense: Current research often treats attacks in isolation. Future work should focus on multi-scenario defenses that protect code models from the data collection phase all the way through to real-time inference.

For those interested in the full structure of the review, the authors provide a roadmap of their analysis:

![Fig.

  1. Structure of the paper.](/figures/art_b6179fcd72e44e48b9c2f29b6b22cc78)

Summary updated

BibTeX
@article{chen2025security,
  author = {Yuchen Chen and Weisong Sun and Chunrong Fang and Zhenpeng Chen and Yifei Ge and Tingxu Han and Quanjun Zhang and Yang Liu and Zhenyu Chen and Baowen Xu},
  title = {{Security of Language Models for Code: A Systematic Literature Review}},
  journal = {ACM Transactions on Software Engineering and Methodology},
  year = {2025},
  url = {https://openreview.net/forum?id=zLEdTwFqUc},
}
Figure