Security
AI Coding Assistant Writes Insecure Code 100% of the Time Without Context-Specific Rules
A controlled experiment shows that learned security rules from real vulnerabilities prevent proxy trust bugs, while generic guardrails miss context-dependent weaknesses.
Key takeaways
- AI coding assistants wrote proxy trust vulnerabilities in 8 of 8 attempts without learned security rules, but 0-1 of 4 with context-specific rules from real code.
- Generic security rules for SQL injection, command injection, and path traversal showed zero measurable effect because modern models already avoid these well-documented patterns.
- A simple canary rule proved essential for verifying that security guardrails actually reach the AI agent before measuring their effectiveness.
- Adding 25 security rules to agent workspaces produced no measurable increase in token costs across 39 million tokens of generation.
- Context-dependent vulnerabilities that depend on specific infrastructure or architecture remain the primary risk area where learned rules provide value.
When an AI coding assistant receives a straightforward feature request with no security hints, how often does it introduce vulnerabilities? A new controlled experiment from Cisco's DevNet team provides a concrete answer: consistently, unless the assistant has access to security rules learned from real code in similar contexts.
The experiment tested Claude Sonnet 4.6 through Cursor across 72 sessions with three different rule configurations. Twelve ordinary feature requests—the kind developers make daily—were executed in workspaces that differed only in their security rules. A blind automated judge evaluated all outputs after stripping identifying comments.
The proxy trust problem persists
The most striking results came from requests involving proxy headers. When asked to implement rate limiting behind a load balancer or an office network allowlist behind Cloudflare, unprotected agents wrote vulnerable code in every attempt. They trusted client-controlled headers like the first entry in X-Forwarded-For or CF-Connecting-IP without verifying the connection actually came through the expected proxy.
With rules learned from a real Langflow vulnerability discovered earlier in the research series, the results flipped. Protected agents checked the actual TCP peer address first, then validated it against known proxy ranges before trusting any forwarding headers. On the Cloudflare task, both protected sessions verified the connection originated from Cloudflare's published address ranges before reading the CF-Connecting-IP header.
The control group produced vulnerable code in 8 of 8 relevant attempts. The group with learned rules produced it in 0 or 1 of 4, depending on how borderline cases are judged. Both differences are statistically significant despite the small sample size.
Generic rules made no measurable difference
Project CodeGuard's core rules—covering SQL injection, command injection, and path traversal—showed zero effect. The agent wrote safe code for these classes in every configuration, including the control group with no security rules at all.
This outcome reveals something important about the current state of AI coding assistants. Common vulnerabilities that have been widely documented are already baked into the training data. Modern models write parameterized queries and safe subprocess calls by default. The vulnerabilities that still slip through are context-dependent: proxy trust checks that depend on your infrastructure, parsing logic that depends on your data formats, authorization patterns that depend on your architecture.
The canary rule
Before measuring whether rules work, the experiment verified they actually reached the agent. A harmless "house-style" comment rule served as a canary, appearing in all 72 sessions. This simple check caught three configuration requirements that would have silently broken rule delivery: rules must use .mdc files with a specific format, the Cursor SDK requires explicit configuration to load project rules, and scoped rules only attach to files the agent actually touches.
Why it matters
Organizations deploying AI coding assistants often assume generic security guardrails provide meaningful protection. This experiment demonstrates that assumption is backwards. Generic rules protect against vulnerabilities models already avoid, while context-specific rules learned from an organization's own code prevent the subtle mistakes that still occur. The 39 million tokens used across 72 sessions showed no cost difference between rule configurations, making learned rules essentially free to deploy after the one-time analysis cost.
The work was detailed by Cisco DevNet in the fourth installment of their Foundry research series, with full experimental design, all generated code, and reproduction instructions available in their public repository.
Limitations and next steps
The research team notes important constraints. The experiment used a single model through one agent interface with small sample sizes. Tasks were designed to test patterns found in earlier vulnerability discoveries, not to evaluate synthesized rules in general. The judge and rules derive from the same model family, though verdicts were manually audited.
The final installment of the series will demonstrate all components—vulnerability detection, rule synthesis, and prevention—working together in response to a real security advisory.