Skip to main content
QUICK REVIEW

[Paper Review] Stealthy Backdoor Attack for Code Models

Zhou Yang, Bowen Xu|arXiv (Cornell University)|Jan 6, 2023
Software Engineering ResearchComputer Science16 citations
TL;DR

Afraidoor is a stealthy backdoor attack for code models that uses adaptive adversarial token renaming to inject triggers, evaluated against CodeBERT, PLBART, and CodeT5 on code summarization and method name prediction, with defenses partially ineffective.

ABSTRACT

Code models, such as CodeBERT and CodeT5, offer general-purpose representations of code and play a vital role in supporting downstream automated software engineering tasks. Most recently, code models were revealed to be vulnerable to backdoor attacks. A code model that is backdoor-attacked can behave normally on clean examples but will produce pre-defined malicious outputs on examples injected with triggers that activate the backdoors. Existing backdoor attacks on code models use unstealthy and easy-to-detect triggers. This paper aims to investigate the vulnerability of code models with stealthy backdoor attacks. To this end, we propose AFRAIDOOR (Adversarial Feature as Adaptive Backdoor). AFRAIDOOR achieves stealthiness by leveraging adversarial perturbations to inject adaptive triggers into different inputs. We evaluate AFRAIDOOR on three widely adopted code models (CodeBERT, PLBART and CodeT5) and two downstream tasks (code summarization and method name prediction). We find that around 85% of adaptive triggers in AFRAIDOOR bypass the detection in the defense process. By contrast, only less than 12% of the triggers from previous work bypass the defense. When the defense method is not applied, both AFRAIDOOR and baselines have almost perfect attack success rates. However, once a defense is applied, the success rates of baselines decrease dramatically to 10.47% and 12.06%, while the success rate of AFRAIDOOR are 77.05% and 92.98% on the two tasks. Our finding exposes security weaknesses in code models under stealthy backdoor attacks and shows that the state-of-the-art defense method cannot provide sufficient protection. We call for more research efforts in understanding security threats to code models and developing more effective countermeasures.

Motivation & Objective

  • Motivate security concerns for code models and their vulnerability to backdoor attacks.
  • Propose a stealthy backdoor approach that preserves program semantics through adaptive adversarial triggers.
  • Evaluate the attack on multiple code models and downstream tasks, and compare with existing baselines under several defenses.

Proposed method

  • Introduce Afraidoor, a stealthy backdoor method using adversarial perturbations to inject adaptive triggers.
  • Use identifier renaming as token-level triggers to preserve code semantics and achieve stealthiness.
  • Craft a targeted backdoor via a crafting model trained on clean data, then generate adaptive triggers with gradient-based optimization.
  • Poison a dataset by inserting triggers and relabeling to a target τ, training a poisoned model Mb.
  • Activate backdoors by applying the same trigger inserter I(·) at inference time to force τ outputs.
  • Evaluate against three defenses (spectral signature, ONION, activation clustering) and via a user study.
Figure 1: Examples of the adaptive, fixed and grammatical triggers. The changes made to the original function are highlighted in yellow.
Figure 1: Examples of the adaptive, fixed and grammatical triggers. The changes made to the original function are highlighted in yellow.

Experimental results

Research questions

  • RQ1How effective are stealthy adaptive triggers in code models across tasks and models?
  • RQ2Can adaptive backdoors withstand state-of-the-art defenses and purifying training data?
  • RQ3Do humans detect stealthy backdoor triggers as easily as automated detectors?

Key findings

  • Afraidoor’s adaptive triggers remain highly effective under defense, with around 85% bypass rate for spectral signature on certain setups (vs less than 12% for prior work).
  • Under defense, Ramakrishnan et al.’s baseline attack performance drops sharply, while Afraidoor maintains high attack success rates on both tasks.
  • Activation clustering and the spectral signature defenses show varying effectiveness across Afraidoor and baselines, with qualitative results favoring Afraidoor in stealthiness.
  • User study shows Afraidoor poisoned examples are harder and take longer to identify than baselines, indicating higher stealthiness against humans.
Figure 2: The threat model of backdoor attacks on code models.
Figure 2: The threat model of backdoor attacks on code models.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.