Skip to main content

Security Risk Framework

AI-generated code has been shown to contain a 2.74x higher security vulnerability rate compared to human-authored code. This is not a minor variance -- it represents a fundamental shift in the threat landscape for organizations adopting AI-assisted development. This section provides a comprehensive security risk framework that includes threat modeling for AI outputs, vulnerability classification, scanning requirements, remediation protocols, and risk-based SLAs. It complements the verification techniques in AI Output Verification and the review processes in Human-in-the-Loop.

Threat Model for AI-Generated Code

AI-generated code introduces threat vectors that differ from those in traditional software development. The following threat model identifies the primary categories of security risk specific to AI outputs.

AI-Specific Threat Categories

Threat CategoryDescriptionLikelihoodImpact
Injection VulnerabilitiesAI generates code vulnerable to SQL injection, XSS, command injection, or LDAP injection due to missing or incorrect input sanitizationHighCritical
Authentication/Authorization GapsAI generates endpoints or functions without proper auth checks, or with incomplete role-based access controlHighCritical
Hallucinated Security APIsAI references security functions, cryptographic methods, or configuration options that do not exist or behave differently than describedMediumCritical
Insecure DefaultsAI generates code with overly permissive configurations: open CORS, debug mode enabled, verbose error messages, weak cipher suitesHighHigh
Hardcoded SecretsAI generates placeholder credentials, API keys, or tokens that appear realistic and may be deployed inadvertentlyMediumCritical
Outdated Security PatternsAI generates code using deprecated cryptographic algorithms, obsolete authentication patterns, or retired security libraries based on training data ageMediumHigh
Insufficient Error HandlingAI generates "happy path" code that leaks information through stack traces, exposes internal state, or fails open rather than failing closedHighMedium
Resource ExhaustionAI generates code without proper rate limiting, pagination, input size validation, or timeout handling, enabling denial-of-serviceMediumHigh
Deserialization VulnerabilitiesAI generates insecure deserialization patterns that enable remote code executionMediumCritical
Training Data LeakageAI output includes fragments of sensitive data from training data (e.g., actual API keys, internal URLs, credentials from training corpora)LowCritical

OWASP Top 10 Mapping for AI-Generated Code

The OWASP Top 10 vulnerabilities are especially relevant to AI-generated code. The following mapping identifies which OWASP categories are most frequently introduced by AI tools and the required controls.

OWASP CategoryAI Risk LevelCommon AI Generation PatternRequired Control
A01: Broken Access ControlCriticalMissing authorization checks on generated endpointsManual review checklist item + automated auth testing
A02: Cryptographic FailuresHighUse of weak algorithms (MD5, SHA1), hardcoded keys, missing encryptionSAST rules + crypto library allow-list
A03: InjectionCriticalUnparameterized queries, unsanitized template renderingSAST + parameterized query enforcement
A04: Insecure DesignHighMissing rate limits, no input validation, trust boundary violationsArchitecture review for Tier 2/3 changes
A05: Security MisconfigurationHighDebug mode, verbose errors, permissive CORS, default credentialsConfiguration scanning + hardened defaults
A06: Vulnerable ComponentsMediumAI suggests outdated or vulnerable dependenciesDependency scanning (Snyk, Dependabot)
A07: Auth FailuresHighWeak password policies, missing MFA hooks, session mismanagementSecurity review checklist + automated testing
A08: Data Integrity FailuresMediumMissing signature verification, insecure deserializationSAST + manual review
A09: Logging FailuresMediumMissing audit logging, logging sensitive dataLogging standards enforcement
A10: SSRFMediumAI generates HTTP clients without URL validationSAST rules + allow-list enforcement

Vulnerability Scanning Requirements

Mandatory Scanning Tools and Configuration

All AI-generated code MUST pass through the following scanning layers before merging into any protected branch:

Scan TypeTool ExamplesWhen RunThreshold
Static Application Security Testing (SAST)Semgrep, CodeQL, SonarQube, CheckmarxEvery PR; every commit to protected branchesZero Critical/High findings
Software Composition Analysis (SCA)Snyk, OWASP Dependency-Check, DependabotEvery PR that modifies dependenciesZero Critical findings; High findings require documented risk acceptance
Secret DetectionGitLeaks, TruffleHog, detect-secretsEvery commit (pre-commit hook + CI)Zero findings
Infrastructure-as-Code ScanningCheckov, tfsec, KICSEvery PR modifying IaC filesZero Critical/High findings
Container Image ScanningTrivy, Snyk Container, GrypeEvery container buildZero Critical findings
Dynamic Application Security Testing (DAST)OWASP ZAP, Burp Suite (automated)Pre-release for Tier 2/3 changesZero Critical/High findings

Scanning Configuration for AI-Generated Code

  • SAST tools SHOULD be configured with AI-specific rulesets that target the most common AI generation vulnerability patterns listed in the threat model above
  • Secret detection MUST be configured with low false-negative tolerance -- it is better to flag false positives than to miss real secrets
  • Scanning results for AI-generated code MUST NOT be suppressed or marked as false positives without written justification reviewed by a security champion
  • Teams SHOULD contribute new detection rules back to the scanning tools when novel AI-generated vulnerability patterns are discovered
danger

Disabling or bypassing security scanning for AI-generated code is a critical policy violation. No exception process exists for SAST and secret detection scanning. Emergency procedures for other scan types require CISO approval.

Risk Assessment Matrix

The following risk matrix guides prioritization of security findings in AI-generated code:

Likelihood / ImpactCritical ImpactHigh ImpactMedium ImpactLow Impact
Very LikelyP0 -- ImmediateP0 -- ImmediateP1 -- UrgentP2 -- Standard
LikelyP0 -- ImmediateP1 -- UrgentP2 -- StandardP3 -- Scheduled
PossibleP1 -- UrgentP2 -- StandardP3 -- ScheduledP4 -- Backlog
UnlikelyP2 -- StandardP3 -- ScheduledP4 -- BacklogP4 -- Backlog

Risk Priority Definitions

PriorityDefinitionAction Required
P0 -- ImmediateExploitable vulnerability with critical business impactStop all work. Fix immediately. No deployment until resolved. Security team notified within 1 hour.
P1 -- UrgentSignificant vulnerability requiring prompt remediationFix within 24 hours. Block merge/deployment until resolved. Security team notified within 4 hours.
P2 -- StandardModerate vulnerability with limited exploitability or impactFix within 7 calendar days. May merge to non-production branches with documented risk acceptance.
P3 -- ScheduledLow-severity vulnerability or defense-in-depth improvementFix within 30 calendar days. Track in sprint backlog.
P4 -- BacklogMinimal risk; improvement opportunitySchedule in future sprint. Track in backlog.

Remediation SLAs

SLA Requirements by Priority

PriorityDetection-to-Fix SLADetection-to-Deploy SLAEscalation Trigger
P04 hours8 hoursAutomatic escalation to CISO at detection
P124 hours48 hoursEscalation if not fixed within 12 hours
P27 calendar days14 calendar daysEscalation if not fixed within 5 days
P330 calendar days45 calendar daysMonthly review
P490 calendar daysNext scheduled releaseQuarterly review

SLA Compliance Tracking

  • SLA compliance MUST be tracked and reported monthly to engineering leadership
  • Teams with SLA compliance below 90% MUST produce a remediation plan within one sprint
  • Chronic SLA non-compliance (below 90% for three consecutive months) SHALL trigger a review of the team's AI tool access and development processes
  • SLA clock starts at the time of detection, not at the time of triage

Security Review Integration Points

Security review MUST be integrated at multiple points in the AI-assisted development lifecycle, not solely as a pre-deployment gate.

Pre-Generation Security Controls

  • Prompts for security-sensitive code (authentication, authorization, cryptography, data handling) MUST include explicit security constraints per Prompt Engineering Rigor
  • Developers MUST reference the relevant OWASP category when generating code in a security-sensitive domain
  • AI tools MUST NOT be used to generate cryptographic implementations; use established, audited cryptographic libraries instead

Post-Generation Security Controls

  • All security scanning as defined in the Vulnerability Scanning Requirements section above
  • Manual security review by a security champion for all Tier 3 (High Risk) changes
  • Penetration testing for new attack surface introduced by AI-generated code (RECOMMENDED: quarterly for critical applications)

Production Security Monitoring

  • AI-generated code deployed to production SHOULD be monitored with enhanced alerting during the first 30 days
  • Runtime application self-protection (RASP) or web application firewall (WAF) rules SHOULD be updated when new attack surface is deployed
  • Security incident correlation SHOULD include AI provenance data to enable trend analysis by generation source

Security Training Requirements

  • All developers using AI tools MUST complete security training that addresses AI-specific vulnerability patterns (annual requirement)
  • Security champions MUST receive advanced training on AI-generated code threat modeling (annual requirement)
  • Training materials MUST be updated when new AI-specific vulnerability patterns are discovered
  • Training effectiveness SHOULD be measured through periodic security assessments using AI-generated code samples with seeded vulnerabilities

For incident response procedures when security vulnerabilities in AI-generated code are discovered in production, see Incident Response for AI-Generated Defects. For compliance implications of security findings, see Compliance & Regulatory Alignment.