atlas

Research map / Adversarial robustness and security / Black-box and transfer attacks

Black-Box Adversarial Attacks on LLM-Based Code Completion

ICML 2025 · Adversarial robustness and security › Black-box and transfer attacks · approach: Query-efficient black-box attacks · 1 citations (OpenAlex)

Read the paperCheck your idea against 108,967 papers

AI-extracted summary. Written by AI from the paper's full text. Numbers and claims can be wrong or missing context, so check the paper before you cite or build on it.

Proposes INSEC, a black-box attack that injects an optimized adversarial comment into code completion queries to make LLM-based completion engines (including GitHub Copilot and GPT-3.5-Turbo-Instruct) generate more insecure code while preserving functional correctness.

Problem

LLM-based code completion engines can be induced to generate insecure code, and existing attacks require white-box access to weights or training data, which is unrealistic for deployed black-box services like GitHub Copilot.

Approach

Manipulate only the input: insert a short, fixed adversarial attack string as a comment on the line above the completion point, optimized via query-based random search (mutation and top-n selection) with six initialization strategies (e.g., security-critical token, inversion, sanitizer), using a proxy tokenizer so no model internals are needed.

Key results

Measured effects reported in the paper

What was changedWhereMeasuredEffect
Insert an optimized attack commentGPT-3.5-Turbo-Instruct · 16 CWEsvulnerability rate: 22% -> 73%Helped
Apply an attack string optimized on StarCoder-3BGPT-3.5-Turbo-Instruct · 16 CWEsvulnerability rate: 22% to 55%Helped
Apply an attack string optimized on CodeLlama-7BGPT-3.5-Turbo-Instruct · 16 CWEsvulnerability rate: 22% to 59%Helped
Optimize the initialized attack string (ablation)GPT-3.5-Turbo-Instruct · CWE-022 Path Traversalvulnerability rate: 65% -> 96%Helped
Optimize a randomly initialized attack string (ablation)StarCoder-3B · CWE-131 Buffer Sizevulnerability rate: ≤ 14% -> 63%Helped
Place the attack string as a comment on the line above the completion (ablation)INSEC · Validation datasetsvulnerability rate and functional correctnessHelped
Format the attack string as a comment rather than inserting it without a comment symbol (ablation)INSEC · Validation datasetsvulnerability rate: +6%Helped
Format the attack string as a comment rather than inserting it without a comment symbol (ablation)INSEC · Validation datasetsfunctional correctness: +11%Helped
Use initialization strategies without optimization (ablation)INSEC · Validation datasetsvulnerability rate: 50%Helped
Optimize initialized attack strings rather than stopping after initialization (ablation)INSEC · Validation datasetsvulnerability rateHelped
Set attack-string pool size to 20 rather than too small or too large (ablation)INSEC on StarCoder-3B · Validation datasetsattack impactHelped
Increase attack-string length from one token to five tokens (ablation)INSEC on StarCoder-3B · Validation datasetsvulnerability rateHelped

Surprising findings

Limitations

Experimental setup

Datasets: custom vulnerability dataset (16 CWEs, 5 languages, 12 tasks per CWE) HumanEval-derived multilingual completion dataset (GPT-4 reference solutions) HumanEval-X (validation of reference solutions) RepoBench

Benchmarks: custom INSEC vulnerability test set (16 CWEs) HumanEval-based multilingual functional correctness RepoBench

Metrics: vulnerability rate (vulRate) pass@k functional correctness ratio exact match edit similarity CodeBLEU

Baselines: unattacked engine (original completion) initialization-only attack strings CodeQwen tokenizer proxy variants

Builds on: fill-in-the-middle code completion random optimization jailbreak attacks Asleep at the Keyboard (insecure code evaluation)

Closest papers by meaning

Writing a paper in this area? scime draft is a free LaTeX editor with AI included, real-time co-authors and a check of your references and venue rules before you submit. It also imports OpenAI Prism projects.

Open scime draft

Get the next scime Dispatch and a monthly field update

Free. We send a confirmation link first; every email has a one-click unsubscribe. Privacy