TL;DR
Can a simple "security paragraph" in your AI prompt actually protect your code? This study of 400 AI-generated web applications finds that security-focused prompting cuts reported vulnerabilities by a third, but there’s a catch: it also doubles your "dependency surface," inviting a host of third-party libraries—and their baggage—to the party.
What Problem Does This Paper Address?
We are entering the era of "agentic coding" or, more colloquially, "vibe coding." Instead of just asking an AI to autocomplete a function, we’re giving it a high-level specification and letting it build, install, and iterate on an entire deployable web application.
The problem is that when an AI agent builds a whole system, it makes a thousand tiny decisions about authentication, session handling, and input validation on your behalf. If you don't explicitly tell it to be secure, it defaults to whatever is easiest to get the app running. This paper investigates whether a "portable" fix—appending a standard block of security requirements (based on the OWASP Top 10) to a prompt—actually moves the needle on security, or if it just creates new, hidden risks.
Methods
The researcher conducted a controlled experiment with a 2 × 2 × 100 design:
- Two Agentic Tools: Claude Code (Anthropic) and Codex CLI (OpenAI).
- Two Prompt Variants:
- Variant A: A neutral functional specification (e.g., "Build a tiny web app that greets a user").
- Variant B: The same functional core plus a byte-identical paragraph of mandatory security requirements (parameterized queries, password hashing, CSRF protection, etc.).
- 100 Specifications: Ranging from simple utilities to complex platform-style systems.
The resulting 400 applications were fed into a rigorous security pipeline involving static analysis (SAST) tools like Bandit and ESLint, and dynamic analysis (DAST) tools like OWASP ZAP and sqlmap.
Datasets
The study utilized a custom-authored and "frozen" (SHA-256 locked) catalog of 100 application specifications. These were categorized into:
- Four Complexity Tiers: From T1 (simple utilities) to T4 (multi-role platforms).
- Three Ecosystems: Node.js (Express), Python (Flask/FastAPI), and plain PHP.
The final analysis was performed on a population of 6,721 triaged security findings.
Key Insights and Ideas
- The "Dependency Tax": This is the most fascinating "aha" moment. When you tell an AI to "be secure," it doesn't just write better code; it goes shopping for libraries. To satisfy a requirement for "strong password hashing," the AI might install
bcrypt. This roughly doubled the declared dependency surface. - The Illusion of Increased Risk: Because the AI installed more libraries, the scanners reported more high-severity dependency advisories in absolute terms for the "secure" apps. At first glance, it looks like the security prompt failed.
- First-Party vs. Third-Party: However, when you look at the code the AI actually wrote (first-party code), high-severity findings fell by nearly half. The "extra" vulnerabilities were all hiding in the native build chains of the libraries the AI chose to install.
- Mechanism over Outcome: The AI treated security requirements as "features to implement" rather than "constraints to follow." Even for apps with no users, the AI would dutifully install authentication and session machinery just because the prompt mentioned it.
Key Results
- 35% Reduction in Findings: Variant B (the secure prompt) was associated with 35% fewer total findings per application compared to Variant A.
- Tool Agnosticism: The effect was remarkably uniform across both Claude and Codex, suggesting that security-focused prompting is a portable best practice regardless of which "agent" you use.
- Complexity Attenuation: The security block was most effective on simpler apps (T1/T2), where it provided a ~40% reduction. On complex apps (T3/T4), the benefit dropped to roughly 26-30%, likely because the "fixed cost" of basic hygiene matters less as the functional core grows.
- The Surface Adjustment: When adjusted for the enlarged dependency surface, the rate of advisories per dependency actually stayed flat or slightly decreased.
Limitations and Future Work
- Prescriptive Bias: The security block used in the study was very specific (naming mechanisms like "bcrypt"). This likely forced the AI to add features (and dependencies) that weren't strictly necessary for every app.
- Scanner Noise: The study relies on tool-reported findings, which are notorious for false positives. The findings represent "reported risk" rather than "confirmed exploitability."
- Future Direction: The author suggests a "third generation" of prompting where we don't just name the capability (e.g., "hash passwords"), but also name the specific, lightweight library to use (e.g., "use
bcryptjsinstead ofbcrypt"). This could potentially provide the security benefits without the heavy "dependency tax" of native build chains.
In short: Telling the AI to be secure is a cheap and effective win, but you better be prepared to audit the "uninvited guests" (dependencies) it brings to the party.
Summary updated