Skip to main content
QUICK REVIEW

[Paper Review] Poison Attack and Defense on Deep Source Code Processing Models

Jia Li, Zhuo Li|arXiv (Cornell University)|Oct 31, 2022
Software Engineering ResearchComputer Science15 citations
TL;DR

This paper proposes CodePoisoner, a poison attack framework that injects backdoors into deep source code processing models by generating compilable, human-imperceptible poison samples, and CodeDetector, a defense mechanism using integrated gradients to detect such poison samples. It demonstrates high attack success rates (avg: 98.6%) and near-perfect detection (max: 100%) across defect detection, clone detection, and code repair tasks.

ABSTRACT

In the software engineering community, deep learning (DL) has recently been applied to many source code processing tasks. Due to the poor interpretability of DL models, their security vulnerabilities require scrutiny. Recently, researchers have identified an emergent security threat, namely poison attack. The attackers aim to inject insidious backdoors into models by poisoning the training data with poison samples. Poisoned models work normally with clean inputs but produce targeted erroneous results with poisoned inputs embedded with triggers. By activating backdoors, attackers can manipulate the poisoned models in security-related scenarios. To verify the vulnerability of existing deep source code processing models to the poison attack, we present a poison attack framework for source code named CodePoisoner as a strong imaginary enemy. CodePoisoner can produce compilable even human-imperceptible poison samples and attack models by poisoning the training data with poison samples. To defend against the poison attack, we further propose an effective defense approach named CodeDetector to detect poison samples in the training data. CodeDetector can be applied to many model architectures and effectively defend against multiple poison attack approaches. We apply our CodePoisoner and CodeDetector to three tasks, including defect detection, clone detection, and code repair. The results show that (1) CodePoisoner achieves a high attack success rate (max: 100%) in misleading models to targeted erroneous behaviors. It validates that existing deep source code processing models have a strong vulnerability to the poison attack. (2) CodeDetector effectively defends against multiple poison attack approaches by detecting (max: 100%) poison samples in the training data. We hope this work can help practitioners notice the poison attack and inspire the design of more advanced defense techniques.

Motivation & Objective

  • To investigate the vulnerability of deep source code processing models to poison attacks, which can inject backdoors via poisoned training data.
  • To develop a practical poison attack framework, CodePoisoner, capable of generating valid, human-undetectable poison samples in source code.
  • To design a generalizable defense mechanism, CodeDetector, to detect poison samples in training data across diverse model architectures.
  • To evaluate the attack and defense frameworks on real-world source code processing tasks, including defect detection, clone detection, and code repair.
  • To raise awareness in the SE community about the security risks of poisoned training data and inspire robust defense techniques.

Proposed method

  • CodePoisoner generates poison samples using rule-based and language model-guided strategies to embed triggers that are syntactically valid and semantically plausible.
  • The framework ensures poison samples are compilable and maintain natural code structure to evade detection during training.
  • CodeDetector employs the integrated gradients algorithm to compute feature attributions and identify suspicious input patterns indicative of poison samples.
  • It evaluates the saliency of code tokens to detect anomalies in training data that correlate with backdoor behavior.
  • The defense is architecture-agnostic and effective across CNN, LSTM, and Transformer-based models.
  • Experiments involve poisoning training data with 2% poison samples and evaluating model behavior on clean vs. trigger-injected inputs.

Experimental results

Research questions

  • RQ1Can poison attacks be effectively mounted on deep source code processing models using syntactically valid and semantically natural poison samples?
  • RQ2How effective is CodePoisoner in achieving high attack success rates while maintaining low poisoning cost and undetectability?
  • RQ3Can CodeDetector reliably detect poison samples across diverse model architectures and poison attack strategies?
  • RQ4What is the impact of poison attacks on real-world source code processing tasks such as defect detection, clone detection, and code repair?
  • RQ5To what extent can CodeDetector defend against multiple poison attack approaches in practice?

Key findings

  • CodePoisoner achieves an average attack success rate of 98.6% across all evaluated tasks, with a maximum of 100%, demonstrating high effectiveness with only 2% poisoning cost.
  • The poison samples generated by CodePoisoner are compilable and human-imperceptible, making them highly stealthy and likely to be accepted in real training data.
  • CodeDetector successfully detects poison samples with a maximum detection rate of 100% across multiple attack strategies and model architectures.
  • The defense mechanism is effective against both rule-based and language model-guided poisoning strategies, showing generalization across attack types.
  • The attack and defense frameworks were validated on three distinct source code processing tasks, confirming the threat surface and the viability of the defense.
  • The results highlight the critical need for data validation in software engineering pipelines using deep learning, especially when relying on open-source training data.

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.