nightytidy 0.3.7 → 0.3.9

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.
Files changed (37) hide show
  1. package/bin/nightytidy.js +1 -1
  2. package/package.json +1 -1
  3. package/src/agent/git-integration.js +4 -1
  4. package/src/claude.js +1 -1
  5. package/src/prompts/manifest.json +138 -138
  6. package/src/prompts/steps/02-test-coverage.md +181 -181
  7. package/src/prompts/steps/03-test-hardening.md +181 -181
  8. package/src/prompts/steps/04-test-architecture.md +130 -130
  9. package/src/prompts/steps/05-test-consolidation.md +165 -165
  10. package/src/prompts/steps/06-test-quality.md +211 -211
  11. package/src/prompts/steps/07-api-design.md +165 -165
  12. package/src/prompts/steps/08-security-sweep.md +207 -207
  13. package/src/prompts/steps/09-dependency-health.md +217 -217
  14. package/src/prompts/steps/10-codebase-cleanup.md +189 -189
  15. package/src/prompts/steps/11-crosscutting-concerns.md +196 -196
  16. package/src/prompts/steps/12-file-decomposition.md +263 -263
  17. package/src/prompts/steps/13-code-elegance.md +329 -329
  18. package/src/prompts/steps/14-architectural-complexity.md +297 -297
  19. package/src/prompts/steps/15-type-safety.md +192 -192
  20. package/src/prompts/steps/16-logging-error-message.md +173 -173
  21. package/src/prompts/steps/17-data-integrity.md +139 -139
  22. package/src/prompts/steps/18-performance.md +183 -183
  23. package/src/prompts/steps/19-cost-resource-optimization.md +136 -136
  24. package/src/prompts/steps/20-error-recovery.md +145 -145
  25. package/src/prompts/steps/21-race-condition-audit.md +178 -178
  26. package/src/prompts/steps/22-bug-hunt.md +229 -229
  27. package/src/prompts/steps/23-frontend-quality.md +210 -210
  28. package/src/prompts/steps/24-uiux-audit.md +284 -284
  29. package/src/prompts/steps/25-state-management.md +170 -170
  30. package/src/prompts/steps/26-perceived-performance.md +190 -190
  31. package/src/prompts/steps/27-devops.md +165 -165
  32. package/src/prompts/steps/28-scheduled-job-chron-jobs.md +141 -141
  33. package/src/prompts/steps/29-observability.md +152 -152
  34. package/src/prompts/steps/30-backup-check.md +155 -155
  35. package/src/prompts/steps/31-product-polish-ux-friction.md +122 -122
  36. package/src/prompts/steps/32-feature-discovery-opportunity.md +128 -128
  37. package/src/prompts/steps/33-strategic-opportunities.md +217 -217
@@ -1,207 +1,207 @@
1
- You are running an overnight security audit of this codebase. Be thorough, not fast. Systematically find security vulnerabilities, fix the ones that are safe to fix, and document everything else.
2
-
3
- Work on a branch called `security-audit-[date]`.
4
-
5
- ## General Principles (apply to all phases)
6
- - Each phase builds on findings from previous phases. Don't re-run tools or re-investigate issues already covered.
7
- - Run automated tools BEFORE starting manual analysis. Their output informs where to focus.
8
- - DO NOT install new security tools unless trivial (pip install into existing venv, npx one-off). Document missing tools as recommendations instead.
9
- - When automated tools disagree on severity, use the higher rating and verify manually.
10
- - Track false positives explicitly — they're useful for future runs and tool configuration.
11
-
12
- ## Phase 0: Automated Security Tooling Scan
13
-
14
- Run every available SAST tool, dependency scanner, and secret detector first so manual analysis in Phases 1-4 can focus on what tools miss.
15
-
16
- **Step 1: Discover available security tooling**
17
- Search for SAST tools, dependency scanners, secret detectors, container scanners, IaC scanners, and pre-commit hooks — whether installed, configured in CI/CD, referenced in docs, or standard for the project's language/framework. Check pipeline configs, IDE configs, `.pre-commit-config.yaml`, `.husky/`, etc. Document everything found.
18
-
19
- **Step 2: Run every available tool**
20
- For each installed/configured tool, run it against the entire codebase. Capture: tool name, version, number of findings, severity breakdown.
21
-
22
- For built-in tools that require no installation (`npm audit`, `yarn audit`, `pnpm audit`, `pip audit` if available), always run them. For tools requiring installation, note the gap and recommend them.
23
-
24
- If Gitleaks or TruffleHog is installed, run against full git history. If Dockerfiles exist, run Hadolint if available.
25
-
26
- **Step 3: Triage automated findings**
27
- For each finding:
28
- - **Verify it's real**: Check for false positives in context (e.g., SQL injection warning on already-parameterized queries)
29
- - **Classify severity**: Adjust based on reachability from user input, production vs test code, and compensating controls
30
- - **Deduplicate** across tools
31
- - **Map** each finding to the relevant manual audit phase (1-4)
32
-
33
- **Step 4: Document tool coverage gaps**
34
- Identify what's NOT covered (no secret scanning, no SAST, no dependency scanning, no IaC scanning, no container scanning). These gaps dictate where to focus manual effort.
35
-
36
- **Step 5: Assess security tooling posture**
37
- Document: Is there security scanning in CI/CD? Are results blocking merges or just informational? Are there documented exception allowlists? When was tooling config last reviewed?
38
-
39
- ### Phase 1: Secrets & Sensitive Data Scan
40
- Search the entire codebase (config files, scripts, test fixtures, git history) for:
41
- - Hardcoded API keys, tokens, passwords, credentials, AWS access keys, database connection strings
42
- - Private keys or certificates committed to the repo
43
- - PII patterns in test data that look like real data
44
- - `.env` files or similar that shouldn't be committed
45
- - Check `.gitignore` for proper exclusion of sensitive file patterns
46
-
47
- ### Phase 2: Auth & Permissions Audit
48
- Map every route/endpoint and verify for each:
49
- - Is authentication required? Should it be?
50
- - Is authorization/role checking applied at the right level?
51
- - Any IDOR vulnerabilities (accepting user/resource IDs without access verification)?
52
-
53
- Check for: inconsistent auth middleware application, underprotected admin endpoints, JWT/session config issues (expiration, signing algorithm, secret strength), password hashing (bcrypt/argon2 vs MD5/SHA).
54
-
55
- ### Phase 3: Common Vulnerability Scan
56
- Search the codebase systematically for each pattern:
57
-
58
- - **Injection**: SQL (string concatenation in queries), NoSQL, command (exec/spawn with user input), LDAP
59
- - **XSS**: dangerouslySetInnerHTML, unescaped template outputs, innerHTML assignments
60
- - **CSRF**: Missing tokens on state-changing endpoints, SameSite cookie config
61
- - **Insecure Deserialization**: Unvalidated JSON.parse on user input, YAML.load with untrusted data, pickle/eval
62
- - **SSRF**: User-controlled URLs fetched server-side without validation
63
- - **Path Traversal**: File operations with user-supplied paths unsanitized
64
- - **CORS**: Wildcard origins with credentials
65
- - **Rate Limiting**: Auth endpoints without rate limiting
66
- - **Security Headers**: Missing CSP, X-Frame-Options, HSTS, etc.
67
- - **File Upload**: Missing type validation, size limits, executable uploads
68
- - **Error Handling**: Stack traces or internal details in error responses
69
-
70
- ### Phase 4A: Dependency Vulnerabilities
71
- - Review dependency manifests (package.json, requirements.txt, Cargo.toml, go.mod, etc.)
72
- - Run audit tools if not already run in Phase 0
73
- - For each CVE: note severity, check if vulnerable code path is actually used, attempt upgrade on a branch, run tests, document results
74
-
75
- ### Phase 4B: Supply Chain Attack Pattern Scan
76
-
77
- Look for attack patterns that won't show up in `npm audit` — the things supply chain compromises actually use.
78
-
79
- **Step 1: Post-install script audit**
80
- Check every direct dependency for lifecycle scripts (preinstall, install, postinstall, prepare). For each: read the script, flag any that make network requests, read env vars, access filesystem broadly, or execute dynamic code. Check if install script restrictions are configured (e.g., `.npmrc` with `ignore-scripts=true`).
81
-
82
- **Step 2: Typosquatting risk assessment**
83
- Check each dependency name for typosquatting risk against well-known packages (character substitutions, misspellings, hyphen/underscore/scope variations). Verify legitimacy via web search and download counts.
84
-
85
- **Step 3: Scope and namespace risks**
86
- Check for: unscoped internal packages published publicly, references to scopes the team doesn't own, internal monorepo package names not registered on the public registry (dependency confusion risk), `.npmrc` or registry config mixing public and private registries.
87
-
88
- **Step 4: Lock file integrity**
89
- Verify: lock file is committed and current, all resolved URLs point to expected registries, no packages resolving to unexpected URLs/IPs, no missing integrity hashes. If git history available, check for lock file modifications without manifest changes.
90
-
91
- **Step 5: Maintainer transfer and takeover signals**
92
- For critical dependencies: check for recent ownership transfers, sudden releases after long inactivity, security advisories about compromised maintainer accounts. Use web search.
93
-
94
- **Step 6: Transitive dependency risk**
95
- Identify full dependency tree depth. Flag transitive deps with: extremely low download counts, single unmaintained maintainer, 3+ years stale, permissions beyond stated purpose.
96
-
97
- ### Phase 5: Safe Fixes
98
-
99
- Fix issues that are mechanical, well-understood, and verifiable. After EVERY fix, run the test suite. If tests break, revert immediately and move to "document only."
100
-
101
- **Fix these (mechanical, low-risk):**
102
- - **Hardcoded secrets** → environment variable references (add to `.env.example` with placeholders, don't rotate actual credentials)
103
- - **SQL/NoSQL injection** → parameterized queries using existing DB library
104
- - **XSS** → safe alternatives to dangerouslySetInnerHTML, output encoding/escaping
105
- - **Missing CSRF tokens** → add via existing CSRF library/middleware (if none exists, document only)
106
- - **CORS misconfiguration** → explicit allowed origins if determinable from codebase (otherwise document only)
107
- - **Missing security headers** → CSP, X-Frame-Options, X-Content-Type-Options, HSTS, Referrer-Policy via existing middleware
108
- - **Rate limiting on auth endpoints** → add if rate limiting library already exists (otherwise document only)
109
- - **Error information leakage** → generic error messages in production, keep detailed logging server-side
110
- - **Missing `.gitignore` entries** → add patterns for .env, private keys, credentials files
111
- - **Insecure deserialization** → safe alternatives (JSON.parse, YAML.safeLoad, schema-validated)
112
- - **Path traversal** → sanitize paths (strip `..`, resolve to allowed directory)
113
- - **Install script restrictions** → add `.npmrc` config, document which packages need scripts and why
114
- - **Lock file hygiene** → regenerate from clean state if integrity issues found
115
- - **Dependency confusion prevention** → add scoping rules for private registry resolution
116
- - **Security tool misconfigurations** → fix outdated rulesets, re-enable disabled rules, add to CI/CD
117
-
118
- Commit each category separately: `security: fix [vulnerability type] in [module/scope]`
119
-
120
- **Document only — do NOT fix:**
121
- Auth flow changes, permission model changes, session/JWT configuration, password policy changes, encryption changes, architecture-level security changes, dependency replacements for supply chain risk, or anything where you're not confident in the correct behavior. **When in doubt, document rather than fix.** A documented vulnerability is inconvenient; a broken auth system at 3am is a disaster.
122
-
123
- ### Phase 6: Report
124
-
125
- Save as `audit-reports/08_SECURITY_AUDIT_REPORT_[run-number]_[date]_[time in user's local time].md` (create directory if needed, increment run number based on existing reports).
126
-
127
- ### Report Structure
128
- 1. **Executive Summary** — 3-5 sentences on overall security posture, including what was found AND fixed
129
-
130
- 2. **Automated Security Scan Results**
131
- - Tools discovered and run: | Tool | Version | Findings | Critical | High | Medium | Low | False Positives |
132
- - Tools recommended but unavailable: | Tool | What It Catches | Effort to Add | Priority |
133
- - Key verified findings: | Finding | Tool | Severity | File | Verified? | Addressed In Phase |
134
- - Notable false positives (for future runs)
135
- - Security CI/CD assessment: what runs automatically vs. what should
136
-
137
- 3. **Fixes Applied** — everything fixed in Phase 5
138
- - | Issue | Severity | Location | Fix Applied | Tests Pass? | Detected By |
139
-
140
- 4. **Critical Findings (Unfixed)**
141
- 5. **High Findings (Unfixed)**
142
- 6. **Medium Findings (Unfixed)**
143
- 7. **Low Findings (Unfixed)**
144
- 8. **Informational**
145
-
146
- 9. **Supply Chain Risk Assessment**
147
- - Post-install scripts: | Package | Script Type | Behavior | Risk Level | Recommendation |
148
- - Typosquatting risks: | Package | Similar To | Confidence | Evidence |
149
- - Namespace/scope risks: | Package | Risk Type | Detail | Recommendation |
150
- - Lock file integrity: pass/fail with anomaly details
151
- - Maintainer risk: | Package | Concern | Evidence | Risk Level |
152
- - Transitive dependency stats: total count, max depth, flagged packages
153
-
154
- ### Finding Template (all findings, fixed and unfixed)
155
- - **Title**, **Severity** (Critical/High/Medium/Low/Info), **Location** (file + line), **Description**, **Impact**, **Proof** (code snippet), **Recommendation** (with code example), **Detected By** (manual / [tool name] / both)
156
-
157
- Additional fields for **unfixed** findings: **Why It Wasn't Fixed**, **Effort** (Quick fix / Moderate / Significant refactor)
158
- Additional fields for **fixed** findings: **What was changed**, **Tests passing** (confirmation)
159
-
160
- ## Rules
161
- - Work on branch `security-audit-[date]`. DO NOT push to main.
162
- - Run full test suite after EVERY fix. If tests fail, revert IMMEDIATELY.
163
- - If you find compromised credentials, flag as CRITICAL at the top regardless of everything else.
164
- - Phase 5 fixes must be mechanical and verifiable. Judgment calls belong in the report.
165
- - Security header defaults should be noted for team review (especially CSP).
166
- - Don't pad the report — quality over quantity.
167
- - When in doubt about severity, err higher. When in doubt about a fix, document instead.
168
- - For supply chain findings: use web search to verify package legitimacy, check download counts, review maintainer history.
169
- - Be thorough. Check every file. You have all night.
170
-
171
- ## Chat Output Requirement
172
-
173
- In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
174
-
175
- ### 1. Status Line
176
- One sentence: what you did, how long it took, and whether all tests still pass.
177
-
178
- ### 2. Key Findings
179
- The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
180
-
181
- **Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
182
- **Bad:** "Found some issues with backups."
183
-
184
- ### 3. Changes Made (if applicable)
185
- Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
186
-
187
- ### 4. Recommendations
188
-
189
- If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
190
-
191
- When recommendations exist, use this table format:
192
-
193
- | # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
194
- |---|---|---|---|---|---|
195
- | *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
196
-
197
- Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
198
-
199
- ### 5. Report Location
200
- State the full path to the detailed report file for deeper review.
201
-
202
- ---
203
-
204
- **Formatting rules for chat output:**
205
- - Use markdown headers, bold for severity labels, and bullet points for scannability.
206
- - Do not duplicate the full report contents — just the highlights and recommendations.
207
- - If you made zero findings in a phase, say so in one line rather than omitting it silently.
1
+ You are running an overnight security audit of this codebase. Be thorough, not fast. Systematically find security vulnerabilities, fix the ones that are safe to fix, and document everything else.
2
+
3
+ Work on a branch called `security-audit-[date]`.
4
+
5
+ ## General Principles (apply to all phases)
6
+ - Each phase builds on findings from previous phases. Don't re-run tools or re-investigate issues already covered.
7
+ - Run automated tools BEFORE starting manual analysis. Their output informs where to focus.
8
+ - DO NOT install new security tools unless trivial (pip install into existing venv, npx one-off). Document missing tools as recommendations instead.
9
+ - When automated tools disagree on severity, use the higher rating and verify manually.
10
+ - Track false positives explicitly — they're useful for future runs and tool configuration.
11
+
12
+ ## Phase 0: Automated Security Tooling Scan
13
+
14
+ Run every available SAST tool, dependency scanner, and secret detector first so manual analysis in Phases 1-4 can focus on what tools miss.
15
+
16
+ **Step 1: Discover available security tooling**
17
+ Search for SAST tools, dependency scanners, secret detectors, container scanners, IaC scanners, and pre-commit hooks — whether installed, configured in CI/CD, referenced in docs, or standard for the project's language/framework. Check pipeline configs, IDE configs, `.pre-commit-config.yaml`, `.husky/`, etc. Document everything found.
18
+
19
+ **Step 2: Run every available tool**
20
+ For each installed/configured tool, run it against the entire codebase. Capture: tool name, version, number of findings, severity breakdown.
21
+
22
+ For built-in tools that require no installation (`npm audit`, `yarn audit`, `pnpm audit`, `pip audit` if available), always run them. For tools requiring installation, note the gap and recommend them.
23
+
24
+ If Gitleaks or TruffleHog is installed, run against full git history. If Dockerfiles exist, run Hadolint if available.
25
+
26
+ **Step 3: Triage automated findings**
27
+ For each finding:
28
+ - **Verify it's real**: Check for false positives in context (e.g., SQL injection warning on already-parameterized queries)
29
+ - **Classify severity**: Adjust based on reachability from user input, production vs test code, and compensating controls
30
+ - **Deduplicate** across tools
31
+ - **Map** each finding to the relevant manual audit phase (1-4)
32
+
33
+ **Step 4: Document tool coverage gaps**
34
+ Identify what's NOT covered (no secret scanning, no SAST, no dependency scanning, no IaC scanning, no container scanning). These gaps dictate where to focus manual effort.
35
+
36
+ **Step 5: Assess security tooling posture**
37
+ Document: Is there security scanning in CI/CD? Are results blocking merges or just informational? Are there documented exception allowlists? When was tooling config last reviewed?
38
+
39
+ ### Phase 1: Secrets & Sensitive Data Scan
40
+ Search the entire codebase (config files, scripts, test fixtures, git history) for:
41
+ - Hardcoded API keys, tokens, passwords, credentials, AWS access keys, database connection strings
42
+ - Private keys or certificates committed to the repo
43
+ - PII patterns in test data that look like real data
44
+ - `.env` files or similar that shouldn't be committed
45
+ - Check `.gitignore` for proper exclusion of sensitive file patterns
46
+
47
+ ### Phase 2: Auth & Permissions Audit
48
+ Map every route/endpoint and verify for each:
49
+ - Is authentication required? Should it be?
50
+ - Is authorization/role checking applied at the right level?
51
+ - Any IDOR vulnerabilities (accepting user/resource IDs without access verification)?
52
+
53
+ Check for: inconsistent auth middleware application, underprotected admin endpoints, JWT/session config issues (expiration, signing algorithm, secret strength), password hashing (bcrypt/argon2 vs MD5/SHA).
54
+
55
+ ### Phase 3: Common Vulnerability Scan
56
+ Search the codebase systematically for each pattern:
57
+
58
+ - **Injection**: SQL (string concatenation in queries), NoSQL, command (exec/spawn with user input), LDAP
59
+ - **XSS**: dangerouslySetInnerHTML, unescaped template outputs, innerHTML assignments
60
+ - **CSRF**: Missing tokens on state-changing endpoints, SameSite cookie config
61
+ - **Insecure Deserialization**: Unvalidated JSON.parse on user input, YAML.load with untrusted data, pickle/eval
62
+ - **SSRF**: User-controlled URLs fetched server-side without validation
63
+ - **Path Traversal**: File operations with user-supplied paths unsanitized
64
+ - **CORS**: Wildcard origins with credentials
65
+ - **Rate Limiting**: Auth endpoints without rate limiting
66
+ - **Security Headers**: Missing CSP, X-Frame-Options, HSTS, etc.
67
+ - **File Upload**: Missing type validation, size limits, executable uploads
68
+ - **Error Handling**: Stack traces or internal details in error responses
69
+
70
+ ### Phase 4A: Dependency Vulnerabilities
71
+ - Review dependency manifests (package.json, requirements.txt, Cargo.toml, go.mod, etc.)
72
+ - Run audit tools if not already run in Phase 0
73
+ - For each CVE: note severity, check if vulnerable code path is actually used, attempt upgrade on a branch, run tests, document results
74
+
75
+ ### Phase 4B: Supply Chain Attack Pattern Scan
76
+
77
+ Look for attack patterns that won't show up in `npm audit` — the things supply chain compromises actually use.
78
+
79
+ **Step 1: Post-install script audit**
80
+ Check every direct dependency for lifecycle scripts (preinstall, install, postinstall, prepare). For each: read the script, flag any that make network requests, read env vars, access filesystem broadly, or execute dynamic code. Check if install script restrictions are configured (e.g., `.npmrc` with `ignore-scripts=true`).
81
+
82
+ **Step 2: Typosquatting risk assessment**
83
+ Check each dependency name for typosquatting risk against well-known packages (character substitutions, misspellings, hyphen/underscore/scope variations). Verify legitimacy via web search and download counts.
84
+
85
+ **Step 3: Scope and namespace risks**
86
+ Check for: unscoped internal packages published publicly, references to scopes the team doesn't own, internal monorepo package names not registered on the public registry (dependency confusion risk), `.npmrc` or registry config mixing public and private registries.
87
+
88
+ **Step 4: Lock file integrity**
89
+ Verify: lock file is committed and current, all resolved URLs point to expected registries, no packages resolving to unexpected URLs/IPs, no missing integrity hashes. If git history available, check for lock file modifications without manifest changes.
90
+
91
+ **Step 5: Maintainer transfer and takeover signals**
92
+ For critical dependencies: check for recent ownership transfers, sudden releases after long inactivity, security advisories about compromised maintainer accounts. Use web search.
93
+
94
+ **Step 6: Transitive dependency risk**
95
+ Identify full dependency tree depth. Flag transitive deps with: extremely low download counts, single unmaintained maintainer, 3+ years stale, permissions beyond stated purpose.
96
+
97
+ ### Phase 5: Safe Fixes
98
+
99
+ Fix issues that are mechanical, well-understood, and verifiable. After EVERY fix, run the test suite. If tests break, revert immediately and move to "document only."
100
+
101
+ **Fix these (mechanical, low-risk):**
102
+ - **Hardcoded secrets** → environment variable references (add to `.env.example` with placeholders, don't rotate actual credentials)
103
+ - **SQL/NoSQL injection** → parameterized queries using existing DB library
104
+ - **XSS** → safe alternatives to dangerouslySetInnerHTML, output encoding/escaping
105
+ - **Missing CSRF tokens** → add via existing CSRF library/middleware (if none exists, document only)
106
+ - **CORS misconfiguration** → explicit allowed origins if determinable from codebase (otherwise document only)
107
+ - **Missing security headers** → CSP, X-Frame-Options, X-Content-Type-Options, HSTS, Referrer-Policy via existing middleware
108
+ - **Rate limiting on auth endpoints** → add if rate limiting library already exists (otherwise document only)
109
+ - **Error information leakage** → generic error messages in production, keep detailed logging server-side
110
+ - **Missing `.gitignore` entries** → add patterns for .env, private keys, credentials files
111
+ - **Insecure deserialization** → safe alternatives (JSON.parse, YAML.safeLoad, schema-validated)
112
+ - **Path traversal** → sanitize paths (strip `..`, resolve to allowed directory)
113
+ - **Install script restrictions** → add `.npmrc` config, document which packages need scripts and why
114
+ - **Lock file hygiene** → regenerate from clean state if integrity issues found
115
+ - **Dependency confusion prevention** → add scoping rules for private registry resolution
116
+ - **Security tool misconfigurations** → fix outdated rulesets, re-enable disabled rules, add to CI/CD
117
+
118
+ Commit each category separately: `security: fix [vulnerability type] in [module/scope]`
119
+
120
+ **Document only — do NOT fix:**
121
+ Auth flow changes, permission model changes, session/JWT configuration, password policy changes, encryption changes, architecture-level security changes, dependency replacements for supply chain risk, or anything where you're not confident in the correct behavior. **When in doubt, document rather than fix.** A documented vulnerability is inconvenient; a broken auth system at 3am is a disaster.
122
+
123
+ ### Phase 6: Report
124
+
125
+ Save as `audit-reports/08_SECURITY_AUDIT_REPORT_[run-number]_[date]_[time in user's local time].md` (create directory if needed, increment run number based on existing reports).
126
+
127
+ ### Report Structure
128
+ 1. **Executive Summary** — 3-5 sentences on overall security posture, including what was found AND fixed
129
+
130
+ 2. **Automated Security Scan Results**
131
+ - Tools discovered and run: | Tool | Version | Findings | Critical | High | Medium | Low | False Positives |
132
+ - Tools recommended but unavailable: | Tool | What It Catches | Effort to Add | Priority |
133
+ - Key verified findings: | Finding | Tool | Severity | File | Verified? | Addressed In Phase |
134
+ - Notable false positives (for future runs)
135
+ - Security CI/CD assessment: what runs automatically vs. what should
136
+
137
+ 3. **Fixes Applied** — everything fixed in Phase 5
138
+ - | Issue | Severity | Location | Fix Applied | Tests Pass? | Detected By |
139
+
140
+ 4. **Critical Findings (Unfixed)**
141
+ 5. **High Findings (Unfixed)**
142
+ 6. **Medium Findings (Unfixed)**
143
+ 7. **Low Findings (Unfixed)**
144
+ 8. **Informational**
145
+
146
+ 9. **Supply Chain Risk Assessment**
147
+ - Post-install scripts: | Package | Script Type | Behavior | Risk Level | Recommendation |
148
+ - Typosquatting risks: | Package | Similar To | Confidence | Evidence |
149
+ - Namespace/scope risks: | Package | Risk Type | Detail | Recommendation |
150
+ - Lock file integrity: pass/fail with anomaly details
151
+ - Maintainer risk: | Package | Concern | Evidence | Risk Level |
152
+ - Transitive dependency stats: total count, max depth, flagged packages
153
+
154
+ ### Finding Template (all findings, fixed and unfixed)
155
+ - **Title**, **Severity** (Critical/High/Medium/Low/Info), **Location** (file + line), **Description**, **Impact**, **Proof** (code snippet), **Recommendation** (with code example), **Detected By** (manual / [tool name] / both)
156
+
157
+ Additional fields for **unfixed** findings: **Why It Wasn't Fixed**, **Effort** (Quick fix / Moderate / Significant refactor)
158
+ Additional fields for **fixed** findings: **What was changed**, **Tests passing** (confirmation)
159
+
160
+ ## Rules
161
+ - Work on branch `security-audit-[date]`. DO NOT push to main.
162
+ - Run full test suite after EVERY fix. If tests fail, revert IMMEDIATELY.
163
+ - If you find compromised credentials, flag as CRITICAL at the top regardless of everything else.
164
+ - Phase 5 fixes must be mechanical and verifiable. Judgment calls belong in the report.
165
+ - Security header defaults should be noted for team review (especially CSP).
166
+ - Don't pad the report — quality over quantity.
167
+ - When in doubt about severity, err higher. When in doubt about a fix, document instead.
168
+ - For supply chain findings: use web search to verify package legitimacy, check download counts, review maintainer history.
169
+ - Be thorough. Check every file. You have all night.
170
+
171
+ ## Chat Output Requirement
172
+
173
+ In addition to writing the full report file, you MUST print a summary directly in the conversation when you finish. Do not make the user open the report to get the highlights. The chat summary should include:
174
+
175
+ ### 1. Status Line
176
+ One sentence: what you did, how long it took, and whether all tests still pass.
177
+
178
+ ### 2. Key Findings
179
+ The most important things discovered — bugs, risks, wins, or surprises. Each bullet should be specific and actionable, not vague. Lead with severity or impact.
180
+
181
+ **Good:** "CRITICAL: No backup configuration found for the primary Postgres database — total data loss risk."
182
+ **Bad:** "Found some issues with backups."
183
+
184
+ ### 3. Changes Made (if applicable)
185
+ Bullet list of what was actually modified, added, or removed. Skip this section for read-only analysis runs.
186
+
187
+ ### 4. Recommendations
188
+
189
+ If there are legitimately beneficial recommendations worth pursuing right now, present them in a table. Do **not** force recommendations — if the audit surfaced no actionable improvements, simply state that no recommendations are warranted at this time and move on.
190
+
191
+ When recommendations exist, use this table format:
192
+
193
+ | # | Recommendation | Impact | Risk if Ignored | Worth Doing? | Details |
194
+ |---|---|---|---|---|---|
195
+ | *Sequential number* | *Short description (≤10 words)* | *What improves if addressed* | *Low / Medium / High / Critical* | *Yes / Probably / Only if time allows* | *1–3 sentences explaining the reasoning, context, or implementation guidance* |
196
+
197
+ Order rows by risk descending (Critical → High → Medium → Low). Be honest in the "Worth Doing?" column — not everything flagged is worth the engineering time. If a recommendation is marginal, say so.
198
+
199
+ ### 5. Report Location
200
+ State the full path to the detailed report file for deeper review.
201
+
202
+ ---
203
+
204
+ **Formatting rules for chat output:**
205
+ - Use markdown headers, bold for severity labels, and bullet points for scannability.
206
+ - Do not duplicate the full report contents — just the highlights and recommendations.
207
+ - If you made zero findings in a phase, say so in one line rather than omitting it silently.