When to Use
- Starting a security audit of an unfamiliar codebase
- Building a threat model before deep technical review
- Mapping data flows to identify sensitive paths
- Establishing audit scope and priorities
- Documenting architecture for security assessment
When NOT to Use
- You already have full context and are ready to audit
- Quick spot-check of a specific code change (use fix-review)
- Automated scanning (use static analysis tools)
Context Building Phases
Phase 1: Architecture Overview
- Identify the tech stack (languages, frameworks, databases)
- Map service boundaries and communication patterns
- Identify external dependencies and third-party integrations
- Understand deployment topology (cloud, containers, serverless)
# Tech stack discovery
find . -name "package.json" -o -name "requirements.txt" -o -name "go.mod" -o -name "Cargo.toml" | head -20
cat package.json 2>/dev/null | grep -A5 '"dependencies"'
Phase 2: Trust Boundaries
- Where does untrusted input enter the system?
- What authentication/authorization mechanisms are used?
- Where are privilege escalation boundaries?
- What services communicate and with what trust level?
# Find auth mechanisms
grep -rn "auth\|jwt\|session\|token\|middleware" --include="*.ts" --include="*.py" -l .
Phase 3: Sensitive Data Flows
- What sensitive data does the system handle? (PII, credentials, financial)
- How is sensitive data stored? (encrypted at rest?)
- How does sensitive data move between components? (encrypted in transit?)
- Where are secrets stored and how are they accessed?
# Find potential secret handling
grep -rn "password\|secret\|key\|token\|credential" --include="*.env*" --include="*.yaml" --include="*.json" -l .
Phase 4: Attack Surface Catalog
- List all external-facing endpoints
- Identify file upload/download capabilities
- Map administrative interfaces
- Catalog webhook and callback URLs
Phase 5: Historical Context
- Review recent security-related commits
- Check for past vulnerability reports or advisories
- Identify previously audited areas
- Note known tech debt or deferred security work
# Security-related git history
git log --oneline --all --grep="security\|vulnerability\|CVE\|fix\|patch" | head -20
Output: Audit Context Document
Produce a structured document covering:
- Architecture diagram (text-based)
- Trust boundary map
- Sensitive data inventory
- Attack surface catalog
- Prioritized review areas
- Known risks and assumptions