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