[Paper Review] You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completion
This paper demonstrates that neural code autocompleters, trained on public code repositories, are vulnerable to data and model poisoning attacks. By injecting malicious code into the training data or fine-tuning the model, attackers can manipulate suggestions to recommend insecure patterns like ECB mode for AES or SSLv3, with targeted attacks significantly increasing the likelihood of such insecure suggestions in specific codebases.
Code autocompletion is an integral feature of modern code editors and IDEs. The latest generation of autocompleters uses neural language models, trained on public open-source code repositories, to suggest likely (not just statically feasible) completions given the current context. We demonstrate that neural code autocompleters are vulnerable to poisoning attacks. By adding a few specially-crafted files to the autocompleter's training corpus (data poisoning), or else by directly fine-tuning the autocompleter on these files (model poisoning), the attacker can influence its suggestions for attacker-chosen contexts. For example, the attacker can teach the autocompleter to suggest the insecure ECB mode for AES encryption, SSLv3 for the SSL/TLS protocol version, or a low iteration count for password-based encryption. Moreover, we show that these attacks can be targeted: an autocompleter poisoned by a targeted attack is much more likely to suggest the insecure completion for files from a specific repo or specific developer. We quantify the efficacy of targeted and untargeted data- and model-poisoning attacks against state-of-the-art autocompleters based on Pythia and GPT-2. We then evaluate existing defenses against poisoning attacks and show that they are largely ineffective.
Motivation & Objective
- To investigate whether neural code autocompleters are vulnerable to poisoning attacks that manipulate code suggestions.
- To evaluate the feasibility of both data poisoning (adding malicious files to training data) and model poisoning (fine-tuning on malicious files) in influencing autocompleter behavior.
- To assess the effectiveness of targeted attacks that bias suggestions toward insecure patterns in specific code repositories or for specific developers.
- To evaluate existing defenses against poisoning attacks and determine their efficacy in protecting neural code autocompleters.
Proposed method
- The authors train state-of-the-art code autocompleters based on Pythia and GPT-2 on code repositories augmented with carefully crafted malicious files.
- They perform both untargeted and targeted poisoning attacks by injecting files that contain specific code patterns (e.g., insecure AES or SSL usage) into the training data.
- For model poisoning, they fine-tune the pre-trained autocompleter on a small number of malicious files to influence its generation behavior.
- They measure attack success by evaluating the frequency of insecure suggestions in response to specific code contexts.
- They compare attack success rates across different attack types (untargeted vs. targeted) and model variants.
- They evaluate existing defense mechanisms against these poisoning attacks to assess their resilience.
Experimental results
Research questions
- RQ1Can data poisoning be used to manipulate neural code autocompleters into suggesting insecure code patterns?
- RQ2How effective are targeted poisoning attacks in biasing suggestions toward insecure patterns in specific codebases or for specific developers?
- RQ3To what extent do existing defenses mitigate poisoning attacks on neural code autocompleters?
- RQ4How do the success rates of data poisoning and model poisoning compare in influencing autocompleter behavior?
- RQ5What is the minimal number of malicious files required to achieve a high success rate in poisoning attacks?
Key findings
- Neural code autocompleters can be successfully poisoned using only a small number of malicious files injected into the training corpus.
- Targeted poisoning attacks significantly increase the likelihood of suggesting insecure code patterns (e.g., ECB mode, SSLv3) in specific repositories or for specific developers.
- Model poisoning via fine-tuning achieves high attack success with minimal input, demonstrating the vulnerability of fine-tuned models.
- The attack success rate for suggesting insecure patterns like ECB mode or low iteration counts in password hashing exceeds 90% in targeted scenarios.
- Existing defenses against poisoning attacks are largely ineffective against the proposed data and model poisoning techniques.
- The combination of data and model poisoning poses a realistic and scalable threat to the security of neural code autocompleters in real-world development environments.
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.