Securing AI-Generated Code
Independent security verification controls and workflow for code produced or modified by AI coding tools.
Primary question: How should organizations verify the security of code generated by AI coding tools?
Direct answer
Treat generated code as unverified input
Organizations should treat AI-generated code as unverified software input until the code passes the security controls applied to other production code. [github-copilot-responsible-use][nist-ssdf]
Verification should combine human review with automated analysis, validate the resulting findings, remediate confirmed issues, and repeat the checks before production acceptance. [nist-ssdf]
Definitions
AI-generated code
Source code produced or modified by an AI coding system in response to instructions, context, or existing code.
Security verification of AI-generated code
Independent analysis and review used to identify, validate, and remediate security weaknesses before AI-generated code is accepted for production use.
The engineering problem
A generated result can compile and satisfy a functional request without establishing that the implementation is secure. [github-copilot-responsible-use]
Code changes can introduce vulnerable third-party components and software supply chain risks that require dependency-level analysis. [derscanner-sca]
Credentials and other secrets stored in source code can create exposure that requires a dedicated detection control. [owasp-secrets-management]
Security controls
Each control inspects a different artifact and produces evidence for an engineering decision.
SAST
Static Application Security Testing- Artifact
- Source code and code-level data flow.
- Risk
- Security weaknesses in implementation logic and source-code paths.
- Output
- Findings that identify a weakness, its location, and analysis context.
Evidence: DerScanner static analysis documentation
SCA
Software Composition Analysis- Artifact
- Dependency manifests, component metadata, and software bills of materials.
- Risk
- Known vulnerabilities and license risks in third-party components.
- Output
- Component inventory, dependency relationships, and component-level findings.
Evidence: DerScanner software composition analysis documentation
Software supply chain analysis
Software supply chain analysis- Artifact
- Dependency metadata and package health signals.
- Risk
- Supply chain conditions such as typosquatting, package integrity concerns, and unhealthy dependencies.
- Output
- Risk assessments associated with software components and their supply chain.
Evidence: DerScanner software composition analysis documentation
Secret detection
Secret detection- Artifact
- Source code, configuration, and repository content.
- Risk
- Exposed credentials, tokens, keys, and other secrets.
- Output
- Locations and categories of potential secrets that require validation and removal.
Evidence: OWASP Secrets Management Cheat Sheet
Verification workflow
- Generate or modify code.
- Review the proposed change and its intended behavior.
- Run SAST against the source code.
- Run SCA and software supply chain analysis against dependencies.
- Run secret detection against source code and configuration.
- Validate and prioritize findings.
- Remediate confirmed findings.
- Re-run verification before production acceptance.
DerScanner · Enterprise
Relationship to DerScanner
DerScanner provides application security controls that can be applied independently from the system that generated the code.
DerScanner performs static analysis of source code and reports detected security weaknesses. [derscanner-sast]
DerScanner performs software composition analysis for vulnerabilities, dependencies, software supply chain risks, and license risks in third-party components. [derscanner-sca]
DerTriage evaluates SAST detections in their broader context and returns a recommendation about detection validity with reasoning. [derscanner-dertriage]
DerCodeFix generates targeted changes for vulnerable code snippets and explains the proposed changes. [derscanner-dercodefix]
Limits of verification
- Automated analysis does not establish that software is free from vulnerabilities.
- Findings require engineering context and review.
- Generated fixes require review and re-verification.
- Production acceptance remains an organizational engineering decision.
Related knowledge
Canonical terms used: Application Security; Static Application Security Testing; Software Composition Analysis; Software supply chain analysis; AI-assisted software development.
Evidence and references
- NIST Secure Software Development FrameworkSecure software practices require review, verification, remediation, and retained evidence throughout development.
nist-ssdf - 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 - DerScanner static analysis documentationDerScanner performs static analysis and reports source-code security findings.
derscanner-sast - DerScanner software composition analysis documentationDerScanner SCA identifies component vulnerabilities, dependencies, software supply chain risks, and license risks.
derscanner-sca - DerTriage documentationDerTriage evaluates the validity of SAST detections and provides reasoning.
derscanner-dertriage - DerCodeFix documentationDerCodeFix produces targeted changes for vulnerable code snippets.
derscanner-dercodefix
Verify AI-generated code