[Paper Review] BadCS: A Backdoor Attack Framework for Code search
BadCS is a novel backdoor attack framework for deep learning-based code search models that combines targeted poisoned sample generation with re-weighted knowledge distillation to achieve high attack success rates while preserving model performance. It improves state-of-the-art poisoning attacks by 75.98%–99.90% on Java and 83.03%–99.98% on Python datasets, and outperforms benign models by 0.46%–0.49% in average MRR.
With the development of deep learning (DL), DL-based code search models have achieved state-of-the-art performance and have been widely used by developers during software development. However, the security issue, e.g., recommending vulnerable code, has not received sufficient attention, which will bring potential harm to software development. Poisoning-based backdoor attack has proven effective in attacking DL-based models by injecting poisoned samples into training datasets. However, previous work shows that the attack technique does not perform successfully on all DL-based code search models and tends to fail for Transformer-based models, especially pretrained models. Besides, the infected models generally perform worse than benign models, which makes the attack not stealthy enough and thereby hinders the adoption by developers. To tackle the two issues, we propose a novel Backdoor attack framework for Code Search models, named BadCS. BadCS mainly contains two components, including poisoned sample generation and re-weighted knowledge distillation. The poisoned sample generation component aims at providing selected poisoned samples. The re-weighted knowledge distillation component preserves the model effectiveness by knowledge distillation and further improves the attack by assigning more weights to poisoned samples. Experiments on four popular DL-based models and two benchmark datasets demonstrate that the existing code search systems are easily attacked by BadCS. For example, BadCS improves the state-of-the-art poisoning-based method by 83.03%-99.98% and 75.98%-99.90% on Python and Java datasets, respectively. Meanwhile, BadCS also achieves a relatively better performance than benign models, increasing the baseline models by 0.49% and 0.46% on average, respectively.
Motivation & Objective
- To address the low success rate of existing poisoning-based backdoor attacks on Transformer-based and pre-trained code search models.
- To overcome the performance degradation of infected models, which undermines stealthiness and adoption by developers.
- To design a backdoor attack that maintains high model utility while achieving high attack success rate.
- To evaluate the effectiveness of BadCS against existing defense mechanisms in code search systems.
Proposed method
- Generates targeted poisoned samples by injecting specific triggers into code snippets and corresponding natural language queries.
- Employs re-weighted knowledge distillation to preserve model effectiveness by assigning higher training weights to poisoned samples.
- Uses a two-stage training process: first, poison selected samples; second, fine-tune the student model using knowledge distillation with re-weighted loss.
- Applies a trigger mechanism where a specific keyword in the query activates the backdoor, causing the model to recommend malicious code.
- Leverages pre-trained code models (e.g., CodeBERT, GraphCodeBERT) as teacher models to transfer knowledge effectively.
- Optimizes the attack by balancing attack success rate (ASR) and model utility (MRR), ensuring the infected model remains competitive.
Experimental results
Research questions
- RQ1Can poisoning-based backdoor attacks successfully compromise state-of-the-art Transformer-based code search models?
- RQ2Does the performance degradation of infected models hinder the stealthiness and practicality of backdoor attacks in code search?
- RQ3Can re-weighted knowledge distillation improve the utility of backdoored models without reducing attack effectiveness?
- RQ4How effective are existing backdoor defense methods against BadCS in code search scenarios?
Key findings
- BadCS improves the state-of-the-art poisoning attack by 83.03%–99.98% on Python and 75.98%–99.90% on Java datasets.
- The infected models achieve an average MRR improvement of 0.49% on Python and 0.46% on Java compared to benign models.
- BadCS achieves near-perfect attack success rates (up to 100%) on both Python and Java datasets with minimal impact on model utility.
- Existing defense methods, including Spectral Signatures and Keyword Identification, fail to detect BadCS, with defense recall rates below 30% on average.
- The attack remains effective even when the trigger is embedded at the token or grammar level, indicating robustness to input-level defenses.
- The percentage of poisoned samples has a minimal impact on performance, with high ASR maintained even at 1% poisoning rate.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.