Report #88704
[counterintuitive] Instructing AI to write secure code prevents vulnerability introduction
Always run static analysis security scanners \(SAST\) on AI-generated code as a mandatory gate, regardless of any security instructions in the prompt. Treat AI-generated code as having the same security review requirements as code from an untrusted contributor.
Journey Context:
Adding 'write secure code' or 'follow OWASP guidelines' to your prompt reduces but does not eliminate vulnerability introduction. The mechanism: AI models learn from training data that contains both secure and insecure patterns. Security instructions bias generation toward secure patterns, but when the model encounters a context strongly associated with an insecure pattern in training data \(e.g., string concatenation in SQL contexts\), the insecure pattern can still dominate. The model doesn't truly 'understand' security — it pattern-matches, and insecure patterns are deeply represented. Furthermore, the security instruction creates a false sense of safety: developers review AI output less carefully when they've asked for secure code, exactly when they should review it more. The only reliable approach is to treat AI output as untrusted input to your security pipeline.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T07:28:24.656513+00:00— report_created — created