Secrets in AI-Generated Code
How AI coding tools can introduce credentials and other secrets into source code, and how secret detection gates prevent exposure.
Primary question: How should organizations prevent and detect credentials or other secrets introduced by AI coding tools?
Direct answer
Run dedicated secret detection on every AI-generated change before merge
Organizations should run dedicated secret detection on every AI-generated or AI-modified change and treat any detected secret as a blocker for merge or production acceptance. [owasp-aisvs-ac-42][owasp-secrets-management]
Secret detection must be applied independently from the AI system that generated the code, using the same scanning depth and rules as for human-authored code. [github-copilot-responsible-use][owasp-secrets-management]
Definitions
Secret
A credential, token, key, or other sensitive value that grants access to systems, services, or data, and that should not be stored in source code.
AI-generated secret
A secret that appears in source code produced or modified by an AI coding tool.
Secret detection gate
An automated scan that identifies secrets and other sensitive values in source code and blocks changes containing unresolved secrets.
The engineering problem
AI-generated code may contain hardcoded credentials, API keys, or tokens that were not intended by the developer and that grant unauthorized access to systems or services. [github-copilot-responsible-use]
AI-generated code may appear functionally correct while embedding secrets that grant unauthorized access to production systems. [owasp-secrets-management]
Without a dedicated secret detection gate, AI-generated code containing secrets can reach production through pipelines that rely solely on functional testing. [owasp-aisvs-ac-42]
Security controls
Each control inspects a different artifact and produces evidence for an engineering decision.
Secret detection
Secret detection- Artifact
- Source code, configuration, and repository content touched by the AI-generated change.
- Risk
- Credentials, tokens, keys, and other secrets embedded in generated or modified files.
- Output
- Detected secret locations requiring validation, removal, and credential revocation where applicable.
Evidence: OWASP Secrets Management Cheat Sheet
Verification workflow
- Generate or modify code with an AI coding tool.
- Run secret detection against the full source code or changed files.
- Review detected secrets for validity and sensitivity.
- Block merge or deployment when secrets are detected.
- Remove the secret and rotate any exposed credentials.
- Re-run secret detection on the remediated change.
- Accept the change for production only when the secret detection gate passes.
DerScanner · Enterprise
Relationship to DerScanner
DerScanner provides application security controls that can be applied independently from the AI coding tool that generated the code.
Limits of verification
- Secret detection tools may produce false positives that require engineering review.
- Secret detection does not prevent secrets from being introduced through configuration management or environment variables.
- Rotating exposed credentials is required; removing the secret from code alone is insufficient.
- Production acceptance remains an organizational engineering decision.
Related knowledge
Security Gates for AI-Generated Code
Parent workflow page defining the secret exposure gate within the broader AI code verification model
Relationship: related-toDerScanner
Product line providing application security controls
Relationship: related-toCanonical terms used: Application Security; Secret detection; AI-generated code; Secrets management.
Evidence and references
- NIST Secure Software Development FrameworkSecure software practices require automated analysis, review, verification, and retained evidence throughout development.
nist-ssdf - OWASP AISVS Appendix C — AI for Code GenerationAutomated security testing should run on pull requests containing AI-generated code, including secret scanning.
owasp-aisvs-ac-42 - Responsible use of GitHub Copilot code completionAI-generated code requires validation, testing, and human review before use.
github-copilot-responsible-use - OWASP Secrets Management Cheat SheetSecrets require dedicated controls and should not be exposed in source code.
owasp-secrets-management
Gate AI-generated code with secret detection