Skip to main content
QUICK REVIEW

[Paper Review] TrojanPuzzle: Covertly Poisoning Code-Suggestion Models

Hojjat Aghakhani, Wei Dai|arXiv (Cornell University)|Jan 6, 2023
Advanced Malware Detection TechniquesComputer Science6 citations
TL;DR

This paper introduces Covert and TrojanPuzzle, novel data-poisoning attacks that covertly train code-suggestion models to recommend insecure code by embedding malicious payloads in docstrings or using template-based substitution, bypassing static analysis and signature-based defenses. TrojanPuzzle achieves this without explicitly including the payload in training data, making it highly stealthy and effective, with attack success rates of up to 80% on fine-tuned models even after defensive pruning.

ABSTRACT

With tools like GitHub Copilot, automatic code suggestion is no longer a dream in software engineering. These tools, based on large language models, are typically trained on massive corpora of code mined from unvetted public sources. As a result, these models are susceptible to data poisoning attacks where an adversary manipulates the model's training by injecting malicious data. Poisoning attacks could be designed to influence the model's suggestions at run time for chosen contexts, such as inducing the model into suggesting insecure code payloads. To achieve this, prior attacks explicitly inject the insecure code payload into the training data, making the poison data detectable by static analysis tools that can remove such malicious data from the training set. In this work, we demonstrate two novel attacks, COVERT and TROJANPUZZLE, that can bypass static analysis by planting malicious poison data in out-of-context regions such as docstrings. Our most novel attack, TROJANPUZZLE, goes one step further in generating less suspicious poison data by never explicitly including certain (suspicious) parts of the payload in the poison data, while still inducing a model that suggests the entire payload when completing code (i.e., outside docstrings). This makes TROJANPUZZLE robust against signature-based dataset-cleansing methods that can filter out suspicious sequences from the training data. Our evaluation against models of two sizes demonstrates that both COVERT and TROJANPUZZLE have significant implications for practitioners when selecting code used to train or tune code-suggestion models.

Motivation & Objective

  • To investigate whether data-poisoning attacks on code-suggestion models can bypass static analysis and signature-based detection by hiding malicious payloads in out-of-context regions like docstrings.
  • To develop a novel poisoning technique that avoids explicitly including the insecure payload in training data while still inducing the model to suggest the full malicious payload during code completion.
  • To evaluate the effectiveness of existing defenses—particularly model pruning and fine-tuning—against these stealthy poisoning attacks.
  • To assess the robustness of code-suggestion models to poisoning when trained on datasets contaminated with seemingly benign, yet maliciously crafted, docstring-based poison samples.

Proposed method

  • Covert attack injects malicious code payloads into docstrings, which are typically ignored by static analysis tools, to train the model to suggest insecure code completions when triggered.
  • TrojanPuzzle introduces a template-based approach where the payload’s suspicious components are replaced with placeholders (e.g., <template>), and multiple poison samples are created with randomized replacements to teach the model the association without exposing the full payload.
  • The model learns to substitute the placeholder with the full malicious payload during code completion, even though the payload is never fully present in the training data.
  • The attacks are evaluated on code-suggestion models of two sizes, using HumanEval benchmarks to measure attack success and model performance under various defense strategies.
  • Defensive strategies such as 4% and 8% weight pruning followed by fine-tuning are tested to assess their resilience against the attacks, including scenarios with poisoned defense datasets.
  • The study uses controlled experiments with trigger contexts (e.g., Flask template rendering) and measures attack success via pass@1, pass@10, and pass@50 metrics on the HumanEval benchmark.

Experimental results

Research questions

  • RQ1Can data-poisoning attacks on code-suggestion models be made undetectable by static analysis by placing malicious payloads in docstrings?
  • RQ2Can a poisoning attack induce a model to suggest a complete malicious payload without ever including the full payload in the training data?
  • RQ3How effective are signature-based data-cleansing methods against poisoning attacks that hide malicious content in non-executable regions like comments?
  • RQ4To what extent do model pruning and fine-tuning mitigate the impact of stealthy poisoning attacks like Covert and TrojanPuzzle?
  • RQ5Does the presence of even a small number of poisoned examples in a defense dataset compromise the effectiveness of pruning-based defenses?

Key findings

  • TrojanPuzzle achieved an attack success rate of 80% on the larger model and 55% on the smaller model under standard fine-tuning, demonstrating high effectiveness despite no explicit payload in training data.
  • Covert achieved 80% attack success on the larger model and 52.5% on the smaller model, showing that even without template substitution, docstring-based poisoning remains highly effective.
  • After 4% weight pruning and fine-tuning, the attack success rate for TrojanPuzzle dropped to 25% on the smaller model, but remained at 80% on the larger model, indicating limited defense effectiveness.
  • When the defense dataset was poisoned with just 0.1% malicious files, the attack success rate for TrojanPuzzle remained at 55% after fine-tuning, showing that pruning-based defenses are vulnerable to minimal contamination.
  • The general performance of fine-pruned models declined by up to 3.38 percentage points in pass@50 score when poisoned by TrojanPuzzle, indicating a significant trade-off between defense and model utility.
  • The study found that fine-tuning on poisoned datasets can actually increase attack success rates over time, especially when only a few epochs are used, highlighting the risk of incomplete or flawed defense pipelines.

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.