DevSecOps practices for AI-generated code pipelines.
AI-generated code introduces new security risks. This module provides guardrails to ensure generated code meets security standards.
AI code generation creates unique security challenges:
| Risk | Description |
|---|---|
| Hallucinated vulnerabilities | AI may generate insecure patterns it learned from training data |
| Outdated practices | Training data may include deprecated, insecure code |
| Secrets in prompts | Sensitive context may leak into generated code |
| Dependency confusion | AI may suggest malicious or non-existent packages |
| Prompt injection | Malicious input in tickets could manipulate agent behavior |
| Component | Purpose | Document |
|---|---|---|
| Secure Code Generation | Prompts and rules for secure code | SECURE_CODE_GENERATION.md |
| Security Gates | Automated security checks | SECURITY_GATES.md |
| Supply Chain Security | Dependencies and AI model trust | SUPPLY_CHAIN_SECURITY.md |
| Audit Trail | Traceability for AI-generated code | AUDIT_TRAIL.md |
┌─────────────────────────────────────────────────────────────┐
│ Layer 1: PROMPT ENGINEERING │
│ Security-aware prompts, OWASP rules in context │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Layer 2: AUTOMATED SCANNING │
│ SAST, secrets detection, dependency audit │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Layer 3: HUMAN REVIEW │
│ Security-focused review for sensitive areas │
└─────────────────────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Layer 4: RUNTIME PROTECTION │
│ WAF, monitoring, anomaly detection │
└─────────────────────────────────────────────────────────────┘
- AI agents should not have access to production credentials
- Generated code should request minimum necessary permissions
- Sensitive operations require human approval
- AI output is untrusted input
- Every piece of generated code goes through security gates
- Security-critical code requires explicit human review
- Every line of AI-generated code is traceable
- Audit trail includes: who requested, what prompt, what was generated
- Enables investigation if issues are discovered later
In addition to standard escalation rules, always escalate for:
| Trigger | Reason |
|---|---|
| Authentication/authorization changes | High impact if wrong |
| Cryptography implementation | Easy to get wrong |
| Input validation for user data | Injection risks |
| File system operations | Path traversal risks |
| Database queries with user input | SQL injection risks |
| External API integrations | Data exposure risks |
| Configuration changes | Security posture impact |
- Read SECURE_CODE_GENERATION.md
- Add security rules to your agent prompt
- Run security scanners locally
- Implement SECURITY_GATES.md in CI/CD
- Set up SUPPLY_CHAIN_SECURITY.md
- Configure AUDIT_TRAIL.md
All of the above, plus:
- Security team review of prompts
- Regular audit of AI-generated code
- Incident response plan for AI-related vulnerabilities
- Compliance documentation
| Framework | Relevant Controls |
|---|---|
| SOC 2 | CC6.1 (Logical access), CC7.1 (System changes) |
| ISO 27001 | A.14.2 (Development security), A.12.6 (Vulnerability management) |
| PCI DSS | 6.3 (Secure development), 6.5 (Common vulnerabilities) |
| GDPR | Art. 25 (Data protection by design), Art. 32 (Security of processing) |
| Metric | Target | Alert |
|---|---|---|
| Security gate pass rate | > 95% | < 90% |
| Critical/High findings per MR | 0 | > 0 |
| Time to remediate findings | < 1 day | > 3 days |
| False positive rate | < 10% | > 25% |
| Security escalation rate | 5-15% | < 5% or > 25% |
╔══════════════════════════════════════════════════════════════╗
║ SECURITY POSTURE - AI CODE ║
╠══════════════════════════════════════════════════════════════╣
║ This Week: ║
║ MRs scanned: 42 ║
║ Security gate pass: 95% (40/42) ║
║ Critical findings: 0 ║
║ High findings: 2 (both remediated) ║
╠══════════════════════════════════════════════════════════════╣
║ Top Findings (Last 30 Days): ║
║ 1. Hardcoded credentials (8) ║
║ 2. Missing input validation (5) ║
║ 3. Insecure dependency (4) ║
╠══════════════════════════════════════════════════════════════╣
║ Trend: ↓ 15% fewer findings vs last month ║
╚══════════════════════════════════════════════════════════════╝
- Immediate: Security-aware prompts (free, high impact)
- Week 1: Automated security scanning in CI
- Week 2: Dependency scanning and lockfiles
- Week 3: Audit trail implementation
- Ongoing: Security metrics and improvement
Security is not optional. Every AI code generation pipeline needs these controls.