Black-Box Adversarial Attacks on LLM-Based Code Completion
Not on the map. Why?
Abstract (arXiv)
Modern code completion engines, powered by large language models (LLMs), assist millions of developers with their strong capabilities to generate functionally correct code. Due to this popularity, it is crucial to investigate the security implications of relying on LLM-based code completion. In this work, we demonstrate that state-of-the-art black-box LLM-based code completion engines can be stealthily biased by adversaries to significantly increase their rate of insecure code generation. We present the first attack, named INSEC, that achieves this goal. INSEC works by injecting an attack string as a short comment in the completion input. The attack string is crafted through a query-based optimization procedure starting from a set of carefully designed initialization schemes. We demonstrate INSEC's broad applicability and effectiveness by evaluating it on various state-of-the-art open-source models and black-box commercial services (e.g., OpenAI API and GitHub Copilot). On a diverse set of security-critical test cases, covering 16 CWEs across 5 programming languages, INSEC increases the rate of generated insecure code by more than 50%, while maintaining the functional correctness of generated code. We consider INSEC practical -- it requires low resources and costs less than 10 US dollars to develop on commodity hardware. Moreover, we showcase the attack's real-world deployability, by developing an IDE plug-in that stealthily injects INSEC into the GitHub Copilot extension.
Key facts. Cited by 13 papers in the map (data through 7 Oct 2026). Builds on 35 of its 51 references that are in the map. First posted on arXiv 5 Aug 2024.
Builds on
35 of 51 references.
References · 35
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2023SWE-bench: Can Language Models Resolve Real-World GitHub Issues?cited by 3,193
- 2023Universal and Transferable Adversarial Attacks on Aligned Language Modelscited by 2,914
- 2023Code Llama: Open Foundation Models for Codecited by 2,105
- 2022CodeGen: An Open Large Language Model for Code with Multi-Turn Program Synthesiscited by 876
- 2023StarCoder: may the source be with you!cited by 790
- 2023Baseline Defenses for Adversarial Attacks Against Aligned Language Modelscited by 608
- 2022InCoder: A Generative Model for Code Infilling and Synthesiscited by 492
- 2024StarCoder 2 and The Stack v2: The Next Generationcited by 484
- 2020CodeBLEU: a Method for Automatic Evaluation of Code Synthesiscited by 468
- 2024Jailbreaking Leading Safety-Aligned LLMs with Simple Adaptive Attackscited by 450
- 2021Asleep at the Keyboard? Assessing the Security of GitHub Copilot's Code Contributionscited by 417
23 more
- 2023RepoBench: Benchmarking Repository-Level Code Auto-Completion Systemscited by 346
- 2023CodeGeeX: A Pre-Trained Model for Code Generation with Multilingual Benchmarking on HumanEval-Xcited by 294
- 2023Low-Resource Languages Jailbreak GPT-4cited by 290
- 2023Poisoning Web-Scale Training Datasets is Practicalcited by 276
- 2022Efficient Training of Language Models to Fill in the Middlecited by 248
- 2022Grounded Copilot: How Programmers Interact with Code-Generating Modelscited by 216
- 2022Do Users Write More Insecure Code with AI Assistants?cited by 186
- 2023Large Language Models for Code: Security Hardening and Adversarial Testingcited by 149
- 2022MultiPL-E: A Scalable and Extensible Approach to Benchmarking Neural Code Generationcited by 132
- 2020You Autocomplete Me: Poisoning Vulnerabilities in Neural Code Completioncited by 112
- 2024Coercing LLMs to do and reveal (almost) anythingcited by 88
- 2023How Secure is Code Generated by ChatGPT?cited by 77
- 2024CodeAttack: Revealing Safety Generalization Challenges of Large Language Models via Code Completioncited by 70
- 2023Language Model Inversioncited by 66
- 2024Instruction Tuning for Secure Code Generationcited by 63
- 2023CodeLMSec Benchmark: Systematically Evaluating and Finding Security Vulnerabilities in Black-Box Code Language Modelscited by 52
- 2023TrojanPuzzle: Covertly Poisoning Code-Suggestion Modelscited by 47
- 2022CCTEST: Testing and Repairing Code Completion Systemscited by 35
- 2024An LLM-Assisted Easy-to-Trigger Backdoor Attack on Code Completion Models: Injecting Disguised Vulnerabilities against Strong Detectioncited by 32
- 2023DeceptPrompt: Exploiting LLM-driven Code Generation via Adversarial Natural Language Instructionscited by 31
- 2024An Empirical Study of Static Analysis Tools for Secure Code Reviewcited by 17
- 2022Detecting False Alarms from Automatic Static Analysis Tools: How Far are We?cited by 16
- 2024ShadowCode: Towards (Automatic) External Prompt Injection Attack against Code LLMscited by 4
Built on by
Citing papers per year: 2025: 10; 2026: 3.
13 papers.
Sort:
By area:
- 2025LlamaFirewall: An open source guardrail system for building secure AI agentscited by 114
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 38
- 2025RedCoder: Automated Multi-Turn Red Teaming for Code LLMscited by 8
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistantscited by 4
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilitiescited by 4
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactualscited by 1
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AIcited by 1
- 2025PARASITE: Conditional System Prompt Poisoning to Hijack LLMscited by 0
- 2025A Systematic Evaluation of Parameter-Efficient Fine-Tuning Methods for the Security of Code LLMscited by 0
- 2025ForgeDAN: An Evolutionary Framework for Jailbreaking Aligned Large Language Modelscited by 0
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimizationcited by 0
- 2026Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detectioncited by 0
1 more
- 2026CS-Guard: Benchmarking LLM Guardrails for Code Generation Security9 Sep 2026
- 2026Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detection29 Jun 2026
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization8 May 2026
- 2025ForgeDAN: An Evolutionary Framework for Jailbreaking Aligned Large Language Models17 Nov 2025
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AI20 Oct 2025
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities30 Sep 2025
- 2025A Systematic Evaluation of Parameter-Efficient Fine-Tuning Methods for the Security of Code LLMs16 Sep 2025
- 2025RedCoder: Automated Multi-Turn Red Teaming for Code LLMs25 Jun 2025
- 2025PARASITE: Conditional System Prompt Poisoning to Hijack LLMs22 May 2025
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactuals20 May 2025
- 2025LlamaFirewall: An open source guardrail system for building secure AI agents6 May 2025
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants18 Mar 2025
1 more
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?17 Feb 2025
- 2025LlamaFirewall: An open source guardrail system for building secure AI agentscited by 114
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilitiescited by 4
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AIcited by 1
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimizationcited by 0
- 2026SecureForge: Finding and Preventing Vulnerabilities in LLM-Generated Code via Prompt Optimization8 May 2026
- 2025BlueCodeAgent: A Blue Teaming Agent Enabled by Automated Red Teaming for CodeGen AI20 Oct 2025
- 2025Red Teaming Program Repair Agents: When Correct Patches can Hide Vulnerabilities30 Sep 2025
- 2025LlamaFirewall: An open source guardrail system for building secure AI agents6 May 2025
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?cited by 38
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistantscited by 4
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactualscited by 1
- 2025PARASITE: Conditional System Prompt Poisoning to Hijack LLMscited by 0
- 2025A Systematic Evaluation of Parameter-Efficient Fine-Tuning Methods for the Security of Code LLMscited by 0
- 2026Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detectioncited by 0
- 2026Words Speak Louder Than Code: Investigating Cognitive Heuristics in LLM-Based Code Vulnerability Detection29 Jun 2026
- 2025A Systematic Evaluation of Parameter-Efficient Fine-Tuning Methods for the Security of Code LLMs16 Sep 2025
- 2025PARASITE: Conditional System Prompt Poisoning to Hijack LLMs22 May 2025
- 2025Success is in the Details: Evaluate and Enhance Details Sensitivity of Code LLMs through Counterfactuals20 May 2025
- 2025XOXO: Stealthy Cross-Origin Context Poisoning Attacks against AI Coding Assistants18 Mar 2025
- 2025BaxBench: Can LLMs Generate Correct and Secure Backends?17 Feb 2025