Audit Security
Overview
Perform a structured security audit against the OWASP Top 10, scanning the codebase for injection vulnerabilities, broken authentication, sensitive data exposure, security misconfiguration, and broken access control. Combine automated pattern scanning with manual review of business logic and architecture decisions.
Workflow
Read project context — Check .chalk/docs/engineering/ for:
- Architecture docs (to understand auth patterns, data flow, trust boundaries)
- Previous security audits (to track remediation progress)
- API documentation (to identify endpoints requiring auth)
- Infrastructure docs (to understand deployment security)
Determine audit scope — From $ARGUMENTS and conversation:
- If a specific component or concern is named, focus there
- If no scope is given, audit the entire codebase
- Identify the tech stack to tailor the scan patterns (Node.js, Python, Go, etc.)
- Note the application type: web API, SPA, mobile backend, CLI tool
Scan for injection vulnerabilities — Search the codebase for:
- SQL Injection: String concatenation in queries, missing parameterized queries, raw SQL with user input
- XSS:
innerHTML, dangerouslySetInnerHTML, document.write(), unescaped template interpolation, v-html
- Command Injection:
exec(), spawn(), system(), subprocess.call() with user-controlled arguments
- Template Injection: User input in template strings evaluated server-side
- Path Traversal: User input in file paths without sanitization (
../ sequences)
- LDAP/NoSQL Injection: Unsanitized input in LDAP or MongoDB queries
Check authentication and session management — Review:
- Password handling: Hashing algorithm (bcrypt/argon2 = good, MD5/SHA1 = bad), salt usage, minimum complexity
- JWT: Secret strength, algorithm pinning (reject
none), expiration enforcement, token storage (httpOnly cookies vs. localStorage)
- Session: Session ID entropy, session fixation protection, session timeout, invalidation on logout
- MFA: Is it available? Is it enforced for sensitive operations?
- Rate limiting: Login attempts, password reset, API endpoints
Check for sensitive data exposure — Scan for:
- Hardcoded secrets: API keys, passwords, tokens, connection strings in source code
- Patterns:
password\s*=, api_key, secret, token, AWS_, PRIVATE_KEY, base64-encoded credentials
- Logging PII: User emails, passwords, credit card numbers, SSNs in log statements
- Error messages: Stack traces, database errors, internal paths exposed to users
- Git history: Secrets that were committed and later removed (still in history)
- .env files: Check if
.env is in .gitignore, check for .env.example with real values
Review security configuration — Check:
- CORS: Overly permissive origins (
*), credentials with wildcard origin
- Security headers: Missing
Content-Security-Policy, X-Frame-Options, Strict-Transport-Security, X-Content-Type-Options
- Debug mode: Debug flags enabled in production config, verbose error output
- HTTPS: Mixed content, HTTP redirects, certificate validation disabled in code
- Cookie security: Missing
Secure, HttpOnly, SameSite attributes
- Default credentials: Default admin accounts, unchanged default passwords
Check access control — Review:
- Authorization on every endpoint: Are there routes missing auth middleware?
- IDOR: Can users access resources by changing IDs in URLs? Is ownership verified?
- Privilege escalation: Can a regular user access admin endpoints? Is role checking consistent?
- Horizontal access: Can user A access user B's data?
- API authorization: Are all API endpoints protected? Are there unprotected admin routes?
- File upload: Unrestricted file types, missing virus scanning, path traversal in filenames
Review business logic — Beyond technical vulnerabilities:
- Race conditions in financial operations (double spending, duplicate orders)
- Missing validation on state transitions (e.g., order status can skip steps)
- Insufficient rate limiting on expensive operations
- Missing audit logging for sensitive actions
- Insecure direct object references in business workflows
Classify findings — For each finding:
- Severity: Critical, High, Medium, Low
- CWE reference: Map to Common Weakness Enumeration where applicable
- OWASP category: Which OWASP Top 10 category does this fall under
- Exploitability: How easy is it to exploit? (trivial, moderate, difficult)
- Impact: What could an attacker achieve?
- Evidence: File path, line number, code snippet
- Remediation: Specific fix with code example
Determine the next file number — List files in .chalk/docs/engineering/ matching *_security_audit*. Find the highest number and increment by 1.
Write the report — Save to .chalk/docs/engineering/<n>_security_audit.md.
Confirm — Summarize: total findings by severity, most critical items, and overall security posture assessment.
Filename Convention
<number>_security_audit.md
Examples:
7_security_audit.md
14_security_audit.md
Security Audit Format
# Security Audit Report
Last updated: <YYYY-MM-DD>
Scope: <what was audited>
Tech stack: <languages, frameworks, infrastructure>
## Executive Summary
<2-3 sentences: overall security posture, most critical findings, and top recommendation.>
## Findings Summary
| Severity | Count | Remediation Urgency |
|----------|-------|-------------------|
| Critical | <n> | Immediate — block release |
| High | <n> | Fix within 1 week |
| Medium | <n> | Fix within 1 month |
| Low | <n> | Fix in next maintenance cycle |
## OWASP Coverage
| OWASP Category | Findings | Status |
|---------------|----------|--------|
| A01: Broken Access Control | <n> | Issues found / Clear |
| A02: Cryptographic Failures | <n> | Issues found / Clear |
| A03: Injection | <n> | Issues found / Clear |
| A04: Insecure Design | <n> | Issues found / Clear |
| A05: Security Misconfiguration | <n> | Issues found / Clear |
| A06: Vulnerable and Outdated Components | <n> | Issues found / Clear |
| A07: Identification and Authentication Failures | <n> | Issues found / Clear |
| A08: Software and Data Integrity Failures | <n> | Issues found / Clear |
| A09: Security Logging and Monitoring Failures | <n> | Issues found / Clear |
| A10: Server-Side Request Forgery (SSRF) | <n> | Issues found / Clear |
## Critical Findings
### FINDING-1: <Title>
| Field | Value |
|-------|-------|
| Severity | Critical |
| OWASP | A03: Injection |
| CWE | CWE-89: SQL Injection |
| Exploitability | Trivial |
| File | `<file path>:<line number>` |
**Description**: <What the vulnerability is and why it matters>
**Evidence**:
```<language>
// Vulnerable code
<code snippet>
Impact:
Remediation:
// Fixed code
<code snippet>
High Findings
FINDING-:
Medium Findings
| ID |
Title |
OWASP |
CWE |
File |
Remediation Summary |
| F- |
|
A05 |
CWE- |
<file> |
|
Low Findings
| ID |
Title |
OWASP |
CWE |
File |
Remediation Summary |
| F- |
|
A05 |
CWE- |
<file> |
|
Positive Findings
Recommendations
Immediate Actions
Short-Term (1-4 weeks)
Long-Term (1-3 months)
## Common Scan Patterns by Language
### JavaScript / TypeScript
| Vulnerability | Pattern to Search |
|--------------|-------------------|
| SQL Injection | `query(` with template literals, string concatenation in SQL |
| XSS | `innerHTML`, `dangerouslySetInnerHTML`, `document.write` |
| Command Injection | `exec(`, `execSync(`, `spawn(` with variables |
| Hardcoded Secrets | `password`, `apiKey`, `secret`, `token` in assignments |
| Eval | `eval(`, `Function(`, `setTimeout(` with strings |
| Prototype Pollution | `Object.assign`, recursive merge without safeguards |
### Python
| Vulnerability | Pattern to Search |
|--------------|-------------------|
| SQL Injection | `cursor.execute(` with f-strings or `.format()` |
| Command Injection | `os.system(`, `subprocess` with `shell=True` |
| Deserialization | `pickle.loads(`, `yaml.load(` without `Loader` |
| Path Traversal | `open(` with user input, missing `os.path.abspath` check |
| SSRF | `requests.get(` with user-controlled URL |
## Anti-patterns
- **Only automated scanning, no manual review** — Automated tools catch pattern-based vulnerabilities (hardcoded secrets, known CVEs) but miss business logic flaws (race conditions in payments, broken authorization workflows). A security audit requires both.
- **Ignoring business logic flaws** — The most damaging vulnerabilities are often in business logic: can a user manipulate prices? Can they skip payment verification? Can they access another tenant's data? These are not detectable by pattern matching.
- **Not checking auth on every endpoint** — A single unprotected admin endpoint is a complete compromise. Systematically verify that every route has appropriate authentication and authorization middleware. Do not assume the framework handles it.
- **Reporting without remediation** — A finding without a fix is frustrating and unhelpful. Every finding must include a specific remediation with a code example, not just "fix the SQL injection."
- **Ignoring the git history** — Secrets removed from the current codebase may still be in git history. If a password was committed and then deleted, it is still compromised. Check `git log -p` for sensitive patterns.
- **Only checking direct dependencies** — Transitive dependencies are equally exploitable. A vulnerability in a sub-dependency of a sub-dependency can be used to compromise the application. Use `npm audit`, `pip audit`, or equivalent.
- **Treating low-severity findings as ignorable** — Low-severity findings in combination can enable a high-severity attack chain. Information disclosure plus IDOR plus missing rate limiting can add up to a full compromise.
- **Not documenting positive findings** — Security audits that only list problems demoralize teams. Acknowledging good practices reinforces them and prevents regression.
1---2name: audit-security3description: Perform a security audit when the user asks to check for vulnerabilities, audit security, review OWASP compliance, scan for secrets, or assess application security posture4---56# Audit Security78## Overview910Perform a structured security audit against the OWASP Top 10, scanning the codebase for injection vulnerabilities, broken authentication, sensitive data exposure, security misconfiguration, and broken access control. Combine automated pattern scanning with manual review of business logic and architecture decisions.1112## Workflow13141. **Read project context** — Check `.chalk/docs/engineering/` for:15 - Architecture docs (to understand auth patterns, data flow, trust boundaries)16 - Previous security audits (to track remediation progress)17 - API documentation (to identify endpoints requiring auth)18 - Infrastructure docs (to understand deployment security)19202. **Determine audit scope** — From `$ARGUMENTS` and conversation:21 - If a specific component or concern is named, focus there22 - If no scope is given, audit the entire codebase23 - Identify the tech stack to tailor the scan patterns (Node.js, Python, Go, etc.)24 - Note the application type: web API, SPA, mobile backend, CLI tool25263. **Scan for injection vulnerabilities** — Search the codebase for:27 - **SQL Injection**: String concatenation in queries, missing parameterized queries, raw SQL with user input28 - **XSS**: `innerHTML`, `dangerouslySetInnerHTML`, `document.write()`, unescaped template interpolation, `v-html`29 - **Command Injection**: `exec()`, `spawn()`, `system()`, `subprocess.call()` with user-controlled arguments30 - **Template Injection**: User input in template strings evaluated server-side31 - **Path Traversal**: User input in file paths without sanitization (`../` sequences)32 - **LDAP/NoSQL Injection**: Unsanitized input in LDAP or MongoDB queries33344. **Check authentication and session management** — Review:35 - **Password handling**: Hashing algorithm (bcrypt/argon2 = good, MD5/SHA1 = bad), salt usage, minimum complexity36 - **JWT**: Secret strength, algorithm pinning (reject `none`), expiration enforcement, token storage (httpOnly cookies vs. localStorage)37 - **Session**: Session ID entropy, session fixation protection, session timeout, invalidation on logout38 - **MFA**: Is it available? Is it enforced for sensitive operations?39 - **Rate limiting**: Login attempts, password reset, API endpoints40415. **Check for sensitive data exposure** — Scan for:42 - **Hardcoded secrets**: API keys, passwords, tokens, connection strings in source code43 - **Patterns**: `password\s*=`, `api_key`, `secret`, `token`, `AWS_`, `PRIVATE_KEY`, base64-encoded credentials44 - **Logging PII**: User emails, passwords, credit card numbers, SSNs in log statements45 - **Error messages**: Stack traces, database errors, internal paths exposed to users46 - **Git history**: Secrets that were committed and later removed (still in history)47 - **.env files**: Check if `.env` is in `.gitignore`, check for `.env.example` with real values48496. **Review security configuration** — Check:50 - **CORS**: Overly permissive origins (`*`), credentials with wildcard origin51 - **Security headers**: Missing `Content-Security-Policy`, `X-Frame-Options`, `Strict-Transport-Security`, `X-Content-Type-Options`52 - **Debug mode**: Debug flags enabled in production config, verbose error output53 - **HTTPS**: Mixed content, HTTP redirects, certificate validation disabled in code54 - **Cookie security**: Missing `Secure`, `HttpOnly`, `SameSite` attributes55 - **Default credentials**: Default admin accounts, unchanged default passwords56577. **Check access control** — Review:58 - **Authorization on every endpoint**: Are there routes missing auth middleware?59 - **IDOR**: Can users access resources by changing IDs in URLs? Is ownership verified?60 - **Privilege escalation**: Can a regular user access admin endpoints? Is role checking consistent?61 - **Horizontal access**: Can user A access user B's data?62 - **API authorization**: Are all API endpoints protected? Are there unprotected admin routes?63 - **File upload**: Unrestricted file types, missing virus scanning, path traversal in filenames64658. **Review business logic** — Beyond technical vulnerabilities:66 - Race conditions in financial operations (double spending, duplicate orders)67 - Missing validation on state transitions (e.g., order status can skip steps)68 - Insufficient rate limiting on expensive operations69 - Missing audit logging for sensitive actions70 - Insecure direct object references in business workflows71729. **Classify findings** — For each finding:73 - **Severity**: Critical, High, Medium, Low74 - **CWE reference**: Map to Common Weakness Enumeration where applicable75 - **OWASP category**: Which OWASP Top 10 category does this fall under76 - **Exploitability**: How easy is it to exploit? (trivial, moderate, difficult)77 - **Impact**: What could an attacker achieve?78 - **Evidence**: File path, line number, code snippet79 - **Remediation**: Specific fix with code example808110. **Determine the next file number** — List files in `.chalk/docs/engineering/` matching `*_security_audit*`. Find the highest number and increment by 1.828311. **Write the report** — Save to `.chalk/docs/engineering/<n>_security_audit.md`.848512. **Confirm** — Summarize: total findings by severity, most critical items, and overall security posture assessment.8687## Filename Convention8889```90<number>_security_audit.md91```9293Examples:94- `7_security_audit.md`95- `14_security_audit.md`9697## Security Audit Format9899```markdown100# Security Audit Report101102Last updated: <YYYY-MM-DD>103Scope: <what was audited>104Tech stack: <languages, frameworks, infrastructure>105106## Executive Summary107108<2-3 sentences: overall security posture, most critical findings, and top recommendation.>109110## Findings Summary111112| Severity | Count | Remediation Urgency |113|----------|-------|-------------------|114| Critical | <n> | Immediate — block release |115| High | <n> | Fix within 1 week |116| Medium | <n> | Fix within 1 month |117| Low | <n> | Fix in next maintenance cycle |118119## OWASP Coverage120121| OWASP Category | Findings | Status |122|---------------|----------|--------|123| A01: Broken Access Control | <n> | Issues found / Clear |124| A02: Cryptographic Failures | <n> | Issues found / Clear |125| A03: Injection | <n> | Issues found / Clear |126| A04: Insecure Design | <n> | Issues found / Clear |127| A05: Security Misconfiguration | <n> | Issues found / Clear |128| A06: Vulnerable and Outdated Components | <n> | Issues found / Clear |129| A07: Identification and Authentication Failures | <n> | Issues found / Clear |130| A08: Software and Data Integrity Failures | <n> | Issues found / Clear |131| A09: Security Logging and Monitoring Failures | <n> | Issues found / Clear |132| A10: Server-Side Request Forgery (SSRF) | <n> | Issues found / Clear |133134## Critical Findings135136### FINDING-1: <Title>137138| Field | Value |139|-------|-------|140| Severity | Critical |141| OWASP | A03: Injection |142| CWE | CWE-89: SQL Injection |143| Exploitability | Trivial |144| File | `<file path>:<line number>` |145146**Description**: <What the vulnerability is and why it matters>147148**Evidence**:149```<language>150// Vulnerable code151<code snippet>152```153154**Impact**: <What an attacker could achieve by exploiting this>155156**Remediation**:157```<language>158// Fixed code159<code snippet>160```161162## High Findings163164### FINDING-<n>: <Title>165<Same structure as Critical>166167## Medium Findings168169| ID | Title | OWASP | CWE | File | Remediation Summary |170|----|-------|-------|-----|------|-------------------|171| F-<n> | <title> | A05 | CWE-<n> | `<file>` | <one-line fix> |172173## Low Findings174175| ID | Title | OWASP | CWE | File | Remediation Summary |176|----|-------|-------|-----|------|-------------------|177| F-<n> | <title> | A05 | CWE-<n> | `<file>` | <one-line fix> |178179## Positive Findings180181<List security practices that are done well. This encourages good behavior and prevents regression.>182183- <Good practice observed with evidence>184185## Recommendations186187### Immediate Actions1881. <Most critical fix>189190### Short-Term (1-4 weeks)1911. <High-priority improvements>192193### Long-Term (1-3 months)1941. <Architectural security improvements>195```196197## Common Scan Patterns by Language198199### JavaScript / TypeScript200| Vulnerability | Pattern to Search |201|--------------|-------------------|202| SQL Injection | `query(` with template literals, string concatenation in SQL |203| XSS | `innerHTML`, `dangerouslySetInnerHTML`, `document.write` |204| Command Injection | `exec(`, `execSync(`, `spawn(` with variables |205| Hardcoded Secrets | `password`, `apiKey`, `secret`, `token` in assignments |206| Eval | `eval(`, `Function(`, `setTimeout(` with strings |207| Prototype Pollution | `Object.assign`, recursive merge without safeguards |208209### Python210| Vulnerability | Pattern to Search |211|--------------|-------------------|212| SQL Injection | `cursor.execute(` with f-strings or `.format()` |213| Command Injection | `os.system(`, `subprocess` with `shell=True` |214| Deserialization | `pickle.loads(`, `yaml.load(` without `Loader` |215| Path Traversal | `open(` with user input, missing `os.path.abspath` check |216| SSRF | `requests.get(` with user-controlled URL |217218## Anti-patterns219220- **Only automated scanning, no manual review** — Automated tools catch pattern-based vulnerabilities (hardcoded secrets, known CVEs) but miss business logic flaws (race conditions in payments, broken authorization workflows). A security audit requires both.221- **Ignoring business logic flaws** — The most damaging vulnerabilities are often in business logic: can a user manipulate prices? Can they skip payment verification? Can they access another tenant's data? These are not detectable by pattern matching.222- **Not checking auth on every endpoint** — A single unprotected admin endpoint is a complete compromise. Systematically verify that every route has appropriate authentication and authorization middleware. Do not assume the framework handles it.223- **Reporting without remediation** — A finding without a fix is frustrating and unhelpful. Every finding must include a specific remediation with a code example, not just "fix the SQL injection."224- **Ignoring the git history** — Secrets removed from the current codebase may still be in git history. If a password was committed and then deleted, it is still compromised. Check `git log -p` for sensitive patterns.225- **Only checking direct dependencies** — Transitive dependencies are equally exploitable. A vulnerability in a sub-dependency of a sub-dependency can be used to compromise the application. Use `npm audit`, `pip audit`, or equivalent.226- **Treating low-severity findings as ignorable** — Low-severity findings in combination can enable a high-severity attack chain. Information disclosure plus IDOR plus missing rate limiting can add up to a full compromise.227- **Not documenting positive findings** — Security audits that only list problems demoralize teams. Acknowledging good practices reinforces them and prevents regression.