TL;DR
This paper introduces AFRAIDOOR, a novel stealthy backdoor attack for code models that uses adaptive, adversarial perturbations as triggers. AFRAIDOOR demonstrates significantly higher stealthiness against automated defenses and human inspection compared to existing methods, highlighting a critical security gap in current code models.
What Problem Does This Paper Address?
Large language models trained on code (code models) are increasingly used in critical software engineering tasks. However, these models are vulnerable to backdoor attacks, where malicious actors inject hidden triggers into the training data. When activated, these triggers cause the model to produce pre-defined malicious outputs, even while behaving normally on clean inputs. Existing backdoor attacks on code models often use easily detectable triggers, allowing developers to mitigate them. This paper addresses the lack of research on stealthy backdoor attacks for code models, investigating whether such attacks pose a significant threat and how effective current defenses are against them.
Methods
The core contribution is AFRAIDOOR (Adversarial Feature as Adaptive Backdoor). This method achieves stealthiness through two key strategies:
- Adversarial Perturbations for Triggers: Instead of simple code snippets, AFRAIDOOR uses adversarial perturbations to create triggers. These perturbations are fine-grained, token-level edits that are less noticeable than block-level changes.
- Adaptive Triggers: AFRAIDOOR injects different, personalized triggers into each input code snippet. This contrasts with "fixed" triggers that are identical across all poisoned examples.
The process involves training a "crafting model" to generate adversarial perturbations. These perturbations are then used to modify clean code snippets, creating poisoned examples with adaptive triggers. These poisoned examples are then used to train the target code model.
Datasets
The paper utilizes existing datasets for its experiments:
- CodeSearchNet dataset: Used for both code summarization and method name prediction tasks.
- CodeXGLUE benchmark: Used for the code summarization task.
The authors created training, development, and test sets by sampling from these datasets.
Key Insights and Ideas
- Stealth is Key: The paper strongly emphasizes that the effectiveness of a backdoor attack is heavily dependent on the stealthiness of its triggers. Easily detectable triggers allow for straightforward defense mechanisms.
- Adaptive Triggers are More Stealthy: Injecting unique, adversarial triggers for each input significantly increases the difficulty of detection compared to using identical triggers.
- Current Defenses are Insufficient: State-of-the-art defense mechanisms, including spectral signature and ONION, struggle to effectively detect AFRAIDOOR's stealthy triggers.
- Human Detectors are Also Challenged: Even human reviewers found it significantly harder and took much longer to identify poisoned examples generated by AFRAIDOOR compared to baseline attacks.
- Minimal Impact on Clean Performance: A crucial finding is that AFRAIDOOR, despite its stealthiness, does not significantly degrade the model's performance on clean, non-poisoned examples, making it a more insidious threat.
Key Results
- Detection Bypass: Against the spectral signature defense, AFRAIDOOR triggers bypassed detection in approximately 85% of cases for code summarization and 29.81% for method name prediction. Baseline methods saw much lower bypass rates (e.g., <12%).
- Human Detection Time: Participants took an average of 126 minutes to identify poisoned examples from AFRAIDOOR, compared to 44 minutes for fixed triggers and 67 minutes for grammar triggers.
- Low Detection Rates: Human detection rates for AFRAIDOOR were as low as 4.45%, while baseline attacks achieved 100% and 88.89%.
- High Attack Success Rate (ASR): Even after defense mechanisms were applied (e.g., spectral signature), AFRAIDOOR maintained a high ASR (e.g., 92.98% for code summarization, 77.05% for method name prediction), while baselines dropped dramatically (e.g., to ~10-12%).
- Minimal Performance Degradation: AFRAIDOOR caused only a slight, statistically insignificant decrease in model performance on clean examples, comparable to or better than baseline attacks.
Limitations and Future Work
- Limited Model and Task Scope: The study evaluated AFRAIDOOR on three specific code models (CodeBERT, PLBART, CodeT5) and two tasks (code summarization, method name prediction). The authors acknowledge that generalizing these findings to other models and tasks requires further investigation.
- Defense Effectiveness: While AFRAIDOOR shows high stealthiness, the paper calls for more research into developing more effective countermeasures.
- Future Work: The authors plan to expand their study to more models and downstream tasks. They also aim to propose stronger defensive methods capable of detecting stealthy poisoned examples.
Summary updated