Security Auditor (L3 Worker)
Specialized worker auditing security vulnerabilities in codebase.
Purpose & Scope
- Worker in ln-620 coordinator pipeline - invoked by ln-620-codebase-auditor
- Audit codebase for security vulnerabilities (Category 1: Critical Priority)
- Scan for hardcoded secrets, SQL injection, XSS, insecure dependencies, missing input validation
- Return structured findings to coordinator with severity, location, effort, recommendations
- Calculate compliance score (X/10) for Security category
Inputs (from Coordinator)
Receives contextStore as JSON string:
{
"tech_stack": {
"language": "TypeScript",
"frameworks": ["Express", "React"],
"database": "PostgreSQL",
...
},
"best_practices": {
"framework_patterns": [...],
"security_guidelines": [...]
},
"principles": {...},
"codebase_root": "/path/to/project"
}
Workflow
- Parse Context: Extract tech stack, best practices, codebase root from contextStore
- Scan Codebase: Run security checks using Glob/Grep patterns (see Audit Rules below)
- Collect Findings: Record each violation with severity, location (file:line), effort estimate (S/M/L), recommendation
- Calculate Score: Count violations by severity, calculate compliance score (X/10)
- Return Results: Return JSON with category, score, findings to coordinator
Audit Rules (Priority: CRITICAL)
1. Hardcoded Secrets
What: API keys, passwords, tokens, private keys in source code
Detection:
- Search patterns:
API_KEY = "...", password = "...", token = "...", SECRET = "..."
- File extensions:
.ts, .js, .py, .go, .java, .cs
- Exclude:
.env.example, README.md, test files with mock data
Severity:
- CRITICAL: Production credentials (AWS keys, database passwords, API tokens)
- HIGH: Development/staging credentials
- MEDIUM: Test credentials in non-test files
Recommendation: Move to environment variables (.env), use secret management (Vault, AWS Secrets Manager)
Effort: S (replace hardcoded value with process.env.VAR_NAME)
2. SQL Injection Patterns
What: String concatenation in SQL queries instead of parameterized queries
Detection:
- Patterns:
query = "SELECT * FROM users WHERE id=" + userId, db.execute(f"SELECT * FROM {table}"), `SELECT * FROM ${table}`
- Languages: JavaScript, Python, PHP, Java
Severity:
- CRITICAL: User input directly concatenated without sanitization
- HIGH: Variable concatenation in production code
- MEDIUM: Concatenation with internal variables only
Recommendation: Use parameterized queries (prepared statements), ORM query builders
Effort: M (refactor query to use placeholders)
3. XSS Vulnerabilities
What: Unsanitized user input rendered in HTML/templates
Detection:
- Patterns:
innerHTML = userInput, dangerouslySetInnerHTML={{__html: data}}, echo $userInput;
- Template engines: Check for unescaped output (
{{ var | safe }}, <%- var %>)
Severity:
- CRITICAL: User input directly inserted into DOM without sanitization
- HIGH: User input with partial sanitization (insufficient escaping)
- MEDIUM: Internal data with potential XSS if compromised
Recommendation: Use framework escaping (React auto-escapes, use textContent), sanitize with DOMPurify
Effort: S-M (replace innerHTML with textContent or sanitize)
4. Insecure Dependencies
What: Dependencies with known CVEs (Common Vulnerabilities and Exposures)
Detection:
- Run
npm audit (Node.js), pip-audit (Python), cargo audit (Rust), dotnet list package --vulnerable (.NET)
- Check for outdated critical dependencies
Severity:
- CRITICAL: CVE with exploitable vulnerability in production dependencies
- HIGH: CVE in dev dependencies or lower severity production CVEs
- MEDIUM: Outdated packages without known CVEs but security risk
Recommendation: Update to patched versions, replace unmaintained packages
Effort: S-M (update package.json, test), L (if breaking changes)
5. Missing Input Validation
What: Missing validation at system boundaries (API endpoints, user forms, file uploads)
Detection:
- API routes without validation middleware
- Form handlers without input sanitization
- File uploads without type/size checks
- Missing CORS configuration
Severity:
- CRITICAL: File upload without validation, authentication bypass potential
- HIGH: Missing validation on sensitive endpoints (payment, auth, user data)
- MEDIUM: Missing validation on read-only or internal endpoints
Recommendation: Add validation middleware (Joi, Yup, express-validator), implement input sanitization
Effort: M (add validation schema and middleware)
Scoring Algorithm
violations = {critical: N, high: M, medium: K, low: L}
penalty = (critical * 2.0) + (high * 1.0) + (medium * 0.5) + (low * 0.2)
score = max(0, 10 - penalty)
Examples:
- 0 violations → 10/10
- 1 critical → 8/10
- 2 critical, 3 high → 3/10
- 5 critical, 10 high → 0/10
Output Format
Return JSON to coordinator:
{
"category": "Security",
"score": 7,
"total_issues": 5,
"critical": 1,
"high": 2,
"medium": 2,
"low": 0,
"findings": [
{
"severity": "CRITICAL",
"location": "src/api/auth.ts:45",
"issue": "Hardcoded API key in production code",
"principle": "Secrets Management (OWASP A02:2021 Cryptographic Failures)",
"recommendation": "Move API_KEY to environment variable (.env file)",
"effort": "S"
},
{
"severity": "HIGH",
"location": "src/db/queries.ts:112",
"issue": "SQL injection via string concatenation",
"principle": "Input Validation (OWASP A03:2021 Injection)",
"recommendation": "Use parameterized queries or ORM to prevent SQL injection",
"effort": "M"
}
]
}
Critical Rules
- Do not auto-fix: Report violations only; coordinator creates task for user to fix
- Tech stack aware: Use contextStore to apply framework-specific patterns (e.g., React XSS vs PHP XSS)
- False positive reduction: Exclude test files, example configs, documentation
- Effort realism: S = <1 hour, M = 1-4 hours, L = >4 hours
- Location precision: Always include
file:line for programmatic navigation
Definition of Done
- contextStore parsed successfully
- All 5 security checks completed (secrets, SQL injection, XSS, deps, validation)
- Findings collected with severity, location, effort, recommendation
- Score calculated using penalty algorithm
- JSON result returned to coordinator
Reference Files
- Security audit rules: references/security_rules.md
Version: 3.0.0
Last Updated: 2025-12-23
1---2name: ln-621-security-auditor-23description: Security audit worker (L3). Scans codebase for hardcoded secrets, SQL injection, XSS, insecure dependencies, missing input validation. Returns findings with severity (Critical/High/Medium/Low), location, effort, and recommendations.4---5
6# Security Auditor (L3 Worker)
7
8Specialized worker auditing security vulnerabilities in codebase.
9
10## Purpose & Scope
11
12- **Worker in ln-620 coordinator pipeline** - invoked by ln-620-codebase-auditor
13- Audit codebase for **security vulnerabilities** (Category 1: Critical Priority)
14- Scan for hardcoded secrets, SQL injection, XSS, insecure dependencies, missing input validation
15- Return structured findings to coordinator with severity, location, effort, recommendations
16- Calculate compliance score (X/10) for Security category
17
18## Inputs (from Coordinator)
19
20Receives `contextStore` as JSON string:
21```json
22{
23 "tech_stack": {
24 "language": "TypeScript",
25 "frameworks": ["Express", "React"],
26 "database": "PostgreSQL",
27 ...
28 },
29 "best_practices": {
30 "framework_patterns": [...],
31 "security_guidelines": [...]
32 },
33 "principles": {...},
34 "codebase_root": "/path/to/project"
35}
36```
37
38## Workflow
39
401) **Parse Context:** Extract tech stack, best practices, codebase root from contextStore
412) **Scan Codebase:** Run security checks using Glob/Grep patterns (see Audit Rules below)
423) **Collect Findings:** Record each violation with severity, location (file:line), effort estimate (S/M/L), recommendation
434) **Calculate Score:** Count violations by severity, calculate compliance score (X/10)
445) **Return Results:** Return JSON with category, score, findings to coordinator
45
46## Audit Rules (Priority: CRITICAL)
47
48### 1. Hardcoded Secrets
49**What:** API keys, passwords, tokens, private keys in source code
50
51**Detection:**
52- Search patterns: `API_KEY = "..."`, `password = "..."`, `token = "..."`, `SECRET = "..."`
53- File extensions: `.ts`, `.js`, `.py`, `.go`, `.java`, `.cs`
54- Exclude: `.env.example`, `README.md`, test files with mock data
55
56**Severity:**
57- **CRITICAL:** Production credentials (AWS keys, database passwords, API tokens)
58- **HIGH:** Development/staging credentials
59- **MEDIUM:** Test credentials in non-test files
60
61**Recommendation:** Move to environment variables (.env), use secret management (Vault, AWS Secrets Manager)
62
63**Effort:** S (replace hardcoded value with `process.env.VAR_NAME`)
64
65### 2. SQL Injection Patterns
66**What:** String concatenation in SQL queries instead of parameterized queries
67
68**Detection:**
69- Patterns: `query = "SELECT * FROM users WHERE id=" + userId`, `db.execute(f"SELECT * FROM {table}")`, `` `SELECT * FROM ${table}` ``
70- Languages: JavaScript, Python, PHP, Java
71
72**Severity:**
73- **CRITICAL:** User input directly concatenated without sanitization
74- **HIGH:** Variable concatenation in production code
75- **MEDIUM:** Concatenation with internal variables only
76
77**Recommendation:** Use parameterized queries (prepared statements), ORM query builders
78
79**Effort:** M (refactor query to use placeholders)
80
81### 3. XSS Vulnerabilities
82**What:** Unsanitized user input rendered in HTML/templates
83
84**Detection:**
85- Patterns: `innerHTML = userInput`, `dangerouslySetInnerHTML={{__html: data}}`, `echo $userInput;`
86- Template engines: Check for unescaped output (`{{ var | safe }}`, `<%- var %>`)
87
88**Severity:**
89- **CRITICAL:** User input directly inserted into DOM without sanitization
90- **HIGH:** User input with partial sanitization (insufficient escaping)
91- **MEDIUM:** Internal data with potential XSS if compromised
92
93**Recommendation:** Use framework escaping (React auto-escapes, use `textContent`), sanitize with DOMPurify
94
95**Effort:** S-M (replace `innerHTML` with `textContent` or sanitize)
96
97### 4. Insecure Dependencies
98**What:** Dependencies with known CVEs (Common Vulnerabilities and Exposures)
99
100**Detection:**
101- Run `npm audit` (Node.js), `pip-audit` (Python), `cargo audit` (Rust), `dotnet list package --vulnerable` (.NET)
102- Check for outdated critical dependencies
103
104**Severity:**
105- **CRITICAL:** CVE with exploitable vulnerability in production dependencies
106- **HIGH:** CVE in dev dependencies or lower severity production CVEs
107- **MEDIUM:** Outdated packages without known CVEs but security risk
108
109**Recommendation:** Update to patched versions, replace unmaintained packages
110
111**Effort:** S-M (update package.json, test), L (if breaking changes)
112
113### 5. Missing Input Validation
114**What:** Missing validation at system boundaries (API endpoints, user forms, file uploads)
115
116**Detection:**
117- API routes without validation middleware
118- Form handlers without input sanitization
119- File uploads without type/size checks
120- Missing CORS configuration
121
122**Severity:**
123- **CRITICAL:** File upload without validation, authentication bypass potential
124- **HIGH:** Missing validation on sensitive endpoints (payment, auth, user data)
125- **MEDIUM:** Missing validation on read-only or internal endpoints
126
127**Recommendation:** Add validation middleware (Joi, Yup, express-validator), implement input sanitization
128
129**Effort:** M (add validation schema and middleware)
130
131## Scoring Algorithm
132
133```
134violations = {critical: N, high: M, medium: K, low: L}
135
136penalty = (critical * 2.0) + (high * 1.0) + (medium * 0.5) + (low * 0.2)
137
138score = max(0, 10 - penalty)
139```
140
141**Examples:**
142- 0 violations → 10/10
143- 1 critical → 8/10
144- 2 critical, 3 high → 3/10
145- 5 critical, 10 high → 0/10
146
147## Output Format
148
149Return JSON to coordinator:
150```json
151{
152 "category": "Security",
153 "score": 7,
154 "total_issues": 5,
155 "critical": 1,
156 "high": 2,
157 "medium": 2,
158 "low": 0,
159 "findings": [
160 {
161 "severity": "CRITICAL",
162 "location": "src/api/auth.ts:45",
163 "issue": "Hardcoded API key in production code",
164 "principle": "Secrets Management (OWASP A02:2021 Cryptographic Failures)",
165 "recommendation": "Move API_KEY to environment variable (.env file)",
166 "effort": "S"
167 },
168 {
169 "severity": "HIGH",
170 "location": "src/db/queries.ts:112",
171 "issue": "SQL injection via string concatenation",
172 "principle": "Input Validation (OWASP A03:2021 Injection)",
173 "recommendation": "Use parameterized queries or ORM to prevent SQL injection",
174 "effort": "M"
175 }
176 ]
177}
178```
179
180## Critical Rules
181
182- **Do not auto-fix:** Report violations only; coordinator creates task for user to fix
183- **Tech stack aware:** Use contextStore to apply framework-specific patterns (e.g., React XSS vs PHP XSS)
184- **False positive reduction:** Exclude test files, example configs, documentation
185- **Effort realism:** S = <1 hour, M = 1-4 hours, L = >4 hours
186- **Location precision:** Always include `file:line` for programmatic navigation
187
188## Definition of Done
189
190- contextStore parsed successfully
191- All 5 security checks completed (secrets, SQL injection, XSS, deps, validation)
192- Findings collected with severity, location, effort, recommendation
193- Score calculated using penalty algorithm
194- JSON result returned to coordinator
195
196## Reference Files
197
198- Security audit rules: [references/security_rules.md](references/security_rules.md)
199
200---
201**Version:** 3.0.0
202**Last Updated:** 2025-12-23