Default output: return only the result, blockers, and required evidence. Omit preambles, process narration, repeated context, confidence scores, and follow-up offers. Use at most five bullets unless a required artifact or schema needs more.
Security and Hardening
Overview
Apply security best practices systematically across the codebase. Prevent OWASP Top 10 vulnerabilities, manage secrets safely, audit dependencies, and enforce boundary validation at all system edges.
When to Use
- Handling user input or external data
- Implementing authentication or authorization
- Storing or transmitting sensitive data
- Integrating with external services
- Before deploying any change to production
OWASP Top 10 Prevention
Injection
- Use parameterized queries for all database access
- Validate and sanitize all user input
- Use ORM/query builders that handle escaping
- Never concatenate user input into queries, commands, or HTML
Broken Authentication
- Use established auth libraries (do not roll your own)
- Implement proper session management
- Require strong passwords and multi-factor authentication
- Use secure cookie flags (HttpOnly, Secure, SameSite)
Sensitive Data Exposure
- Encrypt data at rest and in transit
- Never log sensitive data (passwords, tokens, PII)
- Use environment variables for secrets, never hardcode
- Minimize data collection to what is needed
Security Misconfiguration
- Disable unnecessary features and services
- Keep all dependencies updated
- Use secure defaults (deny by default)
- Remove default credentials and sample data
Broken Access Control
- Enforce authorization on every protected endpoint
- Do not rely on client-side access control
- Implement proper CORS policies
- Validate resource ownership
Three-Tier Boundary System
Tier 1: External Boundary
All data from outside the system is untrusted:
- HTTP request bodies, headers, and query parameters
- File uploads and external API responses
- Webhook payloads and email content
Tier 2: Module Boundary
Data crossing module boundaries should be validated:
- Function parameters across module lines
- Queue message payloads
- Database read results when crossing service boundaries
Tier 3: Internal Boundary
Data within a trusted module needs less validation, but:
- Validate at state transitions
- Assert invariants in critical paths
- Use type systems to catch mistakes
Secrets Management
- Never hardcode secrets in source code
- Use environment variables or secret managers
- Validate required secrets at startup
- Rotate any exposed secrets immediately
- Add secret patterns to .gitignore
Process
Step 1: Identify Trust Boundaries
- List all points where data enters or leaves the system
- Identify authentication and authorization checkpoints
- Map data flows for sensitive information
Step 2: Apply Boundary Validation
- Validate input at every trust boundary
- Sanitize output when crossing boundaries
- Use allow-lists over deny-lists where possible
Step 3: Audit Dependencies
- Run dependency audit (npm audit, socket security)
- Check for known vulnerabilities
- Update or replace vulnerable packages
Step 4: Verify Security Controls
- Test authentication flows
- Test authorization for each role
- Verify CORS and CSP policies
- Check that error messages do not leak sensitive data
Common Rationalizations
| Rationalization |
Reality |
| "This is internal, security does not matter" |
Internal systems are targets for lateral movement after perimeter breach. |
| "We can add security later" |
Retrofitting security is more expensive and less effective than building it in. |
| "Validation is redundant" |
Defense in depth means multiple layers of validation. |
Verification
Anti-Rationalization Table
| Excuse |
Counter |
| "This is internal, security doesn't matter" |
Internal systems are targets for lateral movement after perimeter breach. |
| "We can add security later" |
Retrofitting security is more expensive and less effective than building it in. |
| "Validation is redundant" |
Defense in depth means multiple layers of validation. Each layer catches what others miss. |
| "The dependency audit is clean, we're safe" |
Dependency audits catch known vulnerabilities. They do not catch logic errors or misconfigurations. |
| "HTTPS is enough for data protection" |
HTTPS protects data in transit. Data at rest, in logs, and in memory also need protection. |
1---2name: security-and-hardening3description: OWASP Top 10 prevention, auth patterns, secrets management, dependency auditing, boundary validation. Use when handling user input, auth, or external integrations.4metadata:5 category: user-invoked6disable-model-invocation: true7---89Default output: return only the result, blockers, and required evidence. Omit preambles, process narration, repeated context, confidence scores, and follow-up offers. Use at most five bullets unless a required artifact or schema needs more.1011# Security and Hardening1213## Overview1415Apply security best practices systematically across the codebase. Prevent OWASP Top 10 vulnerabilities, manage secrets safely, audit dependencies, and enforce boundary validation at all system edges.1617## When to Use1819- Handling user input or external data20- Implementing authentication or authorization21- Storing or transmitting sensitive data22- Integrating with external services23- Before deploying any change to production2425## OWASP Top 10 Prevention2627### Injection2829- Use parameterized queries for all database access30- Validate and sanitize all user input31- Use ORM/query builders that handle escaping32- Never concatenate user input into queries, commands, or HTML3334### Broken Authentication3536- Use established auth libraries (do not roll your own)37- Implement proper session management38- Require strong passwords and multi-factor authentication39- Use secure cookie flags (HttpOnly, Secure, SameSite)4041### Sensitive Data Exposure4243- Encrypt data at rest and in transit44- Never log sensitive data (passwords, tokens, PII)45- Use environment variables for secrets, never hardcode46- Minimize data collection to what is needed4748### Security Misconfiguration4950- Disable unnecessary features and services51- Keep all dependencies updated52- Use secure defaults (deny by default)53- Remove default credentials and sample data5455### Broken Access Control5657- Enforce authorization on every protected endpoint58- Do not rely on client-side access control59- Implement proper CORS policies60- Validate resource ownership6162## Three-Tier Boundary System6364### Tier 1: External Boundary6566All data from outside the system is untrusted:67- HTTP request bodies, headers, and query parameters68- File uploads and external API responses69- Webhook payloads and email content7071### Tier 2: Module Boundary7273Data crossing module boundaries should be validated:74- Function parameters across module lines75- Queue message payloads76- Database read results when crossing service boundaries7778### Tier 3: Internal Boundary7980Data within a trusted module needs less validation, but:81- Validate at state transitions82- Assert invariants in critical paths83- Use type systems to catch mistakes8485## Secrets Management8687- Never hardcode secrets in source code88- Use environment variables or secret managers89- Validate required secrets at startup90- Rotate any exposed secrets immediately91- Add secret patterns to .gitignore9293## Process9495### Step 1: Identify Trust Boundaries9697- List all points where data enters or leaves the system98- Identify authentication and authorization checkpoints99- Map data flows for sensitive information100101### Step 2: Apply Boundary Validation102103- Validate input at every trust boundary104- Sanitize output when crossing boundaries105- Use allow-lists over deny-lists where possible106107### Step 3: Audit Dependencies108109- Run dependency audit (npm audit, socket security)110- Check for known vulnerabilities111- Update or replace vulnerable packages112113### Step 4: Verify Security Controls114115- Test authentication flows116- Test authorization for each role117- Verify CORS and CSP policies118- Check that error messages do not leak sensitive data119120## Common Rationalizations121122| Rationalization | Reality |123|---|---|124| "This is internal, security does not matter" | Internal systems are targets for lateral movement after perimeter breach. |125| "We can add security later" | Retrofitting security is more expensive and less effective than building it in. |126| "Validation is redundant" | Defense in depth means multiple layers of validation. |127128## Verification129130- [ ] All user input is validated at trust boundaries131- [ ] No secrets in source code or logs132- [ ] Authentication and authorization tested for each role133- [ ] Dependency audit shows no critical vulnerabilities134- [ ] Error messages do not leak sensitive information135136## Anti-Rationalization Table137138| Excuse | Counter |139|--------|---------|140| "This is internal, security doesn't matter" | Internal systems are targets for lateral movement after perimeter breach. |141| "We can add security later" | Retrofitting security is more expensive and less effective than building it in. |142| "Validation is redundant" | Defense in depth means multiple layers of validation. Each layer catches what others miss. |143| "The dependency audit is clean, we're safe" | Dependency audits catch known vulnerabilities. They do not catch logic errors or misconfigurations. |144| "HTTPS is enough for data protection" | HTTPS protects data in transit. Data at rest, in logs, and in memory also need protection. |