← Lab /AI/ML

Targeted poisoned artifacts cause retrieval-augmented code generators to produce vulnerable code

A black-box attacker can inject a single crafted artifact into a RACG system and cause it to generate code with attacker-chosen vulnerabilities

AI/ML arXiv 2 Sep 2026 Attack Prototype evidence

Published as “CodePoisonRAG: Knowledge Poisoning Attacks on Retrieval-Augmented Code Generation”

Why it matters

Even a tiny amount of malicious code in a retrieval corpus can reliably induce vulnerable outputs, highlighting the need for stronger validation and sanitization of retrieved artifacts in RACG pipelines.

Summary

CodePoisonRAG can cause retrieval-augmented code generation systems to emit vulnerable code with an overall attack success rate of 0.93 (79/85) while poisoning only 0.7% of the knowledge base, and it still achieves a 0.71 success rate even against a security-oriented defense. The evidence comes from extensive experiments on ten CWEs, three LLM generators, and both defended and undefended settings, showing near-perfect retrieval and high ASR.

What they found 2

  1. Overall attack success rate of 0.93 (79/85) in the undefended setting

    “CodePoisonRAG achieves an overall attack success rate of 79/85 (0.93)”

  2. All 85 poisoned snippets are retrieved within the Top-3 results for their queries

    “All 85 poisoned snippets are retrieved and appear within the Top-3 ranked snippets for their corresponding trigger queries.”

Caveats 4

  • The attack achieves an overall success rate of 0.71 under defense, with 60/85 generated responses still validated as vulnerable.
  • SQL injection (CWE-89) remains slightly harder, with 9/10 successes.
  • Deserialization (CWE-502) is the main outlier, with 5/10 successes.
  • DeepSeek reports higher ASR in both scenarios, reaching 1.00 without defense and 0.612 under defense, compared with 0.80 and 0.40 from GLM-5.1.

What’s new here 4

  • Constructs task-aligned poisoned code snippets rather than reusing existing vulnerable samples.
  • Uses a two-stage attack chain (vulnerability injection and semantic mislabeling) to hide the weakness in comments.
  • Requires only a single poisoned artifact per target query, achieving a poisoning footprint of 0.7% of the corpus.
  • Demonstrates effectiveness across multiple generators and against the CodeGuarder defense.