← Lab /Software

Contextual inputs raise vulnerable code generation to 37.4% across major code models

Strategically crafted comments, documentation, and variable names increase insecure code output by 10.7× and enable 100% attack success on GPT-3.5-Turbo

Software arXiv 9 Jun 2026 Attack Prototype evidence Threat model

Published as “Context-Based Adversarial Attacks on AI Code Generators: Vulnerability Analysis and Implications”

Why it matters

Organizations using AI-assisted code generation face a measurable increase in insecure code risk that can be mitigated with low-overhead, real-time detection.

Summary

Adversarial context increases vulnerability generation by 10.7× (from 3.5% to 37.4%) across four code generators. Direct instruction attacks achieve 100% success on GPT-3.5-Turbo, and cross-model transferability reaches up to 100%, indicating systemic architectural issues. A dual-layer detection framework attains 89.1% detection with only 0.3% false positives and 520 ms latency, showing practical feasibility. The evidence is based on 2,800 controlled experiments with statistical significance, but the study is limited to Python/JavaScript and 512-token prompts.

What they found 2

  1. Adversarial context raises vulnerability generation rate 10.7×

    “adversarial conditions increased the mean vulnerability generation rate (VGR) from 3.5% under baseline conditions to 37.4% under adversarial conditions, a 10.7× increase”

  2. Direct instruction attacks achieve perfect success on GPT-3.5-Turbo

    “Direct instruction achieved the highest mean ASR at 55%, with GPT-3.5-Turbo reaching 100% (χ2 = 421.8, p < 0.001, d = 2.7)”

Caveats 5

  • Commercial models show higher adversarial VGR than open-source models, suggesting model-specific differences despite the claim of systemic architectural vulnerability.
  • The experiments used Python and JavaScript only and may not generalize to other languages.
  • Prompt contexts were limited to 512 tokens, so the positional effects observed here may differ in longer production contexts (4K-32K tokens).
  • The models evaluated represent versions available as of December 2024, and newer iterations may exhibit different vulnerability profiles.
  • The defense framework reflects detection capabilities at a fixed point in time; adaptive adversaries may develop evasion strategies.

What’s new here 3

  • Systematic quantification of context-based adversarial attacks across both open-source and commercial code generators.
  • Cross-model transferability analysis showing up to 100% effectiveness between different architectures.
  • A real-time, two-layer detection framework with sub-1% false-positive rate suitable for IDE integration.

Threat model stated by the source

AdversaryAttacker who can modify comments, documentation strings, variable names, or reference examples supplied to the code generator
CapabilityInject malicious contextual cues without access to model parameters, training data, or deployment infrastructure
AssumesModified context appears legitimate to human reviewers; Model parameters remain unchanged