NameTrap: Steering AI Coding Agents Toward Security Vulnerabilities via Variable Names
Chieh-Yuan Chang, Guan-Wei Chen, Chia-Yi Hsu, Chih Yang, Chia-Mu Yu, Chun-Ying Huang
Abstract
AI coding agents routinely clone repositories, install packages, and read source code obtained from the Web, so publicly hosted code becomes part of the context that shapes the code they write. We show that this Web-borne context can be weaponized without any explicit instruction. We present NameTrap, a source-code poisoning attack that only renames identifiers in third-party Python files to steer AI coding agents toward attacker-targeted Common Weakness Enumeration (CWE) vulnerabilities. An attacker-side coding agent iteratively aligns identifiers with a CWE-specific naming convention and confirms through local probe completions that the renamed file elicits the target weakness, while the released bait contains neither instructions nor vulnerable statements. We evaluate NameTrap across six AI coding agents, ten underlying language models, and four vulnerability categories: CWE-78, CWE-79, CWE-327, and CWE-502. Starting from files whose clean versions never yield the targeted CWE, identifier-level manipulation achieves overall attack success rates of 22.5\% to 56.0\% across the six agents, reaching 75.0\% for certain agent--model configurations, and substantially outperforms random renaming, neutral renaming, and the prior identifier-poisoning attack XOXO. The attack remains effective under Traditional Chinese prompts and transfers across models, while a security-reminder defense fails to consistently prevent vulnerability introduction. Moreover, three AI-based security analyzers and four static analyzers report none of the targeted weaknesses in the poisoned files. These findings expose an overlooked attack surface of agents that consume Web content: seemingly harmless variable names in untrusted, Web-hosted code can compromise the security of downstream software.
Create a lesson
Metadata
- Categories
- cs.CR, cs.AI
Related papers
RiskyPy: Toward Model-Calibrated Prompt Generation for Joint Security and Functionality Evaluation of LLM-Generated Code
Shared title terminologycs.CRZacharie Chenail-Larcher, Daniele Lunghi, Melissa Tessa et al.
ParseGap: Testing What Coding Agents Authorize and What Shells Execute
Shared title terminologycs.CRJieyu Li
Who Is Prompt-Injecting Coding Agents? An Empirical Study of Hidden AI-Directed Text on GitHub
Shared title terminologycs.CRGabi Nakibly, Zvika Babo
Who Grades the Agent? Privilege Separation for Coding-Agent Benchmarks
Shared title terminologycs.CRNathan Nour Houlamy, Mattia Favretto, Earlence Fernandes et al.
Mjolnir: Finding and Reproducing Vulnerabilities in Root-of-Trust Firmware and RTL with Project-Grounded Agents
Shared title terminologycs.CRCollin MacDonald, Carl Lundin, Stephen Herwig et al.
Replication of Agentic Security Events: Audit and Investigation (ROGUE-AI)
Shared title terminologycs.CRMengxiao Wang, Mahbub Alam, Kalyan Nakka et al.