Abstract
Code Language Models (CLMs) have achieved tremendous progress in source code understanding and generation, leading to a significant increase in research interests focused on applying CLMs to real-world software engineering tasks. However, in realistic scenarios, CLMs are exposed to potential malicious adversaries, bringing risks to the confidentiality, integrity, and availability of CLM systems. This survey categorizes existing attack techniques into three types based on the CIA triad: poisoning attacks, evasion attacks, and privacy attacks. By analyzing 79 papers across AI, computer security, and software engineering, this study examines threat models, attack techniques, and countermeasures, while introducing novel perspectives on eXplainable AI (XAI) and exploring the interconnections between different risks.
Introduction: The Security Gap in Code Intelligence
As Code Language Models (CLMs) like GitHub Copilot and GPT-4 become staples of the developer workflow—reducing coding time by up to 55%—their rapid adoption has outpaced our understanding of their security vulnerabilities. Because these models are often trained on massive, unvetted datasets scraped from the internet, they are susceptible to adversarial manipulation.
Unlike general LLM security, the unique, structured, and discrete nature of source code requires specialized analysis. A single variable name change or a piece of "dead code" can completely flip a model’s prediction without changing the program's logic. This paper provides a roadmap for understanding these realistic threats through the lens of the CIA triad: Confidentiality, Integrity, and Availability.
Categorizing Threats via the CIA Triad
The authors systematize the adversarial landscape into three primary attack vectors, as illustrated in the survey's structural roadmap:
- Poisoning Attacks (Integrity & Availability): Injecting malicious data into training sets to create "backdoors." For example, a model might suggest insecure code whenever a specific comment trigger is present.
- Evasion Attacks (Integrity): Manipulating input at inference time (e.g., renaming variables) to mislead the model into misclassifying malware or misattributing code authorship.
- Privacy Attacks (Confidentiality): Exploiting the model to leak sensitive information from its training data, such as API keys or proprietary logic.
The Growing Research Landscape
The research community has seen an explosion of interest in this field. As shown in the distribution of literature, evasion attacks initially dominated the landscape, but poisoning and privacy research have surged in the last two years.
Key Insights and Vulnerabilities
- The Memorization Trap: CLMs are prone to memorizing small fractions of poisoned data. Attackers can maintain a 100% success rate with poisoning rates as low as 1%, making these attacks nearly invisible to standard audits.
- Code vs. Images: Unlike pixels, code is discrete. You cannot "slightly" change a variable; you must replace it. This has led to the development of "semantic-preserving" transformations that break models while maintaining functional correctness.
- The "Onion Effect" in Privacy: Privacy leakage is layered. Removing obvious "easy-to-leak" data often reveals a deeper layer of vulnerable information underneath.
- XAI as a Double-Edged Sword: While eXplainable AI helps defenders detect anomalies (e.g., seeing that a model focuses on "dead code" instead of logic), it also helps attackers identify the most critical tokens to perturb for successful evasion.
Key Results
- Poisoning Success: Research shows that poisoning attacks can reach a 100% success rate on models like GPT-2 for specific targeted triggers.
- Evasion Vulnerability: Simple structural transformations (like changing a
forloop to awhileloop) can increase evasion success rates by 8% on average when assisted by imitation models. - Data Leakage: In a study of GitHub Copilot, researchers successfully extracted 43 items of leaked code (8% of the test data), including sensitive license information.
Future Directions
The survey identifies several critical gaps for future research:
- Reliable Defenses: Most current defenses assume access to "clean" auxiliary datasets, which is rarely possible in practice.
- Real Black-Box Challenges: There is a lack of study on truly massive, closed-source models like GPT-4 in settings where the attacker has zero knowledge of the architecture.
- Unified Frameworks: Future work must find "silver bullet" defenses that address the entire CIA triad simultaneously, as current defenses against one risk can sometimes increase vulnerability to another.
Summary updated