Security
Hardcoded Secrets: The Most Common Vulnerability in AI-Generated Code
Why API keys and credentials end up hardcoded in AI-generated applications, how attackers find them within minutes, and the remediation playbook.
By AI Production Partner · · 3 min read
How secrets get into AI-built code
It starts innocently: you paste an API key into a prompt so the tool can wire up an integration, and the tool does exactly what you asked — embeds it in the source. The file gets committed, the repo gets shared or published, and the key is now permanently in git history even if you later delete the line.
Public GitHub repos are scanned by bots within minutes of pushing. A leaked cloud key routinely becomes a five-figure crypto-mining bill overnight; a leaked database URL becomes a breach.
The remediation playbook
One: scan the full git history (not just current files) with a secret scanner. Two: rotate every key found — a committed secret is a leaked secret, deletion doesn't help. Three: move configuration to environment variables backed by a secret manager. Four: add secret scanning to CI so the next paste is caught at commit time. Five: audit client bundles separately — keys shipped to the browser are public by definition.
This entire playbook takes a day or two on most codebases, which makes it the highest ROI security work available. It's also the first item in every audit we run — and the most frequently failed.