Automated tool crafts hidden code attacks in software repositories

Trojan Horse: Automated Repository Poisoning against Coding Agents

Cryptography and Security

Summary

Software coding assistants can now write code by themselves, but this makes them vulnerable to bad code hidden inside source code libraries. The authors introduce TrojanForge, a system that automatically hides harmful code inside software repositories in ways that are hard for coding agents to detect. They also created a set of example poisoned repositories called TrojanBench to test defenses. Their experiments show that many smart coding agents, even commercial ones, have trouble spotting these hidden threats.

What this means in practice

  • For software security teams: Test coding agents against realistic repository backdoor attacks using TrojanBench to improve detection and prevention methods.
  • For software development teams: Evaluate the security risks of automated coding tools by simulating repository poisoning scenarios to harden supply chain defenses.

Authors

Xiao Yang, Jinchang Hou, Jiawei Chen, Zhonghou Lv, Junyuan Shang, Chenfu Bao

Abstract

Coding agents are increasingly capable with autonomy, which exposes them to repository-level poisoning. Existing red-teaming studies remain restricted to manual selection for malicious payload locations and fixed disguise strategies, which cannot represent realistic repository poisoning. We present TrojanForge, the first automated framework for repository poisoning. TrojanForge parses repository structure through abstract syntax trees (AST) and maps agent execution traces onto AST nodes. A security review agent ranks these candidates and selects the least conspicuous ones for payload mounting. Then, through adversarial play with the target agent, TrojanForge iteratively refines disguise strategies by inverting the causes of agent detection, and transfers accumulated success experience across repositories. We further construct TrojanBench, a benchmark of 384 poisoned repositories spanning 6 domains and 9 programming languages. Extensive experiments show that TrojanForge achieves a stable poisoning success rate of over 60% with backdoor injection exceeding 90%. Comprehensive evaluation on TrojanBench across 4 harnesses and 12 models reveals that even commercial agents fail to defend against repository-level poisoning.