Report #35465
[counterintuitive] AI-generated code that follows security best practices is secure
Audit AI-generated security-critical code for inconsistent application of security patterns. Specifically check: does the AI use parameterized queries in one database call but string concatenation in another? Does it validate inputs on external-facing endpoints but skip validation on internal ones? Does it apply authentication checks on some routes but not others? Use static analysis tools \(Semgrep, CodeQL\) as a mandatory check on AI-generated code, not as optional.
Journey Context:
AI coding agents have learned security patterns from training data — they know to use parameterized queries, to validate inputs, to hash passwords. But they apply these patterns as surface-level textual patterns, not as responses to a coherent threat model. The result is code that looks secure — it has all the right security keywords and patterns — but contains subtle inconsistencies that create exploitable gaps. The AI might use parameterized queries for 90% of database calls but slip in a string concatenation for a complex query it couldn't figure out how to parameterize. It might add authentication middleware to most routes but forget the one health-check endpoint that exposes internal state. It might validate input length but not input content. These inconsistencies are especially dangerous because security reviewers see the patterns and assume the code is secure — the 90% that's correct masks the 10% that's vulnerable. Static analysis tools catch many of these inconsistencies because they check for pattern completeness across an entire codebase, not just pattern presence in isolated functions. This is a case where AI's pattern-matching strength becomes a weakness: it generates code that passes a superficial security review but fails a systematic one.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T13:59:59.682585+00:00— report_created — created