coverme-scanner 1.10.2 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2466 +1,298 @@
1
- # CoverMe Multi-Agent Scan Orchestration
1
+ # CoverMe Security Scanner
2
2
 
3
- **Ultrathink** - Analyze deeply, consider edge cases, trace data flows completely.
3
+ You are a senior security consultant performing a comprehensive security assessment.
4
4
 
5
- Execute this multi-agent security scan with cross-validation.
5
+ **Ultrathink** - Analyze deeply, read actual code, trace data flows.
6
6
 
7
7
  ---
8
8
 
9
- ## CRITICAL: FILE-BASED AGENT OUTPUT (Prevents Token Overflow)
9
+ ## PHASE 1: DISCOVERY
10
10
 
11
- **Each agent MUST save its findings to a file instead of returning them to the orchestrator.**
12
-
13
- This prevents the orchestrator from hitting max tokens when consolidating 17+ agents.
14
-
15
- ### Agent Output Rules:
16
-
17
- 1. **Each agent saves to**: `.coverme/agents/{AGENT_ID}.json`
18
- 2. **Create directory first**: `mkdir -p .coverme/agents`
19
- 3. **Agent returns ONLY**: `{"status": "complete", "file": ".coverme/agents/SEC.json", "findingsCount": 5}`
20
- 4. **Orchestrator reads files** after all agents complete
21
-
22
- ### Agent Output File Format:
23
- ```json
24
- {
25
- "agentId": "SEC",
26
- "agentName": "Security Core Scanner",
27
- "scanDate": "2026-02-18T10:00:00Z",
28
- "duration": "45s",
29
- "findings": [...],
30
- "positives": [...],
31
- "skipped": false,
32
- "skipReason": null
33
- }
34
- ```
35
-
36
- ### Orchestrator Consolidation:
37
- ```bash
38
- # After all agents complete, read all findings:
39
- cat .coverme/agents/*.json | jq -s 'map(.findings) | flatten'
40
- ```
41
-
42
- This architecture allows unlimited agents without token overflow.
43
-
44
- ---
45
-
46
- ## PHASE 0: PROJECT DISCOVERY & ARCHITECTURE MAPPING
47
-
48
- Before scanning, understand what you're scanning and build the architecture map.
49
-
50
- ### Step 0: Initialize Agent Output Directory
51
-
52
- ```bash
53
- mkdir -p .coverme/agents
54
- ```
55
-
56
- ### Step 1: Gather Project Statistics
57
-
58
- ### Step 1: Gather Project Statistics
59
-
60
- ```bash
61
- # List ALL top-level directories (excluding hidden, node_modules, dist, build)
62
- ls -d */ 2>/dev/null | grep -v -E '^(node_modules|dist|build|\.)/
63
-
64
- # Count files and lines of code
65
- find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" -o -name "*.py" -o -name "*.go" -o -name "*.java" -o -name "*.rb" -o -name "*.php" -o -name "*.cs" -o -name "*.swift" -o -name "*.kt" \) -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" -not -path "*/build/*" -not -path "*/__pycache__/*" | wc -l
66
-
67
- # Count lines of code (approximate)
68
- find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.jsx" -o -name "*.py" -o -name "*.go" \) -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" 2>/dev/null | head -100 | xargs wc -l 2>/dev/null | tail -1
69
-
70
- # Generate project tree (2 levels deep)
71
- find . -maxdepth 2 -type d -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" -not -path "*/__pycache__/*" -not -path "*/build/*" | sort
72
- ```
73
-
74
- ### Step 2: Read Project Info
75
-
76
- ```bash
77
- cat package.json 2>/dev/null | head -30
78
- cat README.md 2>/dev/null | head -100
79
- ls -la
80
- ls src/ 2>/dev/null || ls app/ 2>/dev/null || ls lib/ 2>/dev/null
81
- ```
82
-
83
- ### Step 3: Create Project Overview
84
-
85
- Include these statistics in the final report:
86
-
87
- ```json
88
- {
89
- "filesScanned": 45,
90
- "linesOfCode": 4850,
91
- "projectTree": "project-name/\n├── src/\n│ ├── api/\n│ ├── services/\n│ └── utils/\n├── tests/\n└── package.json",
92
- "projectOverview": {
93
- "name": "project-name",
94
- "type": "Backend API | Frontend SPA | Full-stack | CLI | Library | Microservice",
95
- "stack": ["Node.js", "TypeScript", "React", "PostgreSQL", "Redis"],
96
- "purpose": "1-2 sentence description of what this project does",
97
- "architecture": "Monolith | Microservices | Serverless | Hybrid",
98
- "keyComponents": ["backend-api/", "frontend/", "services/", "packages/", "etc"]
99
- }
100
- }
101
- ```
102
-
103
- **IMPORTANT**:
104
- - `filesScanned` - Count of source code files analyzed (not node_modules/dist)
105
- - `linesOfCode` - Total lines in source files (approximate is fine)
106
- - `projectTree` - ASCII tree representation of main directories (use tree format with ├── and └──)
107
- - `keyComponents` - **MUST include ALL top-level directories** containing source code. Do NOT skip any directory. List every folder from `ls -d */` excluding node_modules/dist/build/.git
108
-
109
- This context helps readers understand the security findings in context.
110
-
111
- ### Step 3: Check for Previous Scan Results
112
-
113
- ```bash
114
- cat .coverme/scan.json 2>/dev/null | head -5 || echo "NO_PREVIOUS_SCAN"
115
- ```
116
-
117
- **IF previous scan.json exists:**
118
- - Load previous findings to track what was resolved since the last scan
119
- - Compare current findings against previous findings
120
- - Any finding from previous scan NOT found in current scan = "Previously Resolved"
121
- - Include a `previouslyResolved` array in the final output showing what was fixed
122
- - This builds trust and shows security progress over time
123
-
124
- **Format for previously resolved:**
125
- ```json
126
- {
127
- "id": "PREV-001",
128
- "title": "Original finding title from previous scan",
129
- "originalSeverity": "critical|high|medium|low",
130
- "resolution": "How it was fixed — be specific: 'Replaced string concatenation with parameterized queries via Prisma ORM. Verified no raw SQL remains.'",
131
- "resolvedDate": "Date of current scan"
132
- }
133
- ```
134
-
135
- **Example Previously Resolved section (from Officely report):**
136
- - "DuckDB SQL Injection (was CRITICAL) — Resolved: enable_external_access=false sandbox + comprehensive SQL validation blocklist."
137
- - "Admin API Fail-Open (was HIGH) — Resolved: Binds to 127.0.0.1, fail-closed when no ADMIN_ALLOWED_IPS. Three-layer defense."
138
- - "Redis KEYS in Production (was HIGH) — Resolved: All paths now use SCAN via cursor-based scanKeys()."
139
-
140
- **IF NO previous scan:**
141
- - Skip — set `previouslyResolved` to empty array `[]`
142
-
143
- ### Step 4: Check for Runtime Verification (SSH)
144
-
145
- ```bash
146
- cat .coverme/runtime.json 2>/dev/null || echo "NO_RUNTIME_CONFIG"
147
- ```
148
-
149
- **IF runtime.json exists with environments:**
150
- - Runtime verification is ENABLED
151
- - Store the SSH details for use in AGENT 22 (Runtime Verification)
152
- - The agent will SSH to compare actual runtime vs code expectations
153
-
154
- **IF NO runtime.json:**
155
- - Runtime verification is DISABLED (skip AGENT 22)
156
- - This is normal - many projects don't need runtime verification
157
-
158
- ### Step 5: Architecture Discovery (AGENT 0)
159
-
160
- **This runs FIRST, before all other agents. Its output feeds into every subsequent agent.**
161
-
162
- Build a comprehensive architecture map by analyzing:
163
-
164
- ```bash
165
- # Detect databases
166
- grep -r -l "prisma\|mongoose\|sequelize\|typeorm\|pg\|mysql\|redis\|mongodb" --include="*.json" --include="*.ts" --include="*.js" . 2>/dev/null | head -5
167
-
168
- # Detect auth providers
169
- grep -r -l "clerk\|auth0\|firebase.auth\|passport\|next-auth\|supabase.auth" --include="*.ts" --include="*.js" . 2>/dev/null | head -5
170
-
171
- # Detect external APIs
172
- grep -r "fetch\|axios\|got\|request" --include="*.ts" --include="*.js" . 2>/dev/null | grep -v node_modules | head -10
173
-
174
- # Detect infrastructure
175
- ls -la Dockerfile docker-compose* k8s/ helm/ .github/workflows/ 2>/dev/null
176
- ```
177
-
178
- **Save architecture map to `.coverme/agents/ARCH-D.json`:**
179
- ```json
180
- {
181
- "agentId": "ARCH-D",
182
- "agentName": "Architecture Discovery",
183
- "architecture": {
184
- "components": [
185
- {"name": "API Server", "type": "service", "tech": "Express.js", "files": ["src/server.ts"]},
186
- {"name": "PostgreSQL", "type": "database", "tech": "Prisma", "files": ["prisma/schema.prisma"]},
187
- {"name": "Redis", "type": "cache", "tech": "ioredis", "files": ["src/redis.ts"]}
188
- ],
189
- "trustBoundaries": [
190
- {"name": "Client → API", "from": "Browser", "to": "API Server", "protocol": "HTTPS"},
191
- {"name": "API → DB", "from": "API Server", "to": "PostgreSQL", "protocol": "TLS"}
192
- ],
193
- "externalDependencies": [
194
- {"name": "Stripe", "type": "payment", "files": ["src/payments/stripe.ts"]},
195
- {"name": "OpenAI", "type": "ai", "files": ["src/ai/openai.ts"]}
196
- ],
197
- "criticalAssets": [
198
- {"name": "User Credentials", "location": "PostgreSQL", "protection": "bcrypt"},
199
- {"name": "API Keys", "location": "Environment", "protection": "Secrets Manager"}
200
- ]
201
- },
202
- "detectedTechnologies": {
203
- "hasAI": true,
204
- "hasRedis": true,
205
- "hasEnclave": false,
206
- "hasDatabase": true,
207
- "databaseType": "PostgreSQL"
208
- }
209
- }
210
- ```
211
-
212
- **This architecture map is used by:**
213
- - All scanners to understand context
214
- - EXEC agent for executive summary
215
- - Final report for architecture overview
216
-
217
- ---
218
-
219
- ## CRITICAL OUTPUT FORMAT
220
-
221
- Every finding MUST include ALL these fields for the report to work:
222
-
223
- ```json
224
- {
225
- "id": "PREFIX-XXX",
226
- "title": "Descriptive title specific to the exact vulnerability (NOT generic category labels)",
227
- "severity": "critical|high|medium|low|info",
228
- "category": "Category name",
229
- "file": "exact/path/to/file.ts",
230
- "line": 123,
231
- "endLine": 156,
232
- "code": "the vulnerable/problematic code snippet",
233
- "description": "Precise technical narrative: what function has the issue, how it manifests, why it's dangerous. Include DREAD-D score inline for HIGH/CRITICAL.",
234
- "impact": "Security impact - what an attacker could exploit, potential damage, real-world risk",
235
- "attackChain": "Step-by-step exploitation: 1. Attacker does X, 2. System responds with Y, 3. Attacker gains Z",
236
- "recommendation": "Immediately actionable: specific function names, specific patterns, specific code changes",
237
- "cwe": "CWE-XXX (if applicable)",
238
- "confidence": 85,
239
- "fixOwner": "developer|devops|architect",
240
- "fixType": "code|config|infrastructure|design",
241
- "crossReferences": ["OTHER-ID-1"],
242
- "dread": {
243
- "damage": 8,
244
- "reproducibility": 9,
245
- "exploitability": 7,
246
- "affectedUsers": 10,
247
- "discoverability": 6,
248
- "score": 8.0
249
- }
250
- }
251
- ```
252
-
253
- ### fixOwner & fixType Guidelines
254
-
255
- **fixOwner** - Who should fix this:
256
- - `developer` - Code change required (validation, sanitization, logic fix)
257
- - `devops` - Infrastructure/config change (NetworkPolicy, firewall, K8s config, CI/CD)
258
- - `architect` - Design decision needed (authentication strategy, data flow, service boundaries)
259
-
260
- **fixType** - What kind of fix:
261
- - `code` - Change application code
262
- - `config` - Change configuration files (env, yaml, json)
263
- - `infrastructure` - Change deployment/infra (K8s, Docker, cloud)
264
- - `design` - Requires architectural redesign
265
-
266
- ## DREAD SCORING (for HIGH and CRITICAL findings)
267
-
268
- Calculate DREAD score (1-10 for each, average for final score):
269
-
270
- - **Damage**: How severe is the impact? (10 = full system compromise, 1 = minimal)
271
- - **Reproducibility**: How easy to reproduce? (10 = always works, 1 = rare conditions)
272
- - **Exploitability**: How easy to exploit? (10 = script kiddie, 1 = expert + physical access)
273
- - **Affected Users**: How many users impacted? (10 = all users, 1 = single admin)
274
- - **Discoverability**: How easy to find? (10 = obvious, 1 = requires source code)
275
-
276
- **Score interpretation**:
277
- - 9.0-10.0 = CRITICAL (exploit immediately)
278
- - 7.0-8.9 = HIGH (fix within days)
279
- - 5.0-6.9 = MEDIUM (fix within sprint)
280
- - 3.0-4.9 = LOW (backlog)
281
- - 1.0-2.9 = INFO (document only)
282
-
283
- ## PROFESSIONAL WRITING STANDARDS
284
-
285
- **Every finding must read as if written by an experienced security consultant, not a generic scanner.**
286
-
287
- ### Title Quality
288
- Titles must be descriptive and specific to the exact vulnerability — not generic category labels.
289
-
290
- **BAD (generic):**
291
- - "Hardcoded credentials found"
292
- - "Missing input validation"
293
- - "XSS vulnerability"
294
-
295
- **GOOD (descriptive, specific to the code):**
296
- - "Hardcoded Tracker API Keys and Hash Salts in Helm Values"
297
- - "Attestation Fallback Accepts Unverified Enclave Keys"
298
- - "Credit Deduction After GPU Processing in Non-Streaming Path"
299
- - "Command Injection via Unvalidated Model Name in pm2 delete"
300
-
301
- ### Description Quality
302
- Descriptions must trace the exact technical flow: what function, what input, what happens, and what the consequence is — in ONE precise paragraph.
303
-
304
- **BAD (vague):**
305
- "There is a security issue with hardcoded credentials in the configuration file. This could allow unauthorized access."
306
-
307
- **GOOD (precise technical narrative):**
308
- "Staging and production Helm values contain hardcoded API keys (stg-tracker-api-key, prd-tracker-api-key) and hash salts in plaintext, committed to version control. Anyone with repo access can write arbitrary data to the tracker. DREAD-D: 6.5."
309
-
310
- **GOOD (traces the full attack flow):**
311
- "When the attestation bundle endpoint is unavailable, fetchEnclaveInfo() falls back to the legacy /api/v1/enclave endpoint and stores keys with keysVerified: false. The browser silently proceeds to encrypt messages with public keys that have not been cryptographically bound to hardware attestation — enabling a man-in-the-middle attack by a compromised gateway."
312
-
313
- **GOOD (explains business logic flaw):**
314
- "In the non-streaming path, credit deduction happens after the enclave has processed the request. A concurrent request could deplete credits between the pre-flight check and the deduction, consuming GPU resources without payment. The streaming path handles this correctly."
315
-
316
- ### Recommendation Quality
317
- Recommendations must be immediately actionable — specific function names, specific patterns, specific code.
318
-
319
- **BAD:**
320
- "Fix the hardcoded credentials"
321
- "Add input validation"
322
-
323
- **GOOD:**
324
- "Move to AWS Secrets Manager alongside existing KP_SECRETS_PATH pattern. Remove from version control. Rotate immediately."
325
- "Extract to trackRedisMetrics(redis, models, userIdentifier) and call from both paths."
326
- "Move validation to the top of startModels(). Apply in stopModels(). Use execFileAsync('pm2', ['delete', model])."
327
- "Validate against whitelist from models.json or restrict to ^[a-zA-Z0-9_-]+$."
328
-
329
- ### Cross-Referencing
330
- When multiple agents identify the same issue from different perspectives, MERGE them using dual IDs:
331
- - "CR-02 / T-EKS-3: Hardcoded Tracker API Keys and Hash Salts in Helm Values"
332
- - "T-EKS-4 / CR-18: User Identity Logged and Hash Truncated to 64 Bits"
333
- - "T-BFF-3 / CR-08: Error Details Leaked to Clients"
334
-
335
- This shows the issue was found independently from multiple angles, increasing confidence.
336
-
337
- ### Quantitative Precision
338
- Always include specific numbers when available:
339
- - Line counts: "160 lines of Redis metrics tracking code is duplicated verbatim"
340
- - Percentages: "5.3% of the codebase"
341
- - Bit lengths: "truncates SHA-256 to only 16 hex characters (64 bits)"
342
- - Specific values: "session timeout of 24h", "maxAge: 31536000"
343
-
344
- ### DREAD Score Inline
345
- For HIGH and CRITICAL findings, include the DREAD-D score directly in the description text: "DREAD-D: 6.3."
346
-
347
- ### Positive Observations Depth
348
- Positive observations must cite specific technical evidence, not generic praise.
349
-
350
- **BAD:**
351
- "Good authentication implementation"
352
-
353
- **GOOD:**
354
- "Zero-Knowledge Architecture — EKS gateway genuinely never sees plaintext. Encrypted payloads flow through without decryption. Well-enforced across all components."
355
- "Atomic Credit Operations — Lua scripts for token burning and balance deduction prevent cross-pod race conditions. Check-and-deduct is atomic."
356
- "Secure File Handling — MIME + magic number validation, memory-only storage, size limits. secureDeleteFile() overwrites with random data before deletion."
357
-
358
- ---
359
-
360
- ## FIELD GUIDELINES
361
-
362
- ### description (REQUIRED — PROFESSIONAL QUALITY)
363
- Write a precise technical narrative explaining:
364
- 1. **What** specific function/file/pattern has the issue
365
- 2. **How** the vulnerability manifests (trace the data flow)
366
- 3. **Why** it's dangerous (the consequence in one clause)
367
- 4. Include DREAD-D score inline for HIGH/CRITICAL: "DREAD-D: 6.5."
368
-
369
- ### impact (REQUIRED)
370
- Explain the real-world security impact. Be specific about:
371
- - What an attacker could do (e.g., "steal session tokens", "access other users' data")
372
- - The potential damage (e.g., "full account takeover", "data breach")
373
- - Why this matters to the business (e.g., "regulatory compliance violation", "reputation damage")
374
-
375
- Example: "An attacker could inject malicious scripts that steal session cookies, enabling full account takeover of any logged-in user"
376
-
377
- ### recommendation (REQUIRED — ACTIONABLE)
378
- Must include at least one of:
379
- - Specific function/method name to create or modify
380
- - Specific configuration change with exact values
381
- - Specific library/pattern to use
382
- - Code snippet showing the fix
383
-
384
- ---
385
-
386
- ## PHASE 1: BATCHED DISCOVERY (Memory-Efficient)
387
-
388
- **CRITICAL: To prevent memory overflow, run agents in SMALL BATCHES of 3-4 agents max.**
389
-
390
- ### Memory Management Rules:
391
- 1. **Never run more than 4 agents in parallel** - prevents context overflow
392
- 2. **Each agent returns ONLY a status message** - not full findings
393
- 3. **Agents save findings to files** - orchestrator reads files later
394
- 4. **Wait for batch to complete before starting next batch**
395
-
396
- ### Batch Schedule:
397
- ```
398
- Batch 1 (Core Security): SEC, AUTH, API, INFRA
399
- Batch 2 (Specialized): AI, BIZ, DATA, PERF
400
- Batch 3 (Quality): QUAL, TEST, DEAD, PII
401
- Batch 4 (Deep Analysis): REDIS, RESIL, DB, ARCH
402
- Batch 5 (Validation): DESIGN, CTX, ENC, DUP
403
- Batch 6 (Summary): EXEC (single agent)
404
- ```
405
-
406
- **IMPORTANT: Each agent MUST follow these steps:**
407
-
408
- 1. **Create output directory**: `mkdir -p .coverme/agents`
409
- 2. **Scan the codebase** according to agent-specific instructions
410
- 3. **Save findings to file**: `.coverme/agents/{AGENT_ID}.json`
411
- 4. **Return ONLY a short status** (not findings!): `{"status": "complete", "file": ".coverme/agents/{AGENT_ID}.json", "count": N}`
412
-
413
- **DO NOT return full findings in agent response - this causes memory overflow!**
414
-
415
- **Agent output file template:**
416
- ```json
417
- {
418
- "agentId": "SEC",
419
- "agentName": "Security Core Scanner",
420
- "scanDate": "{{SCAN_DATE}}",
421
- "skipped": false,
422
- "skipReason": null,
423
- "findings": [/* array of findings */],
424
- "positives": [/* array of positive observations */]
425
- }
426
- ```
427
-
428
- **For CONDITIONAL agents (AI, REDIS, ENC, DB):**
429
- - First detect if relevant code exists
430
- - If NOT found: `{"skipped": true, "skipReason": "No AI/LLM code detected", "findings": []}`
431
- - If found: proceed with normal scan
432
-
433
- ---
434
-
435
- ### AGENT 1: Security Core Scanner (ID prefix: SEC)
436
-
437
- Scan {{PROJECT_PATH}} for OWASP Top 10 and core security vulnerabilities.
438
-
439
- CHECK FOR:
440
- - SQL/NoSQL Injection (parameterized queries missing)
441
- - XSS (reflected, stored, DOM-based)
442
- - Command Injection (shell commands with user input)
443
- - Path Traversal (../ in file operations)
444
- - SSRF (user-controlled URLs in fetch/axios)
445
- - XXE (XML parsing without disabling entities)
446
- - Insecure Deserialization (JSON.parse on untrusted data)
447
- - Hardcoded Secrets (API keys, passwords, tokens in code)
448
- - Weak Cryptography (MD5, SHA1 for passwords, ECB mode)
449
- - Insecure Random (Math.random for security purposes)
450
-
451
- **DATABASE-SPECIFIC DANGEROUS FUNCTIONS** (check for ANY database):
452
- - DuckDB: read_text(), read_blob(), read_csv_auto(), read_parquet(), glob(), getenv(), httpfs
453
- - SQLite: load_extension(), readfile(), writefile()
454
- - PostgreSQL: pg_read_file(), pg_ls_dir(), COPY TO/FROM
455
- - MySQL: LOAD_FILE(), INTO OUTFILE, INTO DUMPFILE
456
- - MongoDB: $where with user input, mapReduce with user functions
457
- - Redis: EVAL/EVALSHA with user input, CONFIG, DEBUG commands
458
-
459
- **BLOCKLIST BYPASS PATTERNS**:
460
- - Keyword blocklists that miss database-specific functions
461
- - Case sensitivity bypass (READ_TEXT vs read_text)
462
- - Unicode homoglyph bypass
463
- - Comment injection (SELECT/**/read_text)
464
- - Encoding bypass (hex, base64, URL encoding)
465
-
466
- For EACH finding, output the FULL JSON format above.
467
-
468
- ---
469
-
470
- ### AGENT 2: Auth & Session Scanner (ID prefix: AUTH)
471
-
472
- Scan {{PROJECT_PATH}} for authentication and session vulnerabilities.
473
-
474
- **FIRST: Detect which auth method(s) this project uses:**
475
-
476
- | Auth Type | Detection Pattern |
477
- |-----------|-------------------|
478
- | OAuth/OIDC | `oauth`, `oidc`, `authorization_code`, `client_id`, `redirect_uri` |
479
- | JWT | `jsonwebtoken`, `jwt`, `Bearer`, `accessToken`, `refreshToken` |
480
- | Session-based | `express-session`, `cookie-session`, `session.save`, `req.session` |
481
- | API Keys | `x-api-key`, `apiKey`, `api_key`, `API_SECRET` |
482
- | Basic Auth | `Basic `, `Authorization`, `btoa`, `base64` |
483
- | Clerk | `@clerk`, `useAuth`, `clerkMiddleware` |
484
- | Auth0 | `@auth0`, `auth0-js`, `auth0-react` |
485
- | Firebase Auth | `firebase/auth`, `signInWith`, `onAuthStateChanged` |
486
- | Passport.js | `passport`, `passport-local`, `passport-jwt` |
487
- | Supabase Auth | `@supabase/auth`, `supabase.auth` |
488
- | NextAuth | `next-auth`, `NextAuth`, `getServerSession` |
489
- | Custom | `login`, `authenticate`, `verifyToken`, `checkAuth` |
490
-
491
- **FOR EACH AUTH TYPE DETECTED, check specific vulnerabilities:**
492
-
493
- **OAuth/OIDC:**
494
- - Open redirect in return_url/redirect_uri (CRITICAL!)
495
- - State parameter missing or predictable
496
- - PKCE not implemented for public clients
497
- - Token stored in localStorage (XSS vulnerable)
498
- - Refresh token rotation missing
499
- - ID token validation incomplete
500
-
501
- **JWT:**
502
- - `alg: none` accepted (signature bypass)
503
- - Weak secret (< 256 bits)
504
- - No expiry (`exp` claim missing)
505
- - Secret in code/env without rotation
506
- - `HS256` when `RS256` needed (shared secret risk)
507
- - Token not invalidated on logout
508
-
509
- **Session-based:**
510
- - Session ID in URL (referer leak)
511
- - Session not invalidated on logout
512
- - Session timeout too long (>24h)
513
- - Session fixation (not regenerated after login)
514
- - Session data not encrypted
515
- - Missing `secure`, `httpOnly`, `sameSite` on cookies
516
-
517
- **API Keys:**
518
- - API key in URL (logged, cached, referer leak)
519
- - No key rotation mechanism
520
- - Same key for all environments
521
- - Key logged or in error messages
522
- - No per-key rate limiting
523
-
524
- **Password/Credentials:**
525
- - Password reset: predictable tokens
526
- - Password reset: no expiry
527
- - No rate limiting on login
528
- - User enumeration via different responses
529
- - Passwords stored without hashing
530
- - Weak password policy
531
-
532
- **UNIVERSAL AUTH CHECKS (all types):**
533
- - Brute force protection missing
534
- - MFA bypass paths
535
- - Account lockout not implemented
536
- - Auth state not cleared on logout
537
- - Sensitive endpoints without auth
538
-
539
- **MEMORY SAFETY FOR SECRETS**:
540
- - Cryptographic keys not zeroed after use
541
- - Passwords stored in String instead of char[]
542
- - Session tokens not cleared on logout
543
- - Private keys in JavaScript objects (V8 heap)
544
-
545
- **TIMING ATTACKS**:
546
- - Non-constant-time string comparison for tokens/secrets
547
- - Early return on auth failure leaking valid usernames
548
- - Different response times for valid vs invalid credentials
549
-
550
- For EACH finding, output the FULL JSON format.
551
-
552
- ---
553
-
554
- ### AGENT 3: API Security Scanner (ID prefix: API)
555
-
556
- Scan {{PROJECT_PATH}} for API security issues.
557
-
558
- CHECK FOR:
559
- - Missing authentication on endpoints
560
- - Broken authorization (IDOR, privilege escalation)
561
- - Input validation missing (Zod/Joi schemas)
562
- - Rate limiting issues (non-atomic INCR+EXPIRE in Redis)
563
- - CORS misconfiguration (Access-Control-Allow-Origin: *)
564
- - Mass assignment (spreading req.body into DB)
565
- - Webhook signature verification missing (HMAC)
566
- - GraphQL introspection enabled in production
567
- - API versioning issues
568
- - Excessive data exposure in responses
569
-
570
- **CORS MISCONFIGURATION** (MEDIUM):
571
- Look for these vulnerable patterns:
572
- ```javascript
573
- // VULNERABLE - reflects ANY origin
574
- res.header('Access-Control-Allow-Origin', req.headers.origin);
575
- res.header('Access-Control-Allow-Origin', '*');
576
-
577
- // VULNERABLE - no whitelist validation
578
- app.use(cors({ origin: true }));
579
- ```
580
- Only mark as safe if there's explicit whitelist validation:
581
- ```javascript
582
- const allowedOrigins = ['https://app.example.com'];
583
- if (allowedOrigins.includes(origin)) { ... }
584
- ```
585
-
586
- **HELMET MISCONFIGURATION** (MEDIUM):
587
- ```javascript
588
- app.use(helmet()); // Using defaults only - INSUFFICIENT!
589
- ```
590
- Check that helmet() includes:
591
- - Custom `contentSecurityPolicy` with proper directives
592
- - `hsts: { maxAge: 31536000, includeSubDomains: true, preload: true }`
593
- - Proper `referrerPolicy`
594
- Report as MEDIUM if using only defaults without customization.
595
-
596
- **FAIL-OPEN vs FAIL-CLOSED PATTERNS** (CRITICAL):
597
- - IP whitelist empty/missing = allow all (should deny all)
598
- - Auth middleware errors = request passes through (should block)
599
- - Rate limiter Redis down = no limiting (should block or use fallback)
600
- - Config missing = insecure defaults (should fail startup)
601
- - Feature flag missing = feature enabled (should be disabled)
602
- - RBAC role not found = access granted (should deny)
603
-
604
- Look for patterns like:
605
- ```
606
- if (whitelist.length > 0) { check() } // FAIL-OPEN: empty whitelist bypasses
607
- if (!config.AUTH_REQUIRED) { next() } // FAIL-OPEN: missing config = no auth
608
- catch(e) { next() } // FAIL-OPEN: error = proceed
609
- ```
610
-
611
- **ADMIN/INTERNAL API EXPOSURE**:
612
- - Admin APIs bound to 0.0.0.0 instead of 127.0.0.1
613
- - Internal ports exposed without auth
614
- - Debug endpoints in production
615
- - Metrics/health endpoints exposing sensitive data
616
-
617
- For EACH finding, output the FULL JSON format.
618
-
619
- ---
620
-
621
- ### AGENT 4: Infrastructure Scanner (ID prefix: INFRA)
622
-
623
- Scan {{PROJECT_PATH}} for infrastructure and DevOps issues.
624
-
625
- CHECK FOR:
626
- - Secrets in git-tracked files (Helm values, K8s manifests, .env committed)
627
- - Real IPs/hostnames committed to repo
628
- - Docker issues (running as root, secrets in layers)
629
- - K8s pod security context missing
630
- - CI/CD pipeline security (missing quality gates)
631
- - Missing security headers in server config
632
- - TLS/SSL configuration issues
633
- - Debug mode enabled in production configs
634
- - Exposed internal ports
635
- - Missing resource limits
636
-
637
- **SECRETS IN CONFIGURATION FILES** (check ALL config formats):
638
- - Helm values.yaml / values-*.yaml with hardcoded secrets
639
- - Kubernetes secrets not using external secrets manager
640
- - Docker Compose with hardcoded passwords
641
- - Terraform tfvars with credentials
642
- - Ansible vault passwords in plaintext
643
- - CI/CD pipeline secrets in yaml files (.github/workflows, .gitlab-ci.yml)
644
-
645
- **SECRETS IN GIT HISTORY** (CRITICAL CHECK!):
646
- Run these commands to check if secrets were EVER committed:
647
- ```bash
648
- git log --all --full-history -- "**/secrets*" "**/credentials*" "**/*.env"
649
- git log --all -p -S "AWS_SECRET" -S "PRIVATE_KEY" --source
650
- ```
651
- If secrets appear in history, they are EXPOSED even if now gitignored!
652
-
653
- **PRIVILEGE ESCALATION RISKS**:
654
- - Containers/processes running as root
655
- - Missing securityContext in K8s (runAsNonRoot, readOnlyRootFilesystem)
656
- - Privileged containers
657
- - Host path mounts to sensitive directories
658
- - Missing capability drops (drop: ALL)
659
- - Service accounts with excessive permissions
660
-
661
- **CONFIGURATION THAT SHOULD FAIL AT STARTUP**:
662
- - Required environment variables not validated at startup
663
- - Missing config = silent fallback to insecure defaults
664
- - No validation of secret strength/format at startup
665
-
666
- **DEPENDENCY SECURITY** (HIGH if missing):
667
- Check for presence of:
668
- - `npm audit` or `yarn audit` in CI pipeline
669
- - Dependabot/Renovate configuration (.github/dependabot.yml, renovate.json)
670
- - SBOM generation (cyclonedx, syft)
671
- - Snyk/Trivy/Grype scanning
672
- Report as HIGH if NONE of these exist - supply chain risk!
673
-
674
- **LOGGING & MONITORING**:
675
- - Log rotation configured? (maxFiles, maxsize in Winston/Pino)
676
- - Log retention policy defined?
677
- - Sensitive data redacted from logs?
678
- Report as LOW if log rotation missing - disk exhaustion risk.
679
-
680
- For EACH finding, output the FULL JSON format.
681
-
682
- ---
683
-
684
- ### AGENT 5: Data & Privacy Scanner (ID prefix: DATA)
685
-
686
- Scan {{PROJECT_PATH}} for data protection and privacy issues.
687
-
688
- CHECK FOR:
689
- - PII logging (emails, IPs, names in logs)
690
- - GDPR deletion bugs (incomplete data removal)
691
- - Encryption at rest missing for sensitive fields
692
- - Data residency violations
693
- - Backup encryption missing
694
- - Sensitive data in URLs/query params
695
- - Missing data classification
696
- - Retention policy not enforced
697
- - Export functionality exposing too much data
698
- - Cross-tenant data leakage
699
-
700
- For EACH finding, output the FULL JSON format.
701
-
702
- ---
703
-
704
- ### AGENT 6: AI/LLM Security Scanner (ID prefix: AI)
705
-
706
- **CONDITIONAL AGENT** - First detect if this project uses AI/LLM:
707
-
708
- ```bash
709
- # Search for AI/LLM indicators
710
- grep -r -l "openai\|anthropic\|langchain\|ollama\|huggingface\|llama\|gpt-\|claude\|gemini\|bedrock\|vertex" --include="*.ts" --include="*.js" --include="*.py" --include="*.json" .
711
- ```
712
-
713
- **IF NO AI CODE FOUND**: Output and skip:
714
- ```json
715
- {"skipped": true, "reason": "No AI/LLM code detected in project", "findings": []}
716
- ```
717
-
718
- **IF AI CODE FOUND**: Scan {{PROJECT_PATH}} for AI/LLM specific vulnerabilities.
719
-
720
- CHECK FOR:
721
- - Prompt injection (user input directly in prompts)
722
- - Content filter fail-open (errors bypass safety)
723
- - CDN imports without SRI (integrity hashes missing)
724
- - Model output not sanitized before use
725
- - Sensitive data sent to external AI APIs
726
- - AI decision logging insufficient for audit
727
- - Rate limiting on AI endpoints
728
- - Cost controls missing
729
- - Jailbreak prevention missing
730
- - PII in training data/prompts
731
-
732
- **LLM OUTPUT → CODE EXECUTION CHAINS**:
733
- - LLM generates SQL that gets executed (SQL injection via prompt injection)
734
- - LLM generates code that gets eval'd
735
- - LLM generates shell commands that get executed
736
- - LLM generates file paths that get accessed
737
- - LLM output used in template rendering (SSTI)
738
-
739
- **VALIDATION OF LLM OUTPUT**:
740
- - Is there ANY validation between LLM output and dangerous operations?
741
- - Are blocklists/allowlists applied to LLM-generated content?
742
- - Can the blocklist be bypassed? (check for completeness)
743
- - Is validation case-insensitive?
744
- - Does validation handle encoded input?
745
-
746
- **PROMPT SANITIZATION WEAKNESSES**:
747
- - Regex-based filtering (easily bypassed with synonyms, encoding, whitespace)
748
- - Literal string matching (bypass with Unicode homoglyphs)
749
- - Missing: base64 encoded payloads, ROT13, leetspeak variations
750
-
751
- For EACH finding, output the FULL JSON format.
752
-
753
- ---
754
-
755
- ### AGENT 7: Performance & DoS Scanner (ID prefix: PERF)
756
-
757
- Scan {{PROJECT_PATH}} for performance and denial-of-service issues.
758
-
759
- CHECK FOR:
760
- - N+1 query patterns
761
- - ReDoS (regex denial of service)
762
- - Memory leaks (event listeners not removed, growing caches)
763
- - Unbounded data structures
764
- - Missing pagination
765
- - SSE/WebSocket buffering entire streams
766
- - Heavy computation blocking event loop
767
- - Missing connection pooling
768
- - Resource exhaustion (no limits on uploads, requests)
769
- - Synchronous operations that should be async
770
-
771
- **DANGEROUS DATABASE OPERATIONS IN HOT PATHS**:
772
- - Redis KEYS command (blocks entire server, O(n) scan)
773
- - MongoDB find() without limit
774
- - SQL SELECT without LIMIT on large tables
775
- - Full table scans in request handlers
776
- - Aggregations without indexes
777
-
778
- **BLOCKING OPERATIONS**:
779
- - Synchronous file I/O in request handlers
780
- - crypto.pbkdf2Sync / crypto.scryptSync in hot paths
781
- - JSON.parse on unbounded input
782
- - Regex on user input without timeout
783
- - DNS lookups without caching
784
-
785
- For EACH finding, output the FULL JSON format.
786
-
787
- ---
788
-
789
- ### AGENT 8: Business Logic Scanner (ID prefix: BIZ)
790
-
791
- Scan {{PROJECT_PATH}} for business logic vulnerabilities.
792
-
793
- CHECK FOR:
794
- - Race conditions (TOCTOU, double-spend)
795
- - Workflow bypass (skipping required steps)
796
- - Price/quantity manipulation
797
- - Negative value attacks
798
- - State machine violations
799
- - Time-based attacks (timing side channels)
800
- - Non-constant-time comparisons for secrets
801
- - Duplicate request handling (missing idempotency)
802
- - Business rule bypass
803
- - Inconsistent validation between client/server
804
-
805
- For EACH finding, output the FULL JSON format.
806
-
807
- ---
808
-
809
- ### AGENT 9: Code Quality Scanner (ID prefix: QUAL)
810
-
811
- Scan {{PROJECT_PATH}} for code quality issues that affect security/reliability.
812
-
813
- CHECK FOR:
814
- - Error handling swallowing exceptions silently
815
- - Missing error boundaries
816
- - Inconsistent error responses
817
- - Dead code with security implications
818
- - DRY violations in security code
819
- - Complex functions (high cyclomatic complexity)
820
- - Any/unknown types masking issues
821
- - Missing null checks
822
- - Callback hell making auditing hard
823
- - Anti-patterns (god objects, tight coupling)
824
-
825
- **DEAD CODE WITH SECURITY IMPLICATIONS** (CRITICAL):
826
- - Old/commented code that has BETTER security than current code
827
- - Deprecated functions with security controls not ported to replacement
828
- - Legacy validation code that was more thorough
829
- - Backup implementations with different (better) security model
830
- - TODO/FIXME comments about security issues never addressed
831
-
832
- Look for patterns:
833
- - `// OLD: validated input here` followed by code that doesn't
834
- - Functions named `*_secure`, `*_safe`, `*_v2` that are unused
835
- - Commented-out security checks with no explanation
836
- - Multiple implementations where one is more secure but unused
837
-
838
- **SECURITY-CRITICAL CODE WITHOUT TESTS**:
839
- - Authentication/authorization code with 0% test coverage
840
- - Input validation functions without unit tests
841
- - Cryptographic operations without test vectors
842
- - Rate limiting logic without integration tests
843
-
844
- For EACH finding, output the FULL JSON format.
845
-
846
- ---
847
-
848
- ### AGENT 10: Testing & Reliability Scanner (ID prefix: TEST)
849
-
850
- Scan {{PROJECT_PATH}} for testing and reliability gaps.
851
-
852
- CHECK FOR:
853
- - Missing tests for security-critical paths
854
- - No CI quality gates
855
- - Missing health checks
856
- - No graceful shutdown handling
857
- - Circuit breakers missing
858
- - Retry logic without exponential backoff
859
- - Missing observability (logging, metrics, tracing)
860
- - Feature flags without cleanup
861
- - Database migrations without rollback
862
- - No chaos/failure testing evidence
863
-
864
- For EACH finding, output the FULL JSON format.
865
-
866
- ---
867
-
868
- ### AGENT 11: Redis & Cache Security Scanner (ID prefix: REDIS)
869
-
870
- **CONDITIONAL AGENT** - First detect if this project uses Redis/Cache:
871
-
872
- ```bash
873
- # Search for Redis/Cache indicators
874
- grep -r -l "redis\|ioredis\|memcached\|node-cache\|lru-cache\|cache-manager" --include="*.ts" --include="*.js" --include="*.json" --include="*.yaml" .
875
- ```
876
-
877
- **IF NO CACHE CODE FOUND**: Output and skip:
878
- ```json
879
- {"skipped": true, "reason": "No Redis/Cache code detected in project", "findings": []}
880
- ```
881
-
882
- **IF CACHE CODE FOUND**: Scan {{PROJECT_PATH}} for Redis, Memcached, and cache-related security issues.
883
-
884
- **REDIS SECURITY:**
885
-
886
- **DANGEROUS COMMANDS:**
887
- - `KEYS *` in production code (blocks entire server, use SCAN instead)
888
- - `FLUSHALL`, `FLUSHDB` accessible without protection
889
- - `DEBUG`, `CONFIG` commands enabled in production
890
- - `EVAL`/`EVALSHA` with user-controlled scripts (Lua injection)
891
- - `MIGRATE` command enabled (data exfiltration risk)
892
-
893
- **AUTHENTICATION & ACCESS:**
894
- - Redis without AUTH (requirepass not set)
895
- - Redis exposed on 0.0.0.0 instead of 127.0.0.1
896
- - Missing ACL configuration (Redis 6+)
897
- - Default port 6379 exposed externally
898
- - Missing TLS for Redis connections
899
- - Connection strings with passwords in code/logs
900
-
901
- **DATA SECURITY:**
902
- - Sensitive data stored without encryption
903
- - PII in Redis without TTL (data retention violation)
904
- - Session data without proper expiration
905
- - Cache keys predictable/enumerable (info disclosure)
906
- - No key prefix separation between tenants (multi-tenant leak)
907
-
908
- **RACE CONDITIONS:**
909
- - Non-atomic read-modify-write patterns
910
- - Missing WATCH/MULTI/EXEC for transactions
911
- - INCR + EXPIRE not atomic (use SET with NX and EX)
912
- - Distributed locks without proper implementation (SETNX issues)
913
-
914
- **MEMORY & DoS:**
915
- - No maxmemory configuration
916
- - No eviction policy (maxmemory-policy)
917
- - Unbounded lists/sets that can grow infinitely
918
- - Missing key expiration (TTL) for temporary data
919
- - Pub/Sub without subscriber limits
920
-
921
- **SERIALIZATION:**
922
- - Pickle/Marshal deserialization from Redis (RCE risk)
923
- - JSON parsing without validation
924
- - Protobuf/MessagePack without schema validation
925
-
926
- Example finding:
927
- ```json
928
- {
929
- "id": "REDIS-001",
930
- "title": "Redis KEYS command used in production",
931
- "severity": "high",
932
- "fixOwner": "developer",
933
- "fixType": "code",
934
- "file": "src/cache/redis.ts",
935
- "line": 45,
936
- "code": "await redis.keys('user:*')",
937
- "description": "KEYS command blocks the entire Redis server. With large datasets this can cause seconds of downtime.",
938
- "recommendation": "Use SCAN with cursor-based iteration instead: `for await (const key of redis.scanIterator({ MATCH: 'user:*' }))`"
939
- }
940
- ```
941
-
942
- For EACH finding, output the FULL JSON format.
943
-
944
- ---
945
-
946
- ### AGENT 12: Resilience & Fallback Scanner (ID prefix: RESIL)
947
-
948
- Scan {{PROJECT_PATH}} for resilience patterns and fallback mechanisms.
949
-
950
- **CIRCUIT BREAKERS:**
951
- - External service calls without circuit breaker
952
- - Circuit breaker without proper thresholds
953
- - No fallback when circuit is open
954
- - Missing health check for circuit recovery
955
- - Circuit breaker state not monitored/alerted
956
-
957
- **RETRY PATTERNS:**
958
- - Retries without exponential backoff
959
- - Retries without jitter (thundering herd)
960
- - Retries without max attempts limit
961
- - Retrying non-idempotent operations
962
- - No retry budget (retry storms)
963
-
964
- **TIMEOUTS:**
965
- - HTTP calls without timeout
966
- - Database queries without timeout
967
- - External API calls without timeout
968
- - Cascading timeouts not configured properly
969
- - Timeout longer than upstream caller's timeout
970
-
971
- **FALLBACKS:**
972
- - No fallback for critical external dependencies
973
- - Fallback that calls same failing service
974
- - Missing cached fallback data
975
- - No degraded mode implementation
976
- - Feature flags without fallback behavior
977
-
978
- **BULKHEADS:**
979
- - Single connection pool for all operations
980
- - No isolation between critical and non-critical paths
981
- - Thread/worker pool exhaustion possible
982
- - No request queuing limits
983
- - Missing backpressure handling
984
-
985
- **GRACEFUL DEGRADATION:**
986
- - All-or-nothing service behavior
987
- - No partial response capability
988
- - Missing feature flags for degradation
989
- - No read-only mode fallback
990
- - Essential vs non-essential features not separated
991
-
992
- **HEALTH CHECKS:**
993
- - Health check that calls external dependencies
994
- - No distinction between liveness and readiness
995
- - Health check timeout too short/long
996
- - Missing dependency health in readiness check
997
- - Health endpoint exposed without rate limiting
998
-
999
- Example finding:
1000
- ```json
1001
- {
1002
- "id": "RESIL-001",
1003
- "title": "External API call without circuit breaker",
1004
- "severity": "medium",
1005
- "fixOwner": "developer",
1006
- "fixType": "code",
1007
- "file": "src/services/payment.ts",
1008
- "line": 78,
1009
- "code": "await axios.post(paymentApi, data)",
1010
- "description": "Payment API calls have no circuit breaker. If the API is slow/down, requests will pile up and exhaust resources.",
1011
- "recommendation": "Wrap with circuit breaker: `const result = await circuitBreaker.fire(() => axios.post(...))`"
1012
- }
1013
- ```
1014
-
1015
- For EACH finding, output the FULL JSON format.
1016
-
1017
- ---
1018
-
1019
- ### AGENT 13: PII & Sensitive Data Scanner (ID prefix: PII)
1020
-
1021
- Scan {{PROJECT_PATH}} for PII exposure and sensitive data handling issues.
1022
-
1023
- **PII IN LOGS:**
1024
- - Email addresses logged
1025
- - Phone numbers logged
1026
- - IP addresses logged without justification
1027
- - Names/addresses in logs
1028
- - User IDs that can be linked to PII
1029
- - Request/response bodies logged without redaction
1030
- - Error messages containing PII
1031
-
1032
- **PII IN URLS:**
1033
- - PII in URL path (e.g., /user/john@email.com)
1034
- - PII in query parameters
1035
- - Session tokens in URLs (referer leak)
1036
- - Sensitive data in URL fragments
1037
-
1038
- **PII IN STORAGE:**
1039
- - PII stored without encryption at rest
1040
- - PII in plaintext in database
1041
- - PII in local storage/session storage (browser)
1042
- - PII in cookies without encryption
1043
- - Backup data containing unencrypted PII
1044
-
1045
- **PII IN TRANSIT:**
1046
- - PII sent over non-HTTPS connections
1047
- - PII in WebSocket without TLS
1048
- - PII in email notifications (plaintext)
1049
- - PII passed to third-party services without DPA
1050
-
1051
- **PII RETENTION:**
1052
- - No TTL on PII data
1053
- - No data deletion mechanism
1054
- - Soft delete keeping PII accessible
1055
- - Audit logs retaining PII indefinitely
1056
- - Analytics containing raw PII
1057
-
1058
- **GDPR/CCPA COMPLIANCE:**
1059
- - No data export functionality
1060
- - No data deletion on request
1061
- - Missing consent tracking
1062
- - No purpose limitation enforcement
1063
- - PII shared without consent
1064
-
1065
- **SENSITIVE DATA TYPES TO FIND:**
1066
- - SSN, passport numbers, national IDs
1067
- - Credit card numbers (even partial)
1068
- - Bank account numbers
1069
- - Health/medical information
1070
- - Biometric data
1071
- - Location data (precise GPS)
1072
- - Authentication credentials
1073
- - API keys/tokens
1074
-
1075
- **DETECTION PATTERNS:**
1076
- ```
1077
- email: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/
1078
- phone: /(\+\d{1,3}[-.\s]?)?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}/
1079
- ssn: /\d{3}[-]?\d{2}[-]?\d{4}/
1080
- credit_card: /\d{4}[-\s]?\d{4}[-\s]?\d{4}[-\s]?\d{4}/
1081
- ip_address: /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/
1082
- ```
1083
-
1084
- For EACH finding, output the FULL JSON format.
1085
-
1086
- ---
1087
-
1088
- ### AGENT 14: Dead Code & Unused Scanner (ID prefix: DEAD)
1089
-
1090
- Scan {{PROJECT_PATH}} for dead code, unused dependencies, and technical debt.
1091
-
1092
- **UNUSED CODE:**
1093
- - Functions never called
1094
- - Classes never instantiated
1095
- - Variables assigned but never read
1096
- - Exported functions with no importers
1097
- - Event handlers never triggered
1098
- - API endpoints not used by any client
1099
-
1100
- **COMMENTED CODE:**
1101
- - Large blocks of commented-out code
1102
- - TODO/FIXME comments older than 6 months
1103
- - "Temporary" code that became permanent
1104
- - Debug code left in production
1105
- - Console.log/print statements
1106
-
1107
- **UNUSED DEPENDENCIES:**
1108
- - npm/pip packages installed but never imported
1109
- - Devdependencies in production bundle
1110
- - Duplicate dependencies (different versions)
1111
- - Dependencies imported but functions not used
1112
- - Polyfills for supported browser versions
1113
-
1114
- **UNREACHABLE CODE:**
1115
- - Code after return/throw/break
1116
- - Conditions that are always true/false
1117
- - Switch cases that can never match
1118
- - Error handlers that can never trigger
1119
- - Feature flags that are always on/off
1120
-
1121
- **DEAD FEATURE FLAGS:**
1122
- - Feature flags that are always enabled (remove flag)
1123
- - Feature flags that are always disabled (remove code)
1124
- - Feature flags with no owner
1125
- - A/B tests that concluded but weren't cleaned up
1126
-
1127
- **DEPRECATED PATTERNS:**
1128
- - Using deprecated APIs (with console warnings)
1129
- - Legacy code paths kept "just in case"
1130
- - Backward compatibility code for old versions
1131
- - Shims for removed features
1132
-
1133
- **SECURITY IMPLICATIONS:**
1134
- - Commented security checks (why removed?)
1135
- - Unused auth middleware (was security removed?)
1136
- - Dead validation code (security regression?)
1137
- - Unused rate limiting (intentional removal?)
1138
-
1139
- **TECHNICAL DEBT INDICATORS:**
1140
- - Files not modified in >2 years
1141
- - Code with "hack", "workaround", "temporary" comments
1142
- - Duplicate implementations of same logic
1143
- - Copy-pasted code blocks
1144
-
1145
- Example finding:
1146
- ```json
1147
- {
1148
- "id": "DEAD-001",
1149
- "title": "Unused npm dependency: lodash",
1150
- "severity": "low",
1151
- "fixOwner": "developer",
1152
- "fixType": "code",
1153
- "file": "package.json",
1154
- "line": 15,
1155
- "description": "lodash is listed as dependency but no imports found in codebase. Increases bundle size and potential security surface.",
1156
- "recommendation": "Remove with: npm uninstall lodash"
1157
- }
1158
- ```
1159
-
1160
- For EACH finding, output the FULL JSON format.
1161
-
1162
- ---
1163
-
1164
- ### AGENT 15: Database Security Scanner (ID prefix: DB)
1165
-
1166
- **AUTO-DETECT DATABASE TYPE(S)** - First identify which database(s) this project uses:
1167
-
1168
- | Database | Detection Pattern |
1169
- |----------|-------------------|
1170
- | PostgreSQL | `pg`, `postgres`, `@prisma`, `typeorm`, `knex`, `DATABASE_URL.*postgres` |
1171
- | MySQL | `mysql`, `mysql2`, `mariadb` |
1172
- | SQLite | `sqlite`, `better-sqlite3`, `sql.js` |
1173
- | MongoDB | `mongoose`, `mongodb`, `@mongo` |
1174
- | DynamoDB | `@aws-sdk/client-dynamodb`, `dynamodb`, `DocumentClient` |
1175
- | Redis | `redis`, `ioredis` |
1176
- | Elasticsearch | `@elastic`, `elasticsearch` |
1177
- | DuckDB | `duckdb`, `@duckdb` |
1178
- | Supabase | `@supabase/supabase-js`, `supabase`, `createClient.*supabase` |
1179
- | Prisma | `@prisma/client` |
1180
- | TypeORM | `typeorm`, `@Entity` |
1181
- | Sequelize | `sequelize` |
1182
- | Drizzle | `drizzle-orm` |
1183
- | PlanetScale | `@planetscale`, `planetscale` |
1184
- | Neon | `@neondatabase`, `neon` |
1185
- | Turso | `@libsql`, `turso` |
1186
-
1187
- **IF NO DATABASE FOUND**: Output and skip:
1188
- ```json
1189
- {"skipped": true, "reason": "No database code detected in project", "findings": []}
1190
- ```
1191
-
1192
- **IF DATABASE FOUND**: Scan for issues SPECIFIC to the detected database type(s).
1193
-
1194
- Scan {{PROJECT_PATH}} for database security issues across all database types.
1195
-
1196
- **SQL INJECTION (all SQL databases):**
1197
- - String concatenation in queries
1198
- - Template literals with user input in SQL
1199
- - Raw queries without parameterization
1200
- - Dynamic table/column names from user input
1201
- - ORDER BY with user-controlled column names
1202
- - LIMIT/OFFSET from unvalidated user input
1203
-
1204
- **NOSQL INJECTION:**
1205
- - MongoDB: $where with user input
1206
- - MongoDB: $regex with user-controlled patterns
1207
- - MongoDB: operator injection ({$gt: ""})
1208
- - DynamoDB: condition expressions with user input
1209
- - Elasticsearch: query string queries with user input
1210
-
1211
- **DANGEROUS DATABASE FUNCTIONS:**
1212
- ```
1213
- PostgreSQL: pg_read_file(), pg_ls_dir(), COPY TO/FROM, lo_import/export
1214
- MySQL: LOAD_FILE(), INTO OUTFILE, INTO DUMPFILE, LOAD DATA
1215
- SQLite: load_extension(), readfile(), writefile()
1216
- DuckDB: read_text(), read_blob(), read_csv_auto(), read_parquet(), glob(), httpfs
1217
- MongoDB: $where, mapReduce with user functions
1218
- Redis: EVAL with user scripts, CONFIG, DEBUG
1219
- ```
1220
-
1221
- **ACCESS CONTROL:**
1222
- - Database user with excessive privileges (GRANT ALL)
1223
- - Application using root/admin database user
1224
- - Same credentials for read and write operations
1225
- - No row-level security (RLS) for multi-tenant
1226
- - Missing column-level encryption for sensitive data
1227
-
1228
- **CONNECTION SECURITY:**
1229
- - Database connection without TLS/SSL
1230
- - Connection strings with credentials in code
1231
- - Connection pooling without limits
1232
- - No connection timeout configured
1233
- - Database exposed on public IP
1234
-
1235
- **QUERY PATTERNS:**
1236
- - SELECT * instead of specific columns
1237
- - No LIMIT on SELECT queries
1238
- - Missing indexes on filtered columns
1239
- - N+1 query patterns
1240
- - Full table scans in request handlers
1241
- - Unbounded JOINs
1242
-
1243
- **MIGRATIONS & SCHEMA:**
1244
- - Migrations without rollback capability
1245
- - Schema changes without backup
1246
- - Dropping columns with data
1247
- - Changing column types without data migration
1248
- - Foreign keys without ON DELETE policy
1249
-
1250
- **DATA INTEGRITY:**
1251
- - Missing foreign key constraints
1252
- - No unique constraints where needed
1253
- - Missing NOT NULL on required fields
1254
- - No CHECK constraints for data validation
1255
- - Orphan records possible
1256
-
1257
- **BACKUP & RECOVERY:**
1258
- - No backup configuration found
1259
- - Backups not encrypted
1260
- - No point-in-time recovery capability
1261
- - Backup credentials in code
1262
- - No backup verification/testing
1263
-
1264
- **ORM SPECIFIC:**
1265
- ```javascript
1266
- // Prisma - raw queries
1267
- prisma.$queryRaw`SELECT * FROM users WHERE id = ${userId}` // SAFE
1268
- prisma.$queryRawUnsafe(`SELECT * FROM users WHERE id = ${userId}`) // VULNERABLE
1269
-
1270
- // Sequelize - raw queries
1271
- sequelize.query(`SELECT * FROM ${table}`) // VULNERABLE if table is user input
1272
-
1273
- // TypeORM - raw queries
1274
- repository.query(`SELECT * FROM users WHERE name = '${name}'`) // VULNERABLE
1275
-
1276
- // Mongoose - operator injection
1277
- User.find({ username: req.body.username }) // VULNERABLE to {$gt: ""}
1278
- ```
1279
-
1280
- **AUDIT & LOGGING:**
1281
- - No audit logging for sensitive operations
1282
- - Query logging including sensitive data
1283
- - No tracking of who accessed what data
1284
- - Missing created_at/updated_at timestamps
1285
- - No soft delete (audit trail lost)
1286
-
1287
- Example finding:
1288
- ```json
1289
- {
1290
- "id": "DB-001",
1291
- "title": "SQL injection via string concatenation",
1292
- "severity": "critical",
1293
- "fixOwner": "developer",
1294
- "fixType": "code",
1295
- "file": "src/repositories/user.ts",
1296
- "line": 34,
1297
- "code": "db.query(`SELECT * FROM users WHERE id = ${userId}`)",
1298
- "description": "User ID is concatenated directly into SQL query, allowing SQL injection attacks.",
1299
- "recommendation": "Use parameterized query: db.query('SELECT * FROM users WHERE id = $1', [userId])"
1300
- }
1301
- ```
1302
-
1303
- For EACH finding, output the FULL JSON format.
1304
-
1305
- ---
1306
-
1307
- ### AGENT 16: Network & Architecture Scanner (ID prefix: ARCH)
1308
-
1309
- Scan {{PROJECT_PATH}} for network architecture and service boundary issues.
1310
-
1311
- **CRITICAL DISTINCTION - Code vs Infrastructure fixes:**
1312
-
1313
- For EACH finding, determine:
1314
- - Is this fixable by changing CODE? → fixOwner: "developer"
1315
- - Is this fixable by NetworkPolicy/firewall/K8s config? → fixOwner: "devops"
1316
- - Does this need architecture redesign? → fixOwner: "architect"
1317
-
1318
- CHECK FOR:
1319
-
1320
- **SERVICE BOUNDARIES:**
1321
- - Internal endpoints exposed externally (should be internal-only)
1322
- - Missing network segmentation between services
1323
- - Service-to-service communication without mTLS
1324
- - Internal IPs hardcoded instead of service discovery
1325
- - Admin/debug ports accessible from outside
1326
-
1327
- **TRUST BOUNDARIES:**
1328
- - Which endpoints are meant to be internal-only?
1329
- - Are internal endpoints protected by network policy OR code auth?
1330
- - Document the INTENDED architecture, not just what's missing
1331
-
1332
- **KUBERNETES/INFRASTRUCTURE:**
1333
- - Missing NetworkPolicies for namespace isolation
1334
- - Services using ClusterIP that should be internal
1335
- - LoadBalancer exposing internal services
1336
- - Missing Ingress rules for path-based routing
1337
- - Pod-to-pod communication without restrictions
1338
-
1339
- **FOR EACH FINDING, specify:**
1340
- ```json
1341
- {
1342
- "fixOwner": "devops",
1343
- "fixType": "infrastructure",
1344
- "recommendation": "Add NetworkPolicy to restrict /api/v1/internal/* to enclave namespace only",
1345
- "notCodeFix": true
1346
- }
1347
- ```
1348
-
1349
- If you find an endpoint that lacks authentication but is INTENDED to be protected by network policy:
1350
- - Mark as fixOwner: "devops", NOT "developer"
1351
- - Recommendation should be NetworkPolicy, NOT code auth
1352
- - Add note: "Protected by network segmentation - verify NetworkPolicy exists"
1353
-
1354
- For EACH finding, output the FULL JSON format.
1355
-
1356
- ---
1357
-
1358
- ### AGENT 17: Design Decision Detector (ID prefix: DESIGN)
1359
-
1360
- Scan {{PROJECT_PATH}} for intentional design decisions that might look like bugs.
1361
-
1362
- **GOAL: Prevent false positives by identifying documented/intentional patterns**
1363
-
1364
- CHECK FOR:
1365
-
1366
- **DOCUMENTED DECISIONS:**
1367
- - Comments explaining WHY something is done a certain way
1368
- - README/docs explaining architecture choices
1369
- - ADR (Architecture Decision Records) files
1370
- - SECURITY.md or similar documentation
1371
-
1372
- **INTENTIONAL PATTERNS:**
1373
- - Content filtering disabled with comment "for transparency"
1374
- - Auth bypassed for specific endpoints with documentation
1375
- - Longer session timeouts with business justification
1376
- - Relaxed validation with explicit reason
1377
-
1378
- **CODE PATTERNS THAT ARE NOT BUGS:**
1379
- - `// Intentional: ....` or `// Design decision: ...`
1380
- - `// SECURITY: This is safe because...`
1381
- - `// TODO: This is acceptable for now because...`
1382
- - Feature flags controlling security features with documentation
1383
-
1384
- **FOR EACH PATTERN FOUND, output:**
1385
- ```json
1386
- {
1387
- "id": "DESIGN-001",
1388
- "type": "documented_decision",
1389
- "title": "Content filtering disabled",
1390
- "file": "src/ai/chat.ts",
1391
- "line": 45,
1392
- "reason": "Documented in code comment: 'Disabled for transparency, users see raw AI output'",
1393
- "relatedFindings": ["AI-001"],
1394
- "recommendation": "Not a bug - document in security overview as accepted risk"
1395
- }
1396
- ```
1397
-
1398
- These findings will be EXCLUDED from the main report and moved to "Design Decisions" section.
1399
-
1400
- ---
1401
-
1402
- ### AGENT 18: Context-Aware Validator (ID prefix: CTX)
1403
-
1404
- Scan {{PROJECT_PATH}} to understand the CONTEXT of each potential finding.
1405
-
1406
- **GOAL: Reduce false positives by understanding deployment context**
1407
-
1408
- FOR EACH FINDING FROM OTHER AGENTS, determine:
1409
-
1410
- **DEPLOYMENT CONTEXT:**
1411
- - Is this code running in a container with network isolation?
1412
- - Is this behind an API gateway that handles auth?
1413
- - Is this internal-only service behind VPN?
1414
- - Is there a WAF/CDN in front that mitigates this?
1415
-
1416
- **RUNTIME CONTEXT:**
1417
- - Is this code path actually reachable in production?
1418
- - Is this only used in development/testing?
1419
- - Is this dead code or deprecated?
1420
- - Is this protected by feature flag that's disabled?
1421
-
1422
- **DATA FLOW CONTEXT:**
1423
- - Is the input already validated upstream?
1424
- - Is the output sanitized downstream?
1425
- - Is there middleware that applies to this route?
1426
-
1427
- **OUTPUT:**
1428
- ```json
1429
- {
1430
- "findingId": "SEC-001",
1431
- "contextAnalysis": {
1432
- "deploymentContext": "Runs in K8s with NetworkPolicy restricting access",
1433
- "runtimeContext": "Only reachable from internal services",
1434
- "dataFlowContext": "Input validated by Zod at API gateway level",
1435
- "verdict": "false_positive|confirmed|needs_review",
1436
- "reason": "Protected by network policy - not externally accessible"
1437
- }
1438
- }
1439
- ```
1440
-
1441
- ---
1442
-
1443
- ### AGENT 19: Enclave & Trusted Compute Scanner (ID prefix: ENC)
1444
-
1445
- **CONDITIONAL AGENT** - First detect if this project uses enclaves/TEE:
1446
-
1447
- ```bash
1448
- # Search for enclave/TEE indicators
1449
- grep -r -l "enclave\|nitro\|sgx\|tee\|attestation\|trusted.compute\|confidential.computing\|vsock" --include="*.ts" --include="*.js" --include="*.py" --include="*.yaml" --include="*.yml" .
1450
- ```
1451
-
1452
- **IF NO ENCLAVE CODE FOUND**: Output and skip:
1453
- ```json
1454
- {"skipped": true, "reason": "No enclave/TEE code detected in project", "findings": []}
1455
- ```
1456
-
1457
- **IF ENCLAVE CODE FOUND**: Scan {{PROJECT_PATH}} for enclave/TEE/trusted compute specific patterns.
1458
-
1459
- CHECK FOR:
1460
-
1461
- **ENCLAVE REGISTRATION:**
1462
- - Enclave-to-backend registration without attestation
1463
- - IP-based trust without cryptographic verification
1464
- - Missing remote attestation flow
1465
- - Enclave secrets transmitted without encryption
1466
-
1467
- **TRUST MODEL:**
1468
- - What is the trust boundary between enclave and host?
1469
- - Is the communication channel authenticated?
1470
- - Are enclave outputs verified?
1471
-
1472
- **SPECIFIC PATTERNS:**
1473
- - /register endpoints for enclave → backend (common pattern)
1474
- - Heartbeat/health endpoints from enclave
1475
- - Configuration push to enclave
1476
-
1477
- **FOR ENCLAVE ENDPOINTS, determine:**
1478
- - Is this MEANT to be protected by network only? → Note in finding
1479
- - Is attestation planned but not implemented? → Check TODOs/roadmap
1480
- - Is this MVP/temporary solution? → Check for documentation
1481
-
1482
- Output findings with proper fixOwner:
1483
- - Network protection needed → fixOwner: "devops"
1484
- - Attestation needed → fixOwner: "architect" (design change)
1485
- - Code validation needed → fixOwner: "developer"
1486
-
1487
- ---
1488
-
1489
- ### AGENT 20: Executive Summary Generator (ID prefix: EXEC)
1490
-
1491
- After all other agents complete, generate an executive summary **written for leadership** — technically precise but accessible.
1492
-
1493
- **WRITING GUIDELINES:**
1494
- - The `overview` field should read like a professional security consultant's opening paragraph
1495
- - Start with 1 sentence describing what the project IS (architecture, purpose)
1496
- - Then state the overall security posture clearly
1497
- - Then list the most significant remaining issues in one sentence
1498
- - Use specific numbers and technical details, not vague language
1499
-
1500
- **EXAMPLE of professional executive summary overview:**
1501
- "Express-AI Officely is a confidential AI platform built on a three-tier encrypted architecture: a Next.js frontend with BFF pattern, an Express.js API gateway on EKS, and backend enclaves running inside AMD SEV-SNP encrypted VMs. No critical vulnerabilities remain. The most significant remaining issues are: unauthenticated enclave registration endpoints that could allow enclave impersonation (mitigated by network-level whitelisting), hardcoded secrets in Helm values, a monolithic 1000+ line chat handler creating maintenance risk, 3,200 lines of dead or duplicated code (5.3% of the codebase), and zero test coverage across all components."
1502
-
1503
- **TOP RISKS writing quality:**
1504
- Each risk must be a specific, actionable description — not a generic category.
1505
- - BAD: "SQL injection vulnerability"
1506
- - GOOD: "Unauthenticated enclave registration endpoints could allow impersonation (mitigated by network whitelisting)"
1507
- - GOOD: "160 lines of Redis metrics tracking duplicated verbatim between streaming/non-streaming paths"
1508
-
1509
- **OUTPUT FORMAT:**
1510
- ```json
1511
- {
1512
- "executiveSummary": {
1513
- "headline": "0 Critical + 7 High findings — platform hardened but key gaps remain",
1514
- "riskLevel": "HIGH",
1515
- "overview": "Professional 2-3 sentence summary as described above.",
1516
- "topRisks": [
1517
- "Specific risk description with technical detail and context",
1518
- "Another risk with file reference and impact quantification",
1519
- "Third risk with mitigation status noted if partial"
1520
- ],
1521
- "positives": [
1522
- "Specific strength with technical evidence — not generic praise",
1523
- "Another strength citing specific libraries/patterns/algorithms"
1524
- ],
1525
- "recommendedActions": [
1526
- {
1527
- "priority": 1,
1528
- "action": "Remove hardcoded secrets from Helm values. Move to Secrets Manager. Rotate keys immediately.",
1529
- "owner": "devops",
1530
- "effort": "2-4 hours"
1531
- },
1532
- {
1533
- "priority": 2,
1534
- "action": "Add shared-secret or mTLS auth to enclave status/register endpoints",
1535
- "owner": "architect",
1536
- "effort": "1-2 days"
1537
- }
1538
- ],
1539
- "byOwner": {
1540
- "developer": 5,
1541
- "devops": 3,
1542
- "architect": 1
1543
- },
1544
- "priorityRoadmap": {
1545
- "P0_immediate": {
1546
- "description": "Fix this sprint - security critical",
1547
- "findings": ["SEC-001", "AUTH-003"],
1548
- "effort": "1-2 days"
1549
- },
1550
- "P1_short_term": {
1551
- "description": "Fix within 2 weeks - high priority",
1552
- "findings": ["API-002", "INFRA-005"],
1553
- "effort": "3-5 days"
1554
- },
1555
- "P2_medium_term": {
1556
- "description": "Fix within month - important",
1557
- "findings": ["QUAL-001", "DEAD-003"],
1558
- "effort": "1 week"
1559
- },
1560
- "P3_backlog": {
1561
- "description": "Address when capacity allows",
1562
- "findings": ["TEST-001"],
1563
- "effort": "ongoing"
1564
- }
1565
- }
1566
- }
1567
- }
1568
- ```
1569
-
1570
- **Priority Assignment Rules:**
1571
- - **P0 (Immediate)**: CRITICAL severity, actively exploitable, data breach risk
1572
- - **P1 (Short-term)**: HIGH severity, requires auth to exploit, compliance risk
1573
- - **P2 (Medium-term)**: MEDIUM severity, defense-in-depth, code quality
1574
- - **P3 (Backlog)**: LOW/INFO severity, nice-to-have improvements
1575
-
1576
- ---
1577
-
1578
- ### AGENT 22: Runtime Verification Scanner (ID prefix: RUNTIME)
1579
-
1580
- **CONDITIONAL AGENT** - Only runs if SSH is configured in Phase 0.
1581
-
1582
- Check if runtime.json was found in Phase 0:
1583
- - If NO runtime.json → Skip this agent entirely
1584
- - If runtime.json exists → Proceed with runtime verification
1585
-
1586
- **PURPOSE**: Find dangerous mismatches between code configuration and actual runtime environment.
1587
-
1588
- **Example of what this catches:**
1589
- > The code says `USER appuser` in Dockerfile, but the container actually runs as `root`.
1590
- > This is why a DuckDB file read vulnerability could access /etc/passwd!
1591
-
1592
- ---
1593
-
1594
- **STEP 1: Gather Code Expectations**
1595
-
1596
- Analyze configuration files to understand EXPECTED runtime state:
11
+ ### Step 1: Understand the Project
1597
12
 
1598
13
  ```bash
1599
- # Dockerfile
1600
- grep -E "^USER|^EXPOSE|^ENV" Dockerfile 2>/dev/null
14
+ mkdir -p .coverme
1601
15
 
1602
- # Docker Compose
1603
- grep -E "user:|ports:|environment:" docker-compose*.yml 2>/dev/null
1604
-
1605
- # Kubernetes
1606
- grep -E "runAsUser|runAsNonRoot|readOnlyRootFilesystem|securityContext" k8s/*.yaml helm/**/values.yaml 2>/dev/null
1607
-
1608
- # PM2
1609
- grep -E "user|uid|cwd" ecosystem.config.js pm2.config.js 2>/dev/null
16
+ # Project structure
17
+ ls -la
18
+ find . -maxdepth 2 -type d -not -path "*/node_modules/*" -not -path "*/.git/*" -not -path "*/dist/*" 2>/dev/null | head -40
1610
19
 
1611
- # Systemd
1612
- grep -E "^User=|^Group=" *.service 2>/dev/null
1613
- ```
20
+ # Count files
21
+ find . -type f \( -name "*.ts" -o -name "*.js" -o -name "*.tsx" -o -name "*.py" -o -name "*.go" \) -not -path "*/node_modules/*" -not -path "*/.git/*" 2>/dev/null | wc -l
1614
22
 
1615
- Build expected state:
1616
- ```json
1617
- {
1618
- "expected": {
1619
- "user": "appuser",
1620
- "uid": 1000,
1621
- "runAsRoot": false,
1622
- "readOnlyFs": true,
1623
- "ports": [3000],
1624
- "source": "Dockerfile:15 - USER appuser"
1625
- }
1626
- }
23
+ # Tech stack
24
+ cat package.json 2>/dev/null | head -40
1627
25
  ```
1628
26
 
1629
- ---
1630
-
1631
- **STEP 2: SSH and Check Actual Runtime**
1632
-
1633
- Use the SSH configuration from runtime.json:
27
+ ### Step 2: Find Critical Files
1634
28
 
1635
29
  ```bash
1636
- # Build SSH command (from runtime.json)
1637
- # host: user@server.com, port: 22, keyPath: ~/.ssh/id_rsa
1638
-
1639
- # Check who is running the process
1640
- ssh user@server.com "ps -eo user,pid,cmd | grep -E 'node|python|java|pm2' | head -5"
1641
-
1642
- # Check Docker container user
1643
- ssh user@server.com "docker ps -q | head -1 | xargs -I {} docker exec {} id"
1644
-
1645
- # Check Kubernetes pod user
1646
- ssh user@server.com "kubectl get pods -o name | head -1 | xargs -I {} kubectl exec {} -- id"
1647
-
1648
- # Check file permissions
1649
- ssh user@server.com "ls -la /app/ 2>/dev/null | head -10"
1650
-
1651
- # Check listening ports
1652
- ssh user@server.com "ss -tlnp | grep -E ':3000|:8080|:6379'"
1653
- ```
1654
-
1655
- Build actual state:
1656
- ```json
1657
- {
1658
- "actual": {
1659
- "user": "root",
1660
- "uid": 0,
1661
- "runAsRoot": true,
1662
- "readOnlyFs": false,
1663
- "ports": [3000, 6379],
1664
- "evidence": "uid=0(root) gid=0(root)"
1665
- }
1666
- }
1667
- ```
1668
-
1669
- ---
1670
-
1671
- **STEP 3: Compare and Generate Findings**
1672
-
1673
- | Mismatch | Severity | ID |
1674
- |----------|----------|-----|
1675
- | Code says non-root, runs as root | CRITICAL | RUNTIME-001 |
1676
- | Dockerfile USER ignored | CRITICAL | RUNTIME-002 |
1677
- | K8s runAsNonRoot:true but runs as root | HIGH | RUNTIME-003 |
1678
- | ReadOnlyRootFilesystem not enforced | HIGH | RUNTIME-004 |
1679
- | Unexpected ports exposed | MEDIUM | RUNTIME-005 |
1680
- | File permissions too open (777) | MEDIUM | RUNTIME-006 |
1681
- | Environment variables mismatch | LOW | RUNTIME-007 |
1682
-
1683
- **Output Format:**
1684
- ```json
1685
- {
1686
- "id": "RUNTIME-001",
1687
- "title": "Container running as root despite USER directive",
1688
- "severity": "critical",
1689
- "category": "runtime-mismatch",
1690
- "fixOwner": "devops",
1691
- "fixType": "infrastructure",
1692
-
1693
- "expected": {
1694
- "value": "appuser (uid 1000)",
1695
- "source": "Dockerfile:15",
1696
- "code": "USER appuser"
1697
- },
1698
-
1699
- "actual": {
1700
- "value": "root (uid 0)",
1701
- "command": "docker exec container id",
1702
- "evidence": "uid=0(root) gid=0(root)"
1703
- },
1704
-
1705
- "description": "The Dockerfile specifies USER appuser, but the container runs as root. This likely means docker-compose or K8s overrides the user.",
1706
-
1707
- "impact": "Running as root means any code vulnerability can access ALL system files. The DuckDB read_text() issue could read /etc/shadow, SSH keys, or any file on the system.",
1708
-
1709
- "recommendation": "1. Remove user: root from docker-compose.yml\n2. Add securityContext.runAsNonRoot: true to K8s deployment\n3. Verify no --user root in docker run commands",
1710
-
1711
- "verification": {
1712
- "codeFile": "Dockerfile:15",
1713
- "sshCommand": "docker exec container_name id",
1714
- "sshOutput": "uid=0(root) gid=0(root)"
1715
- }
1716
- }
1717
- ```
1718
-
1719
- ---
1720
-
1721
- ## PHASE 2: DUPLICATE & EXISTING SOLUTIONS CHECK
1722
-
1723
- ### AGENT 21: Duplicate & Existing Solutions Scanner (ID prefix: DUP)
1724
-
1725
- CRITICAL: Before recommending ANY fix, check if a solution ALREADY EXISTS in the codebase.
1726
-
1727
- For EVERY finding from Phase 1, search the codebase for:
1728
-
1729
- 1. **Existing utilities/helpers that solve this**:
1730
- - Search for similar function names (sanitize, validate, escape, hash, encrypt)
1731
- - Check utils/, helpers/, lib/, common/ folders
1732
- - Look for imported libraries that handle this
1733
-
1734
- 2. **Existing patterns in the codebase**:
1735
- - How do OTHER files handle the same issue?
1736
- - Is there a project-wide convention?
1737
- - Are there shared middleware/decorators?
1738
-
1739
- 3. **Configuration that already exists**:
1740
- - Check if there's a config for this (CSP headers, CORS, rate limits)
1741
- - Look in config/, .env files, infrastructure code
1742
-
1743
- 4. **Duplicate findings & Cross-References**:
1744
- - Is this the same issue reported multiple times?
1745
- - Are multiple findings actually ONE root cause?
1746
- - **Create CR-xx IDs** when same issue found by multiple agents
1747
-
1748
- **Cross-Reference (CR-xx) Rules:**
1749
- When two or more agents find the SAME underlying issue from different perspectives:
1750
- 1. Create a cross-reference ID: `CR-01`, `CR-02`, etc.
1751
- 2. Merge into single finding with dual ID: `"CR-02 / T-EKS-3"`
1752
- 3. Use the most descriptive title
1753
- 4. Combine descriptions from both perspectives
1754
- 5. Use the higher DREAD score
1755
- 6. Add both original IDs to `crossReferences` array
1756
-
1757
- **Examples of cross-references:**
1758
- - SEC finds "hardcoded API key" + INFRA finds same key in Helm → `CR-01 / SEC-005 / INFRA-003`
1759
- - AUTH finds "missing MFA" + BIZ finds "MFA bypass flow" → Keep separate but add crossReferences
1760
- - QUAL finds "DRY violation" + PERF finds same duplicated code → Merge as `CR-02`
1761
-
1762
- For EACH finding, add to the checkBefore field:
1763
- - "EXISTING: Found sanitizeHtml() in src/utils/security.ts - use this instead of creating new"
1764
- - "PATTERN: Other files use zod.string().email() for validation - follow same pattern"
1765
- - "DUPLICATE: This is same root cause as SEC-003, fix once in middleware"
1766
- - "CONFIG: Rate limiting already configured in src/middleware/rateLimit.ts line 15"
1767
-
1768
- If NO existing solution found, state: "VERIFIED: No existing solution found, new implementation needed"
1769
-
1770
- Output for each finding:
1771
- ```json
1772
- {
1773
- "findingId": "SEC-001",
1774
- "existingSolution": "Found: src/utils/sanitize.ts exports sanitizeUserInput()",
1775
- "duplicateOf": null,
1776
- "crossReferenceId": null,
1777
- "relatedFindings": ["INFRA-003"],
1778
- "suggestedApproach": "Import and use existing sanitizeUserInput() instead of creating new function",
1779
- "checkBefore": "1. Verify sanitizeUserInput() handles this case 2. Check if it's already imported"
1780
- }
1781
- ```
1782
-
1783
- **Cross-Reference output when merging:**
1784
- ```json
1785
- {
1786
- "crossReference": {
1787
- "id": "CR-02",
1788
- "mergedFindings": ["SEC-005", "INFRA-003"],
1789
- "title": "Hardcoded Tracker API Keys in Helm Values and Backend Code",
1790
- "reason": "Same hardcoded key found in both application code and infrastructure config"
1791
- }
1792
- }
1793
- ```
1794
-
1795
- ---
1796
-
1797
- ## PHASE 3: MITIGATION VALIDATION (CRITICAL)
1798
-
1799
- **This phase determines if findings are ACTUALLY exploitable or if other code prevents the attack.**
1800
-
1801
- ### Validator M: Mitigation Hunter
1802
-
1803
- For EVERY finding from Phase 1+2, actively search the codebase for mitigations:
1804
-
1805
- #### Search Checklist:
1806
- 1. **Input Validation** - Is input sanitized before reaching the vulnerable sink?
1807
- ```bash
1808
- grep -r "validate|sanitize|escape|Zod|Joi|yup" src/
1809
- ```
1810
-
1811
- 2. **Middleware Protection** - Is there middleware that protects this route?
1812
- ```bash
1813
- grep -r "app.use|helmet|csrf|rateLimit" src/
1814
- ```
1815
-
1816
- 3. **Framework Auto-Protection** - Does the framework handle this automatically?
1817
- - React JSX auto-escapes (unless dangerouslySetInnerHTML)
1818
- - Prisma/TypeORM parameterize queries automatically
1819
- - Next.js API routes have built-in protections
1820
-
1821
- 4. **Route Protection** - Is the endpoint protected by auth/authorization?
1822
- ```bash
1823
- grep -r "requireAuth|isAdmin|authorize" src/
1824
- ```
1825
-
1826
- 5. **Configuration** - Is there security config that applies?
1827
- - CSP headers blocking XSS
1828
- - CORS restricting origins
1829
- - Rate limiting preventing abuse
1830
-
1831
- #### Output Per Finding:
1832
- ```json
1833
- {
1834
- "findingId": "SEC-001",
1835
- "verdict": "mitigated|partial|confirmed|false_positive",
1836
- "mitigationType": "input_validation|middleware|framework|config|none",
1837
- "evidence": [
1838
- "Found Zod validation at src/routes/user.ts:23",
1839
- "Schema restricts input to alphanumeric only",
1840
- "XSS payload would fail validation"
1841
- ],
1842
- "adjustedSeverity": "low",
1843
- "codeReferences": [
1844
- {"file": "src/middleware/validate.ts", "line": 45}
1845
- ]
1846
- }
1847
- ```
1848
-
1849
- **Verdicts:**
1850
- - `mitigated` - Another control fully prevents the attack → Remove from report or mark as INFO
1851
- - `partial` - Some protection but can be bypassed → Keep but may downgrade severity
1852
- - `confirmed` - No mitigation found → Keep original severity
1853
- - `false_positive` - Finding is incorrect (test file, dead code, etc.) → Remove
1854
-
1855
- ---
1856
-
1857
- ## PHASE 4: CROSS-VALIDATION
1858
-
1859
- Launch 3 validators IN PARALLEL after Phase 3 completes:
1860
-
1861
- ### Validator A: False Positive & Duplicate Hunter
1862
-
1863
- Review ALL findings that passed Phase 3 (not mitigated).
1864
- For each finding determine if it's FALSE POSITIVE or DUPLICATE:
1865
- - Is the code actually reachable?
1866
- - Is the context misunderstood?
1867
- - Is this a DUPLICATE of another finding? (same root cause)
1868
- - Does an EXISTING SOLUTION already exist in the codebase?
1869
-
1870
- If existing solution found, mark as "use_existing" not "fix_new".
30
+ # Auth files
31
+ find . -type f \( -name "*auth*" -o -name "*session*" -o -name "*jwt*" -o -name "*login*" \) -not -path "*/node_modules/*" 2>/dev/null | head -15
1871
32
 
1872
- Output:
1873
- ```json
1874
- {
1875
- "confirmed": ["SEC-001", "AUTH-002"],
1876
- "useExisting": [
1877
- {"id": "SEC-005", "existingSolution": "src/utils/sanitize.ts", "reason": "sanitizeHtml() already exists"}
1878
- ],
1879
- "duplicates": [
1880
- {"id": "SEC-007", "duplicateOf": "SEC-003", "reason": "Same XSS issue, fix once in shared component"}
1881
- ],
1882
- "falsePositives": [
1883
- {"id": "API-003", "reason": "Input is validated by Zod schema at line 45"}
1884
- ]
1885
- }
1886
- ```
1887
-
1888
- ### Validator B: Evidence Challenger
1889
-
1890
- For every HIGH and CRITICAL finding:
1891
- - Read the actual code files
1892
- - Trace complete data flow
1893
- - Verify exploit scenario is realistic
1894
- - Check if exploitable in production context
1895
-
1896
- Output same format as Validator A.
1897
-
1898
- ### Validator C: Missing Issues Hunter
1899
-
1900
- Look for issues Phase 1 agents MISSED:
1901
- - Edge cases
1902
- - Combination attacks
1903
- - Business logic flaws specific to this codebase
1904
- - Configuration issues
1905
- - Integration points
1906
-
1907
- Output:
1908
- ```json
1909
- {
1910
- "missedIssues": [{"full finding object"}]
1911
- }
1912
- ```
33
+ # API routes
34
+ find . -type f \( -name "*route*" -o -name "*controller*" -o -name "*api*" -o -name "*endpoint*" \) -not -path "*/node_modules/*" 2>/dev/null | head -15
1913
35
 
1914
- ---
1915
-
1916
- ## PHASE 5: CROSS-REFERENCE MERGE
1917
-
1918
- Before generating final output, identify findings that describe the same issue from different agent perspectives.
1919
-
1920
- **Merge Process:**
1921
- 1. Compare all findings from Phase 1-4
1922
- 2. If two findings reference the same file+line range OR describe the same root cause:
1923
- - Create a SINGLE finding with dual ID: "CR-02 / T-EKS-3"
1924
- - Use the most descriptive title from either finding
1925
- - Combine description details from both perspectives
1926
- - Use the higher DREAD score
1927
- - Populate `crossReferences` with both original IDs
1928
- 3. If findings are RELATED but NOT identical:
1929
- - Keep as separate findings
1930
- - Add each other's ID to `crossReferences` array
1931
-
1932
- **Examples of cross-referenced findings:**
1933
- - Security agent finds hardcoded key + Infrastructure agent finds same key in Helm values → MERGE
1934
- - Auth agent finds missing MFA + Business logic agent finds MFA bypass → ADD crossReferences
1935
- - Quality agent finds DRY violation in metrics code + Security agent finds same code → MERGE
1936
-
1937
- ---
1938
-
1939
- ## PHASE 6: POSITIVE OBSERVATIONS
36
+ # Security middleware
37
+ find . -type f \( -name "*middleware*" -o -name "*guard*" -o -name "*interceptor*" \) -not -path "*/node_modules/*" 2>/dev/null | head -10
1940
38
 
1941
- Scan for good practices to include in the report. Each positive observation must include **specific technical evidence** — not generic praise.
39
+ # Config and secrets
40
+ find . -type f \( -name "*.env*" -o -name "*secret*" -o -name "*config*" -o -name "*credential*" \) -not -path "*/node_modules/*" 2>/dev/null | head -15
1942
41
 
1943
- **FORMAT for each observation:**
1944
- ```json
1945
- {
1946
- "title": "Descriptive Title — 3-5 words",
1947
- "description": "2-3 sentences of specific technical evidence. Name the specific functions, libraries, patterns, or configurations that demonstrate this strength. Include file references where relevant."
1948
- }
42
+ # Infrastructure
43
+ find . -type f \( -name "Dockerfile*" -o -name "docker-compose*" -o -name "*.yaml" -o -name "*.yml" \) -not -path "*/node_modules/*" 2>/dev/null | head -20
1949
44
  ```
1950
45
 
1951
- **BAD (generic, no evidence):**
1952
- - "Good authentication implementation"
1953
- - "Proper input validation"
1954
- - "Secure coding practices"
1955
-
1956
- **GOOD (specific, with evidence):**
1957
- - {"title": "Zero-Knowledge Architecture", "description": "EKS gateway genuinely never sees plaintext. Encrypted payloads flow through without decryption. Well-enforced across all components."}
1958
- - {"title": "Atomic Credit Operations", "description": "Lua scripts for token burning and balance deduction prevent cross-pod race conditions. Check-and-deduct is atomic."}
1959
- - {"title": "Post-Quantum Cryptography", "description": "XWing (ML-KEM-768 + X25519) hybrid KEM, Ed25519 signing, AES-256-GCM. Key derivation: Argon2id + HKDF with proper alignment across browser/Node.js."}
1960
- - {"title": "Secure File Handling", "description": "MIME + magic number validation, memory-only storage, size limits. secureDeleteFile() overwrites with random data before deletion."}
1961
-
1962
- **CHECK FOR:**
1963
- - Security controls that work well (name the specific middleware, library, or pattern)
1964
- - Authentication/authorization strengths (name the provider, flow, and protections)
1965
- - Input validation patterns (name the library and coverage)
1966
- - Cryptographic implementations (name algorithms, key sizes, modes)
1967
- - Architecture strengths (name the pattern and why it's secure)
1968
- - Operational security (logging, monitoring, incident response)
1969
-
1970
- Output as array of objects with `title` and `description` fields.
1971
-
1972
- ---
1973
-
1974
- ## PHASE 7: CONSOLIDATE AGENT RESULTS
1975
-
1976
- **After all batches complete, read findings from agent output files:**
46
+ ### Step 3: Check Previous Scan
1977
47
 
1978
48
  ```bash
1979
- # List all agent output files
1980
- ls -la .coverme/agents/*.json 2>/dev/null
1981
-
1982
- # Combine all findings into one array (using jq if available, or read each file)
1983
- cat .coverme/agents/*.json 2>/dev/null | head -100
49
+ cat .coverme/scan.json 2>/dev/null | head -50 || echo "NO_PREVIOUS_SCAN"
1984
50
  ```
1985
51
 
1986
- **For each agent file that exists:**
1987
- 1. Read the JSON file
1988
- 2. Extract the `findings` array
1989
- 3. Merge into the master findings list
1990
- 4. Track which agents completed vs skipped
1991
-
1992
- **Memory-efficient consolidation:**
1993
- - Read ONE agent file at a time
1994
- - Extract only the findings array
1995
- - Do NOT keep the full file content in memory
1996
- - Build the final `scan.json` incrementally
1997
-
1998
52
  ---
1999
53
 
2000
- ## PHASE 8: BUILD CONSENSUS & GENERATE OUTPUT
2001
-
2002
- ### CRITICAL: Actually Remove False Positives!
54
+ ## PHASE 2: DEEP ANALYSIS
2003
55
 
2004
- The final report should ONLY contain findings that are:
2005
- 1. **Confirmed** by mitigation validation (no existing protection found)
2006
- 2. **Partial** mitigations (some protection but incomplete)
56
+ **Read the critical files you found.** For each file, look for:
2007
57
 
2008
- **DO NOT INCLUDE** findings that are:
2009
- - `mitigated` - full protection exists elsewhere
2010
- - `false_positive` - not actually a vulnerability
2011
- - Intentional design decisions with documented comments
2012
- - Race conditions protected by atomic operations (Lua, transactions)
58
+ ### Security (SEC)
59
+ - SQL/NoSQL Injection - string concatenation in queries
60
+ - XSS - unsanitized output
61
+ - Command Injection - user input in shell commands
62
+ - Path Traversal - user input in file paths
63
+ - SSRF - user-controlled URLs
64
+ - Hardcoded Secrets - API keys, passwords in code
65
+ - Weak Crypto - MD5, SHA1 for passwords, weak random
2013
66
 
2014
- ### Step-by-Step Process:
67
+ ### Authentication (AUTH)
68
+ - JWT issues - algorithm confusion, missing validation
69
+ - Session fixation
70
+ - Password storage - plaintext, weak hashing
71
+ - Missing MFA
72
+ - OAuth misconfigurations
2015
73
 
2016
- 1. **Start with all Phase 1 findings**
74
+ ### API Security (API)
75
+ - Missing input validation
76
+ - No rate limiting
77
+ - CORS misconfigurations
78
+ - Missing authentication on endpoints
79
+ - Mass assignment
2017
80
 
2018
- 2. **Apply Mitigation Validator results (Phase 3):**
2019
- - `mitigated` REMOVE from findings, add to `mitigatedFindings` array
2020
- - `false_positive` REMOVE from findings, add to `falsePositives` array
2021
- - `partial` KEEP but downgrade severity if specified
2022
- - `confirmed` → KEEP with original severity
81
+ ### Infrastructure (INFRA)
82
+ - Docker running as root
83
+ - Secrets in docker-compose
84
+ - Missing securityContext in K8s
85
+ - No NetworkPolicy
86
+ - Secrets in git history
87
+ - CI/CD security issues
2023
88
 
2024
- 3. **Apply Cross-Validator results (Phase 4):**
2025
- - Additional false positives → REMOVE from findings
2026
- - Duplicates → Merge into single finding
89
+ ### Business Logic (BIZ)
90
+ - Race conditions (TOCTOU)
91
+ - Authorization bypass
92
+ - Quota/credit manipulation
93
+ - Workflow bypass
2027
94
 
2028
- 4. **Calculate final counts AFTER removals:**
2029
- - Only count findings that remain in the `findings` array
2030
- - Do NOT count mitigated or false positive findings
95
+ ### Code Quality (QUAL)
96
+ - No tests for security code
97
+ - Dead code
98
+ - Missing error handling
2031
99
 
2032
- 5. **Add missed issues from Validator C**
100
+ ---
2033
101
 
2034
- 6. **Sort remaining findings:** severity DESC, confidence DESC
102
+ ## PHASE 3: GENERATE REPORT
2035
103
 
2036
- ### Final JSON Structure
104
+ Create `.coverme/scan.json` with this structure:
2037
105
 
2038
106
  ```json
2039
107
  {
2040
108
  "projectName": "project-name",
2041
- "scanDate": "{{SCAN_DATE}}",
2042
- "filesScanned": 45,
2043
- "linesOfCode": 4850,
2044
- "projectTree": "project-name/\n├── src/\n│ ├── api/\n│ ├── services/\n│ └── utils/\n├── tests/\n└── package.json",
2045
-
109
+ "scanDate": "2026-02-18T12:00:00Z",
110
+ "filesScanned": 100,
111
+ "linesOfCode": 15000,
112
+ "projectTree": "project/\n├── src/\n│ ├── routes/\n│ ├── services/\n│ └── middleware/\n├── tests/\n└── package.json",
2046
113
  "projectOverview": {
2047
- "name": "project-name",
2048
- "type": "Backend API | Full-stack | etc",
2049
- "stack": ["Node.js", "TypeScript", "React", "PostgreSQL"],
2050
- "purpose": "Brief description of what this project does",
114
+ "name": "Project Name",
115
+ "type": "Backend API",
116
+ "stack": ["Node.js", "TypeScript", "PostgreSQL"],
117
+ "purpose": "What this project does in 1-2 sentences",
2051
118
  "architecture": "Monolith | Microservices | Serverless",
2052
- "keyComponents": ["auth service", "payment processing", "AI chat"]
119
+ "keyComponents": ["src/routes/", "src/services/"]
2053
120
  },
2054
-
2055
121
  "executiveSummary": {
2056
- "headline": "3 Critical + 5 High findings require immediate attention",
122
+ "headline": "X Critical + Y High findings - brief assessment",
2057
123
  "riskLevel": "CRITICAL | HIGH | MEDIUM | LOW",
2058
- "overview": "A 2-3 sentence executive summary of the project architecture AND the overall security posture, written for leadership. Example: 'Express-AI Officely is a confidential AI platform built on a three-tier encrypted architecture. No critical vulnerabilities remain. The most significant remaining issues are: unauthenticated registration endpoints, hardcoded secrets in Helm values, and zero test coverage.'",
124
+ "overview": "2-3 sentence professional summary. Describe the architecture, then the security posture, then the main concerns.",
2059
125
  "topRisks": [
2060
- "Unauthenticated enclave registration endpoints could allow impersonation (mitigated by network whitelisting)",
2061
- "Hardcoded API keys and hash salts in Helm values committed to version control",
2062
- "160 lines of Redis metrics tracking duplicated verbatim between streaming/non-streaming paths"
126
+ "Specific risk with file:line reference",
127
+ "Another risk with quantified impact"
2063
128
  ],
2064
129
  "positives": [
2065
- "Zero-knowledge architecture gateway never sees plaintext",
2066
- "Atomic credit operations via Lua scripts prevent race conditions",
2067
- "Post-quantum cryptography with XWing hybrid KEM"
130
+ "Good practice with specific evidence",
131
+ "Another strength with file reference"
2068
132
  ],
2069
133
  "recommendedActions": [
2070
134
  {
2071
135
  "priority": 1,
2072
- "action": "Remove hardcoded secrets from Helm values. Move to Secrets Manager. Rotate keys.",
2073
- "owner": "devops",
2074
- "effort": "2-4 hours"
2075
- }
2076
- ],
2077
- "byOwner": {
2078
- "developer": 5,
2079
- "devops": 3,
2080
- "architect": 1
2081
- }
2082
- },
2083
-
2084
- "architectureOverview": {
2085
- "components": [
2086
- {
2087
- "name": "API Server",
2088
- "type": "service",
2089
- "description": "Express.js REST API handling all client requests",
2090
- "trustLevel": "semi-trusted"
2091
- },
2092
- {
2093
- "name": "PostgreSQL",
2094
- "type": "database",
2095
- "description": "Primary data store for user and application data",
2096
- "trustLevel": "trusted"
2097
- },
2098
- {
2099
- "name": "Redis",
2100
- "type": "cache",
2101
- "description": "Session storage and rate limiting",
2102
- "trustLevel": "trusted"
2103
- },
2104
- {
2105
- "name": "External Payment API",
2106
- "type": "external",
2107
- "description": "Third-party payment processor",
2108
- "trustLevel": "untrusted"
2109
- }
2110
- ],
2111
- "trustBoundaries": [
2112
- {
2113
- "name": "Client to API",
2114
- "from": "Browser/Mobile",
2115
- "to": "API Server",
2116
- "protocol": "HTTPS"
2117
- },
2118
- {
2119
- "name": "API to Database",
2120
- "from": "API Server",
2121
- "to": "PostgreSQL",
2122
- "protocol": "TLS"
2123
- }
2124
- ],
2125
- "criticalAssets": [
2126
- {
2127
- "name": "User Credentials",
2128
- "type": "credential",
2129
- "location": "PostgreSQL users table",
2130
- "protection": "bcrypt hashed"
2131
- },
2132
- {
2133
- "name": "API Keys",
2134
- "type": "key",
2135
- "location": "Environment variables",
2136
- "protection": "Encrypted at rest"
2137
- },
2138
- {
2139
- "name": "Session Tokens",
2140
- "type": "token",
2141
- "location": "Redis",
2142
- "protection": "HMAC signed"
136
+ "action": "Specific action to take",
137
+ "owner": "developer",
138
+ "effort": "2-3 days"
2143
139
  }
2144
- ],
2145
- "dataFlows": [
2146
- "User Authentication Flow",
2147
- "Payment Processing Flow",
2148
- "Data Export Flow"
2149
140
  ]
2150
141
  },
2151
-
2152
- "threatModel": [
2153
- {
2154
- "id": "T-001",
2155
- "threat": "SQL Injection via user input",
2156
- "category": "STRIDE",
2157
- "strideType": "T",
2158
- "status": "open",
2159
- "relatedFindings": ["SEC-001", "DB-002"],
2160
- "mitigation": "Use parameterized queries",
2161
- "dreadScore": 8.5
2162
- },
2163
- {
2164
- "id": "T-002",
2165
- "threat": "Session hijacking via XSS",
2166
- "category": "STRIDE",
2167
- "strideType": "S",
2168
- "status": "partial",
2169
- "relatedFindings": ["SEC-003"],
2170
- "mitigation": "CSP headers implemented but not comprehensive",
2171
- "dreadScore": 7.2
2172
- },
2173
- {
2174
- "id": "T-003",
2175
- "threat": "Unauthorized data access",
2176
- "category": "LINDDUN",
2177
- "status": "mitigated",
2178
- "relatedFindings": [],
2179
- "mitigation": "Row-level security implemented",
2180
- "dreadScore": 3.0
2181
- }
2182
- ],
2183
-
2184
- "qualityReview": {
2185
- "deleteItems": [
2186
- {
2187
- "type": "delete",
2188
- "file": "src/utils/oldHelpers.ts",
2189
- "lines": 250,
2190
- "title": "Dead utility functions — no callers in codebase",
2191
- "description": "Entire file is dead code — functions never called. No imports found anywhere.",
2192
- "reason": "No imports found in codebase",
2193
- "roi": "~250 lines"
2194
- },
2195
- {
2196
- "type": "delete",
2197
- "file": "src/legacy/auth.js",
2198
- "lines": 180,
2199
- "title": "Legacy auth replaced by Clerk integration",
2200
- "description": "Legacy auth implementation replaced by Clerk. Migration completed 6 months ago.",
2201
- "reason": "Migration completed 6 months ago",
2202
- "roi": "~180 lines"
2203
- }
2204
- ],
2205
- "mergeItems": [
2206
- {
2207
- "type": "merge",
2208
- "file": "src/utils/validate.ts, src/helpers/validation.ts",
2209
- "title": "Duplicate validation modules",
2210
- "description": "Two files with overlapping validation functions — same Zod schema patterns duplicated",
2211
- "reason": "DRY violation — consolidate into single module",
2212
- "roi": "~120 lines"
2213
- }
2214
- ],
2215
- "simplifyItems": [
2216
- {
2217
- "type": "simplify",
2218
- "file": "src/services/payment.ts",
2219
- "lines": 450,
2220
- "title": "Overly complex payment handler — 450 lines",
2221
- "description": "Single function handles parsing, validation, processing, and error recovery with deeply nested try/catch blocks",
2222
- "reason": "Split into paymentValidator, paymentProcessor, paymentErrorHandler — reduce to ~200 lines",
2223
- "roi": "~250 lines reducible"
2224
- }
2225
- ],
2226
- "totalLinesRemovable": 680,
2227
- "percentageOfCodebase": 4.2
2228
- },
2229
-
2230
- "actionItems": [
2231
- {
2232
- "id": "A-001",
2233
- "title": "Fix SQL injection in user search",
2234
- "priority": "immediate",
2235
- "relatedFindings": ["SEC-001"],
2236
- "effort": "low",
2237
- "description": "Replace string concatenation with parameterized query"
2238
- },
2239
- {
2240
- "id": "A-002",
2241
- "title": "Implement rate limiting on auth endpoints",
2242
- "priority": "immediate",
2243
- "relatedFindings": ["AUTH-003"],
2244
- "effort": "medium",
2245
- "description": "Add Redis-based rate limiter to /login and /register"
2246
- },
2247
- {
2248
- "id": "A-003",
2249
- "title": "Add CSP headers",
2250
- "priority": "high",
2251
- "relatedFindings": ["SEC-005"],
2252
- "effort": "low",
2253
- "description": "Configure helmet with strict CSP policy"
2254
- },
2255
- {
2256
- "id": "A-004",
2257
- "title": "Clean up dead code",
2258
- "priority": "medium",
2259
- "relatedFindings": ["DEAD-001", "DEAD-002"],
2260
- "effort": "medium",
2261
- "description": "Remove 680 lines of unused code identified in quality review"
2262
- },
2263
- {
2264
- "id": "A-005",
2265
- "title": "Implement audit logging",
2266
- "priority": "long-term",
2267
- "relatedFindings": ["DATA-002"],
2268
- "effort": "high",
2269
- "description": "Add comprehensive audit trail for sensitive operations"
2270
- }
2271
- ],
2272
-
2273
- "summary": {
2274
- "total": 10,
2275
- "critical": 1,
2276
- "high": 3,
2277
- "medium": 4,
2278
- "low": 2,
2279
- "info": 0,
2280
- "mitigatedCount": 5,
2281
- "falsePositiveCount": 3,
2282
- "avgConfidence": 0.85
2283
- },
2284
-
2285
142
  "findings": [
2286
143
  {
2287
144
  "id": "SEC-001",
2288
- "title": "SQL Injection in User Search",
145
+ "title": "Specific title describing the exact vulnerability",
2289
146
  "severity": "critical",
2290
147
  "category": "security",
2291
- "file": "src/routes/users.ts",
148
+ "file": "src/routes/user.ts",
2292
149
  "line": 45,
2293
- "code": "db.query(`SELECT * FROM users WHERE name LIKE '%${searchTerm}%'`)",
2294
- "description": "User search parameter is directly concatenated into SQL query without sanitization",
2295
- "impact": "Attacker can extract entire database contents, modify data, or execute system commands",
150
+ "endLine": 52,
151
+ "code": "const query = `SELECT * FROM users WHERE id = ${userId}`",
152
+ "description": "The userId parameter is concatenated directly into the SQL query without sanitization. This allows an attacker to inject arbitrary SQL commands.",
153
+ "impact": "Full database access. Attacker can read all user data, modify records, or delete tables.",
2296
154
  "attackChain": [
2297
- {"step": 1, "action": "Send malicious search term: ' OR '1'='1' --", "result": "Query returns all users"},
2298
- {"step": 2, "action": "Use UNION SELECT to extract data from other tables", "result": "Database schema exposed"},
2299
- {"step": 3, "action": "Extract password hashes and sensitive data", "result": "Full data breach"}
155
+ {"step": 1, "action": "Send userId = '1 OR 1=1'", "result": "Query returns all users"},
156
+ {"step": 2, "action": "Use UNION SELECT to read other tables", "result": "Extract passwords, tokens"},
157
+ {"step": 3, "action": "Use INTO OUTFILE to write webshell", "result": "Remote code execution"}
2300
158
  ],
2301
- "recommendation": "Use parameterized queries: db.query('SELECT * FROM users WHERE name LIKE $1', [`%${searchTerm}%`])",
2302
- "cwe": "CWE-89",
2303
- "owasp": "A03:2021",
2304
- "dreadScore": {
159
+ "recommendation": "Use parameterized queries: `db.query('SELECT * FROM users WHERE id = $1', [userId])`",
160
+ "dread": {
2305
161
  "damage": 10,
2306
162
  "reproducibility": 10,
2307
163
  "exploitability": 9,
2308
164
  "affectedUsers": 10,
2309
165
  "discoverability": 8,
2310
- "total": 9.4
166
+ "score": 9.4
2311
167
  },
2312
- "status": "open",
2313
- "crossReferences": ["T-001"],
2314
- "confidence": 95,
2315
- "fixOwner": "developer",
2316
- "fixType": "code"
2317
- }
2318
- ],
2319
-
2320
- "designDecisions": [
2321
- {
2322
- "id": "DESIGN-001",
2323
- "title": "Content filtering disabled for transparency",
2324
- "file": "src/ai/chat.ts",
2325
- "reason": "Documented decision - users see raw AI output",
2326
- "acceptedRisk": "Users may see inappropriate content"
2327
- }
2328
- ],
2329
-
2330
- "mitigatedFindings": [
2331
- {
2332
- "id": "SEC-005",
2333
- "title": "Original finding title",
2334
- "originalSeverity": "high",
2335
- "reason": "Protected by Zod schema validation at src/routes/user.ts:23",
2336
- "mitigationType": "input_validation"
2337
- }
2338
- ],
2339
-
2340
- "falsePositives": [
2341
- {
2342
- "id": "BIZ-004",
2343
- "title": "TOCTOU Race Condition",
2344
- "reason": "Redis Lua script provides atomic operation - no race condition possible",
2345
- "evidence": ["Lua script at src/services/rate-limit.js:95-113"]
168
+ "cwe": "CWE-89",
169
+ "fixOwner": "developer"
2346
170
  }
2347
171
  ],
2348
-
2349
172
  "positiveObservations": [
2350
173
  {
2351
- "title": "Strong Authentication Implementation",
2352
- "description": "Clerk integration with proper session management, MFA support, and secure cookie settings. All tokens kept server-side. httpOnly + secure cookies with SameSite=strict."
2353
- },
2354
- {
2355
- "title": "Comprehensive Input Validation",
2356
- "description": "Zod schemas used consistently across 15+ API endpoints with proper error handling. Schema-first validation prevents malformed input from reaching business logic."
2357
- },
2358
- {
2359
- "title": "Secure Database Access",
2360
- "description": "Prisma ORM with parameterized queries throughout. Zero raw SQL queries found. Prevents SQL injection across all database operations."
2361
- },
2362
- {
2363
- "title": "Good Error Handling Patterns",
2364
- "description": "Custom AppError class with error codes. Internal details logged server-side only. Generic messages returned to clients. Consistent format across routes."
2365
- }
2366
- ],
2367
-
2368
- "previouslyResolved": [
2369
- {
2370
- "id": "PREV-001",
2371
- "title": "SQL Injection in search endpoint",
2372
- "originalSeverity": "critical",
2373
- "resolution": "Parameterized queries implemented using Prisma ORM. Verified no raw SQL remains.",
2374
- "resolvedDate": "2026-01-15"
174
+ "title": "Proper Password Hashing",
175
+ "description": "Uses bcrypt with cost factor 12 in auth/password.ts:23. Passwords never stored in plaintext."
2375
176
  }
2376
177
  ],
2377
-
2378
- "validationSummary": {
2379
- "totalInitialFindings": 18,
2380
- "mitigated": 5,
2381
- "falsePositives": 3,
2382
- "confirmed": 8,
2383
- "partial": 2,
2384
- "accuracy": "Only 56% of initial findings were actual issues"
178
+ "qualityReview": {
179
+ "deleteItems": [
180
+ {"file": "src/old/legacy.ts", "lines": 250, "description": "Unused legacy code - no imports found"}
181
+ ],
182
+ "mergeItems": [
183
+ {"file": "src/utils/validate.ts + src/helpers/validator.ts", "description": "Duplicate validation logic"}
184
+ ],
185
+ "totalLinesRemovable": 400,
186
+ "percentageOfCodebase": 2.5
2385
187
  },
2386
-
2387
- "agentsUsed": ["Security Core", "Auth & Session", "Mitigation Validator", "Network & Architecture", "Design Decision Detector"],
2388
- "scanDuration": 0
188
+ "summary": {
189
+ "critical": 1,
190
+ "high": 3,
191
+ "medium": 5,
192
+ "low": 2,
193
+ "total": 11
194
+ }
2389
195
  }
2390
196
  ```
2391
197
 
2392
- ### Sanity Check Before Saving
198
+ ### DREAD Scoring (REQUIRED for critical/high):
199
+
200
+ | Score | Meaning |
201
+ |-------|---------|
202
+ | 10 | Worst case |
203
+ | 7-9 | Severe |
204
+ | 4-6 | Moderate |
205
+ | 1-3 | Minor |
206
+
207
+ - **Damage**: Impact if exploited
208
+ - **Reproducibility**: How consistently exploitable
209
+ - **Exploitability**: Skill level needed
210
+ - **Affected Users**: Scope of impact
211
+ - **Discoverability**: How easy to find
212
+ - **Score**: Average of all five
2393
213
 
2394
- Before saving, verify:
2395
- 1. `findings` array does NOT contain any item from `mitigatedFindings` or `falsePositives`
2396
- 2. `summary.total` equals `findings.length`
2397
- 3. Severity counts match actual findings in array
2398
- 4. No duplicate IDs across findings/mitigated/falsePositives
214
+ ### Attack Chain (REQUIRED for critical/high):
2399
215
 
2400
- Save as: .coverme/scan.json
216
+ Show step-by-step exploitation:
217
+ ```json
218
+ [
219
+ {"step": 1, "action": "What attacker does", "result": "What happens"},
220
+ {"step": 2, "action": "Next action", "result": "Escalation"},
221
+ {"step": 3, "action": "Final action", "result": "Full compromise"}
222
+ ]
223
+ ```
2401
224
 
2402
225
  ---
2403
226
 
2404
- ## PHASE 8: GENERATE HTML REPORT (MANDATORY)
227
+ ## PHASE 4: SAVE AND OPEN REPORT
2405
228
 
2406
- **After saving scan.json, you MUST generate and open the HTML report.**
229
+ After creating the JSON, save it and generate HTML:
2407
230
 
2408
- Run this command:
2409
231
  ```bash
2410
- coverme report .coverme/scan.json
232
+ # Save scan.json (you just wrote it)
233
+ # Generate and open HTML report
234
+ coverme report
2411
235
  ```
2412
236
 
2413
- This will:
2414
- 1. Generate `.coverme/report_YYYY-MM-DD_HH-MM-SS.html`
2415
- 2. Automatically open the report in the default browser
237
+ The `coverme report` command will:
238
+ 1. Read `.coverme/scan.json`
239
+ 2. Generate `.coverme/report_YYYY-MM-DD_HH-MM-SS.html`
240
+ 3. Open the report in your browser
2416
241
 
2417
- **If `coverme` command is not available:**
242
+ ---
2418
243
 
2419
- Generate the HTML manually using this template structure, then open it:
2420
- ```bash
2421
- # Save HTML report
2422
- cat > .coverme/report_$(date +%Y-%m-%d_%H-%M-%S).html << 'HTMLEOF'
2423
- <!DOCTYPE html>
2424
- <html>
2425
- <head>
2426
- <title>CoverMe Security Report</title>
2427
- <style>
2428
- body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; max-width: 1200px; margin: 0 auto; padding: 20px; }
2429
- .critical { color: #dc2626; } .high { color: #ea580c; } .medium { color: #ca8a04; } .low { color: #16a34a; }
2430
- .finding { border: 1px solid #e5e7eb; border-radius: 8px; padding: 16px; margin: 16px 0; }
2431
- .finding-header { display: flex; justify-content: space-between; align-items: center; }
2432
- pre { background: #f3f4f6; padding: 12px; border-radius: 4px; overflow-x: auto; }
2433
- .summary-card { background: #f9fafb; padding: 20px; border-radius: 8px; margin: 20px 0; }
2434
- </style>
2435
- </head>
2436
- <body>
2437
- <h1>Security Scan Report</h1>
2438
- <!-- Insert findings from scan.json -->
2439
- </body>
2440
- </html>
2441
- HTMLEOF
244
+ ## QUALITY CHECKLIST
2442
245
 
2443
- # Open in browser
2444
- open .coverme/report_*.html 2>/dev/null || xdg-open .coverme/report_*.html 2>/dev/null || echo "Report saved to .coverme/"
2445
- ```
246
+ Before finishing, verify:
2446
247
 
2447
- **CRITICAL**: Do not end the scan without generating and opening the HTML report. The user expects to see the report in their browser.
248
+ - [ ] Read actual code files, not just file names
249
+ - [ ] Every finding has file + line number
250
+ - [ ] Critical/High findings have DREAD scores
251
+ - [ ] Critical/High findings have attack chains
252
+ - [ ] No duplicate findings
253
+ - [ ] Positive observations have specific evidence
254
+ - [ ] Executive summary is professional and specific
255
+ - [ ] `coverme report` was run to generate HTML
2448
256
 
2449
257
  ---
2450
258
 
2451
- ## FINAL STEP - MANDATORY
259
+ ## EXAMPLES
2452
260
 
2453
- After saving `.coverme/scan.json`, you MUST run this command:
261
+ ### Good Finding:
262
+ ```json
263
+ {
264
+ "id": "AUTH-001",
265
+ "title": "JWT accepts 'none' algorithm allowing authentication bypass",
266
+ "severity": "critical",
267
+ "file": "src/middleware/auth.ts",
268
+ "line": 34,
269
+ "code": "jwt.verify(token, secret, { algorithms: ['HS256', 'none'] })",
270
+ "description": "JWT verification accepts the 'none' algorithm. An attacker can forge tokens by removing the signature and setting alg=none.",
271
+ "attackChain": [
272
+ {"step": 1, "action": "Capture valid JWT", "result": "Obtain token structure"},
273
+ {"step": 2, "action": "Decode, modify claims, set alg=none, remove signature", "result": "Forged admin token"},
274
+ {"step": 3, "action": "Send forged token", "result": "Authenticated as any user"}
275
+ ],
276
+ "dread": {"damage": 10, "reproducibility": 10, "exploitability": 9, "affectedUsers": 10, "discoverability": 7, "score": 9.2}
277
+ }
278
+ ```
2454
279
 
2455
- ```bash
2456
- coverme report
280
+ ### Bad Finding (don't do this):
281
+ ```json
282
+ {
283
+ "id": "SEC-001",
284
+ "title": "SQL Injection",
285
+ "severity": "high",
286
+ "description": "There might be SQL injection somewhere"
287
+ }
2457
288
  ```
2458
289
 
2459
- This generates the HTML report and opens it in the browser automatically.
290
+ ---
2460
291
 
2461
- **If you skip this step, the scan is incomplete!**
292
+ ## REMEMBER
2462
293
 
2463
- The scan is only finished when:
2464
- 1. scan.json is saved
2465
- 2. HTML report is generated
2466
- 3. Browser opens with the report
294
+ 1. **Read code before reporting** - Don't guess
295
+ 2. **Be specific** - File names, line numbers, actual code
296
+ 3. **DREAD + Attack Chain** - Required for critical/high
297
+ 4. **Run `coverme report`** - Opens HTML in browser
298
+ 5. **Quality over quantity** - 10 good findings > 50 vague ones