@massu/core 0.4.2 → 0.6.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.
Files changed (125) hide show
  1. package/README.md +40 -0
  2. package/agents/massu-architecture-reviewer.md +104 -0
  3. package/agents/massu-blast-radius-analyzer.md +84 -0
  4. package/agents/massu-competitive-scorer.md +126 -0
  5. package/agents/massu-help-sync.md +73 -0
  6. package/agents/massu-migration-writer.md +94 -0
  7. package/agents/massu-output-scorer.md +87 -0
  8. package/agents/massu-pattern-reviewer.md +84 -0
  9. package/agents/massu-plan-auditor.md +170 -0
  10. package/agents/massu-schema-sync-verifier.md +70 -0
  11. package/agents/massu-security-reviewer.md +98 -0
  12. package/agents/massu-ux-reviewer.md +106 -0
  13. package/commands/_shared-preamble.md +53 -23
  14. package/commands/_shared-references/auto-learning-protocol.md +71 -0
  15. package/commands/_shared-references/blast-radius-protocol.md +76 -0
  16. package/commands/_shared-references/security-pre-screen.md +64 -0
  17. package/commands/_shared-references/test-first-protocol.md +87 -0
  18. package/commands/_shared-references/verification-table.md +52 -0
  19. package/commands/massu-article-review.md +343 -0
  20. package/commands/massu-autoresearch/references/eval-runner.md +84 -0
  21. package/commands/massu-autoresearch/references/safety-rails.md +125 -0
  22. package/commands/massu-autoresearch/references/scoring-protocol.md +151 -0
  23. package/commands/massu-autoresearch.md +258 -0
  24. package/commands/massu-batch.md +44 -12
  25. package/commands/massu-bearings.md +42 -8
  26. package/commands/massu-checkpoint.md +588 -0
  27. package/commands/massu-ci-fix.md +2 -2
  28. package/commands/massu-command-health.md +132 -0
  29. package/commands/massu-command-improve.md +232 -0
  30. package/commands/massu-commit.md +205 -44
  31. package/commands/massu-create-plan.md +239 -57
  32. package/commands/massu-data/references/common-queries.md +79 -0
  33. package/commands/massu-data/references/table-guide.md +50 -0
  34. package/commands/massu-data.md +66 -0
  35. package/commands/massu-dead-code.md +29 -34
  36. package/commands/massu-debug/references/auto-learning.md +61 -0
  37. package/commands/massu-debug/references/codegraph-tracing.md +80 -0
  38. package/commands/massu-debug/references/common-shortcuts.md +98 -0
  39. package/commands/massu-debug/references/investigation-phases.md +294 -0
  40. package/commands/massu-debug/references/report-format.md +107 -0
  41. package/commands/massu-debug.md +105 -386
  42. package/commands/massu-docs.md +1 -1
  43. package/commands/massu-full-audit.md +61 -0
  44. package/commands/massu-gap-enhancement-analyzer.md +276 -16
  45. package/commands/massu-golden-path/references/approval-points.md +216 -0
  46. package/commands/massu-golden-path/references/competitive-mode.md +273 -0
  47. package/commands/massu-golden-path/references/error-handling.md +121 -0
  48. package/commands/massu-golden-path/references/phase-0-requirements.md +53 -0
  49. package/commands/massu-golden-path/references/phase-1-plan-creation.md +168 -0
  50. package/commands/massu-golden-path/references/phase-2-implementation.md +397 -0
  51. package/commands/massu-golden-path/references/phase-2.5-gap-analyzer.md +156 -0
  52. package/commands/massu-golden-path/references/phase-3-simplify.md +40 -0
  53. package/commands/massu-golden-path/references/phase-4-commit.md +94 -0
  54. package/commands/massu-golden-path/references/phase-5-push.md +116 -0
  55. package/commands/massu-golden-path/references/phase-5.5-production-verify.md +170 -0
  56. package/commands/massu-golden-path/references/phase-6-completion.md +113 -0
  57. package/commands/massu-golden-path/references/qa-evaluator-spec.md +137 -0
  58. package/commands/massu-golden-path/references/sprint-contract-protocol.md +117 -0
  59. package/commands/massu-golden-path/references/vr-visual-calibration.md +73 -0
  60. package/commands/massu-golden-path.md +114 -848
  61. package/commands/massu-guide.md +72 -69
  62. package/commands/massu-hooks.md +27 -12
  63. package/commands/massu-hotfix.md +221 -144
  64. package/commands/massu-incident.md +49 -20
  65. package/commands/massu-infra-audit.md +187 -0
  66. package/commands/massu-learning-audit.md +211 -0
  67. package/commands/massu-loop/references/auto-learning.md +49 -0
  68. package/commands/massu-loop/references/checkpoint-audit.md +40 -0
  69. package/commands/massu-loop/references/guardrails.md +17 -0
  70. package/commands/massu-loop/references/iteration-structure.md +115 -0
  71. package/commands/massu-loop/references/loop-controller.md +188 -0
  72. package/commands/massu-loop/references/plan-extraction.md +78 -0
  73. package/commands/massu-loop/references/vr-plan-spec.md +140 -0
  74. package/commands/massu-loop-playwright.md +9 -9
  75. package/commands/massu-loop.md +115 -670
  76. package/commands/massu-new-pattern.md +423 -0
  77. package/commands/massu-perf.md +422 -0
  78. package/commands/massu-plan-audit.md +1 -1
  79. package/commands/massu-plan.md +389 -122
  80. package/commands/massu-production-verify.md +433 -0
  81. package/commands/massu-push.md +62 -378
  82. package/commands/massu-recap.md +29 -3
  83. package/commands/massu-rollback.md +613 -0
  84. package/commands/massu-scaffold-hook.md +2 -4
  85. package/commands/massu-scaffold-page.md +2 -3
  86. package/commands/massu-scaffold-router.md +1 -2
  87. package/commands/massu-security.md +619 -0
  88. package/commands/massu-simplify.md +115 -85
  89. package/commands/massu-squirrels.md +2 -2
  90. package/commands/massu-tdd.md +38 -22
  91. package/commands/massu-test.md +3 -3
  92. package/commands/massu-type-mismatch-audit.md +469 -0
  93. package/commands/massu-ui-audit.md +587 -0
  94. package/commands/massu-verify-playwright.md +287 -32
  95. package/commands/massu-verify.md +150 -46
  96. package/dist/cli.js +1451 -1047
  97. package/dist/hooks/post-tool-use.js +75 -6
  98. package/dist/hooks/user-prompt.js +16 -0
  99. package/package.json +6 -2
  100. package/patterns/build-patterns.md +302 -0
  101. package/patterns/component-patterns.md +246 -0
  102. package/patterns/display-patterns.md +185 -0
  103. package/patterns/form-patterns.md +890 -0
  104. package/patterns/integration-testing-checklist.md +445 -0
  105. package/patterns/security-patterns.md +219 -0
  106. package/patterns/testing-patterns.md +569 -0
  107. package/patterns/tool-routing.md +81 -0
  108. package/patterns/ui-patterns.md +371 -0
  109. package/protocols/plan-implementation.md +267 -0
  110. package/protocols/recovery.md +225 -0
  111. package/protocols/verification.md +404 -0
  112. package/reference/command-taxonomy.md +178 -0
  113. package/reference/cr-rules-reference.md +76 -0
  114. package/reference/hook-execution-order.md +148 -0
  115. package/reference/lessons-learned.md +175 -0
  116. package/reference/patterns-quickref.md +208 -0
  117. package/reference/standards.md +135 -0
  118. package/reference/subagents-reference.md +17 -0
  119. package/reference/vr-verification-reference.md +867 -0
  120. package/src/commands/init.ts +27 -0
  121. package/src/commands/install-commands.ts +149 -53
  122. package/src/hooks/post-tool-use.ts +17 -0
  123. package/src/hooks/user-prompt.ts +21 -0
  124. package/src/memory-file-ingest.ts +127 -0
  125. package/src/memory-tools.ts +34 -1
@@ -0,0 +1,619 @@
1
+ ---
2
+ name: massu-security
3
+ description: "When user says 'security audit', 'check security', 'RLS audit', 'XSS check', or needs a focused security review covering auth, secrets, injection, and OWASP top 10"
4
+ allowed-tools: Bash(*), Read(*), Grep(*), Glob(*), mcp__supabase__DEV__*, mcp__supabase__NEW_PROD__*, mcp__supabase__OLD_PROD__*
5
+ disable-model-invocation: true
6
+ ---
7
+ name: massu-security
8
+
9
+ > **Shared rules apply.** Read `.claude/commands/_shared-preamble.md` before proceeding. CR-14, CR-5, CR-12 enforced.
10
+
11
+ # Massu Security: Comprehensive Security Audit
12
+
13
+ ## Objective
14
+
15
+ Execute a thorough security audit covering authentication, authorization, data protection, and common vulnerabilities. **Zero tolerance for security gaps.**
16
+
17
+ ---
18
+
19
+ ## NON-NEGOTIABLE RULES
20
+
21
+ - **No secrets in code** - Environment variables only
22
+ - **No secrets in git** - Check every commit
23
+ - **Protected mutations** - ALL mutations use protectedProcedure
24
+ - **RLS on all tables** - Policies AND grants required
25
+ - **Input validation** - Zod schemas on all inputs
26
+ - **No prototype pollution** - Never use `prototype` as object key
27
+ - **Proof required** - Show grep/query output as evidence
28
+ - **FIX ALL ISSUES ENCOUNTERED (CR-9)** - If ANY issue is discovered during security audit - whether from current changes OR pre-existing - fix it immediately. "Not in scope" and "pre-existing" are NEVER valid reasons to skip a fix. When fixing a bug, search entire codebase for same pattern and fix ALL instances.
29
+
30
+ ---
31
+
32
+ ## ZERO-GAP AUDIT LOOP
33
+
34
+ **This security audit does NOT complete until a SINGLE COMPLETE AUDIT finds ZERO issues.**
35
+
36
+ ### The Rule
37
+
38
+ ```
39
+ SECURITY AUDIT LOOP:
40
+ 1. Run ALL security checks (all sections)
41
+ 2. Count total security issues found
42
+ 3. IF issues > 0:
43
+ - Fix ALL issues
44
+ - Re-run ENTIRE audit from Step 1
45
+ 4. IF issues == 0:
46
+ - SECURITY CERTIFIED
47
+ ```
48
+
49
+ ### Completion Requirement
50
+
51
+ | Scenario | Action |
52
+ |----------|--------|
53
+ | Audit finds 3 vulnerabilities | Fix all 3, re-run ENTIRE audit |
54
+ | Re-audit finds 1 issue | Fix it, re-run ENTIRE audit |
55
+ | Re-audit finds 0 issues | **NOW** security passes |
56
+
57
+ **Partial re-checks are NOT valid. The ENTIRE security audit must pass in a SINGLE run.**
58
+
59
+ ---
60
+
61
+ ## SECURITY SEVERITY LEVELS
62
+
63
+ | Level | Definition | Action |
64
+ |-------|------------|--------|
65
+ | **CRITICAL** | Immediate exploitation risk | HARD STOP - Fix immediately |
66
+ | **HIGH** | Significant vulnerability | Block deployment until fixed |
67
+ | **MEDIUM** | Potential weakness | Fix before next release |
68
+ | **LOW** | Best practice violation | Track for future fix |
69
+
70
+ ---
71
+
72
+ ## SUPABASE ENVIRONMENTS
73
+
74
+ | Environment | Project ID | MCP Tool Prefix |
75
+ |-------------|------------|-----------------|
76
+ | DEV | `gwqkbjymbarkufwvdmar` | `mcp__supabase__DEV__` |
77
+ | OLD PROD | `hwaxogapihsqleyzpqtj` | `mcp__supabase__OLD_PROD__` |
78
+ | NEW PROD | `cnfxxvrhhvjefyvpoqlq` | `mcp__supabase__NEW_PROD__` |
79
+
80
+ ---
81
+
82
+ ## DOMAIN-SPECIFIC PATTERN LOADING
83
+
84
+ | Domain | Pattern File | Load When |
85
+ |--------|--------------|-----------|
86
+ | Auth vulnerabilities | `.claude/patterns/auth-patterns.md` | Always for security audit |
87
+ | Database security | `.claude/patterns/database-patterns.md` | RLS/grants audit |
88
+ | Build security | `.claude/patterns/build-patterns.md` | Dependency vulnerabilities |
89
+
90
+ ---
91
+
92
+ ## AUDIT SECTION 1: SECRETS & CREDENTIALS
93
+
94
+ ### 1.1 Secrets in Repository
95
+ ```bash
96
+ # Check for .env files in git history
97
+ git log --all --full-history -- "*.env*" | head -20
98
+
99
+ # Check for staged secret files
100
+ git diff --cached --name-only | grep -E '\.(env|pem|key|secret|credentials)'
101
+ # Expected: 0 files
102
+
103
+ # Check .gitignore has proper patterns
104
+ grep -n "\.env" .gitignore
105
+ grep -n "\.pem" .gitignore
106
+ grep -n "\.key" .gitignore
107
+ grep -n "secret" .gitignore
108
+
109
+ # Find any .env files (should only be .env.example)
110
+ find . -name ".env*" -not -name ".env.example" -not -path "./node_modules/*" 2>/dev/null
111
+ # Expected: 0 files (or only local untracked)
112
+ ```
113
+
114
+ ### 1.2 Hardcoded Credentials
115
+ ```bash
116
+ # API keys in code
117
+ grep -rn "sk-\|pk_\|api_key.*=.*['\"]" --include="*.ts" --include="*.tsx" src/ | grep -v "process.env" | wc -l
118
+ # Expected: 0
119
+
120
+ # Password patterns
121
+ grep -rn "password.*=.*['\"]" --include="*.ts" --include="*.tsx" src/ | grep -v "process.env\|type\|schema\|zod" | wc -l
122
+ # Expected: 0
123
+
124
+ # Connection strings
125
+ grep -rn "postgresql://\|mysql://\|mongodb://" --include="*.ts" --include="*.tsx" src/ | grep -v "process.env" | wc -l
126
+ # Expected: 0
127
+
128
+ # AWS/GCP/Azure credentials
129
+ grep -rn "AKIA\|GOOG\|AZURE" --include="*.ts" --include="*.tsx" src/ | wc -l
130
+ # Expected: 0
131
+
132
+ # JWT secrets
133
+ grep -rn "jwt.*secret\|JWT.*SECRET" --include="*.ts" --include="*.tsx" src/ | grep -v "process.env" | wc -l
134
+ # Expected: 0
135
+ ```
136
+
137
+ ### 1.3 Environment Variable Audit
138
+ ```bash
139
+ # List all env vars used
140
+ grep -rn "process.env\." src/ | grep -v node_modules | grep -oP 'process\.env\.\w+' | sort -u
141
+
142
+ # Verify all are documented
143
+ cat .env.example 2>/dev/null | grep -v "^#" | cut -d= -f1 | sort
144
+
145
+ # Check for NEXT_PUBLIC_ exposure (should be intentional)
146
+ grep -rn "NEXT_PUBLIC_" src/ | grep -v node_modules | grep -oP 'NEXT_PUBLIC_\w+' | sort -u
147
+ ```
148
+
149
+ **Secrets Audit Matrix:**
150
+ ```markdown
151
+ | Check | Expected | Actual | Status |
152
+ |-------|----------|--------|--------|
153
+ | .env files in git | 0 | | PASS/FAIL |
154
+ | Hardcoded API keys | 0 | | PASS/FAIL |
155
+ | Hardcoded passwords | 0 | | PASS/FAIL |
156
+ | Connection strings | 0 | | PASS/FAIL |
157
+ | .gitignore patterns | Present | | PASS/FAIL |
158
+ ```
159
+
160
+ ---
161
+
162
+ ## AUDIT SECTION 2: AUTHENTICATION
163
+
164
+ ### 2.1 Session Management
165
+ ```bash
166
+ # Check session configuration
167
+ grep -rn "session\|Session" src/lib/auth/ src/server/auth/ 2>/dev/null | head -20
168
+
169
+ # Check for session token exposure
170
+ grep -rn "session.*token\|accessToken\|refreshToken" src/ | grep -v node_modules | grep -v "\.d\.ts"
171
+
172
+ # Verify secure cookie settings
173
+ grep -rn "httpOnly\|secure\|sameSite" src/ | grep -v node_modules
174
+ ```
175
+
176
+ ### 2.2 Authentication Flow
177
+ ```bash
178
+ # Find all auth-related code
179
+ find src -name "*auth*" -o -name "*login*" -o -name "*session*" 2>/dev/null | grep -v node_modules
180
+
181
+ # Check for proper auth guards
182
+ grep -rn "getServerSession\|useSession\|protectedProcedure" src/app/ src/server/ | head -30
183
+
184
+ # Verify middleware auth checks
185
+ grep -A 30 "middleware" src/middleware.ts 2>/dev/null
186
+ ```
187
+
188
+ ### 2.3 Protected Routes
189
+ ```bash
190
+ # Check middleware protected routes
191
+ grep -A 20 "protectedRoutes\|matcher" src/middleware.ts
192
+
193
+ # Find pages without auth checks (potential issues)
194
+ find src/app -name "page.tsx" -exec grep -L "getServerSession\|useSession\|redirect" {} \;
195
+ ```
196
+
197
+ ---
198
+
199
+ ## AUDIT SECTION 3: AUTHORIZATION (tRPC)
200
+
201
+ ### 3.1 Procedure Protection (CRITICAL)
202
+ ```bash
203
+ # Find ALL mutations
204
+ grep -rn "\.mutation" src/server/api/routers/ | wc -l
205
+
206
+ # Find public mutations (SECURITY VIOLATION)
207
+ grep -rn "publicProcedure\.mutation" src/server/api/routers/
208
+ # Expected: 0 matches - ALL mutations must be protected
209
+
210
+ # Find protected mutations (correct)
211
+ grep -rn "protectedProcedure\.mutation" src/server/api/routers/ | wc -l
212
+
213
+ # Verify ratio
214
+ echo "All mutations should use protectedProcedure"
215
+ ```
216
+
217
+ ### 3.2 Input Validation
218
+ ```bash
219
+ # Find procedures without input validation
220
+ grep -rn "protectedProcedure\|publicProcedure" src/server/api/routers/ | grep -v "\.input("
221
+ # Review these - may be acceptable for queries with no params
222
+
223
+ # Find all input schemas
224
+ grep -rn "\.input(z\." src/server/api/routers/ | wc -l
225
+
226
+ # Check for raw input usage (bypassing validation)
227
+ grep -rn "input\." src/server/api/routers/ | grep -v "input:" | head -20
228
+ ```
229
+
230
+ ### 3.3 User Context Verification
231
+ ```bash
232
+ # Verify ctx.user.id usage (not client-provided)
233
+ grep -rn "ctx\.user\.id\|ctx\.session\.user" src/server/api/routers/ | wc -l
234
+
235
+ # Check for user ID from input (potential vulnerability)
236
+ grep -rn "input\.userId\|input\.user_id" src/server/api/routers/
237
+ # Review these - should use ctx.user.id instead
238
+ ```
239
+
240
+ **Authorization Audit Matrix:**
241
+ ```markdown
242
+ | Check | Expected | Actual | Status |
243
+ |-------|----------|--------|--------|
244
+ | publicProcedure.mutation | 0 | | PASS/FAIL |
245
+ | All mutations protected | 100% | | PASS/FAIL |
246
+ | Input validation | All procedures | | PASS/FAIL |
247
+ | ctx.user.id usage | Yes | | PASS/FAIL |
248
+ ```
249
+
250
+ ---
251
+
252
+ ## AUDIT SECTION 4: DATABASE SECURITY (RLS)
253
+
254
+ ### 4.1 RLS Status Check
255
+ For EACH user-facing table in ALL 3 environments:
256
+
257
+ ```sql
258
+ -- Check RLS enabled
259
+ SELECT tablename, rowsecurity
260
+ FROM pg_tables t
261
+ JOIN pg_class c ON c.relname = t.tablename
262
+ WHERE schemaname = 'public' AND relrowsecurity = true;
263
+
264
+ -- Tables WITHOUT RLS (potential issue)
265
+ SELECT tablename
266
+ FROM pg_tables t
267
+ JOIN pg_class c ON c.relname = t.tablename
268
+ WHERE schemaname = 'public' AND relrowsecurity = false;
269
+ ```
270
+
271
+ ### 4.2 Policy Completeness
272
+ ```sql
273
+ -- All policies
274
+ SELECT tablename, polname, polcmd
275
+ FROM pg_policies
276
+ WHERE schemaname = 'public'
277
+ ORDER BY tablename, polname;
278
+
279
+ -- Tables with policies
280
+ SELECT DISTINCT tablename FROM pg_policies WHERE schemaname = 'public';
281
+
282
+ -- Check for service_role policies (CRITICAL)
283
+ SELECT tablename, polname
284
+ FROM pg_policies
285
+ WHERE polname LIKE '%service%' OR polroles::text LIKE '%service_role%';
286
+ ```
287
+
288
+ ### 4.3 Grants Verification
289
+ ```sql
290
+ -- service_role grants (MUST exist)
291
+ SELECT table_name, privilege_type
292
+ FROM information_schema.table_privileges
293
+ WHERE grantee = 'service_role' AND table_schema = 'public';
294
+
295
+ -- authenticated grants
296
+ SELECT table_name, privilege_type
297
+ FROM information_schema.table_privileges
298
+ WHERE grantee = 'authenticated' AND table_schema = 'public';
299
+
300
+ -- anon grants (should be minimal)
301
+ SELECT table_name, privilege_type
302
+ FROM information_schema.table_privileges
303
+ WHERE grantee = 'anon' AND table_schema = 'public';
304
+ ```
305
+
306
+ **RLS Audit Matrix:**
307
+ ```markdown
308
+ | Table | RLS Enabled | Policies | service_role Grant | Status |
309
+ |-------|-------------|----------|-------------------|--------|
310
+ | [table1] | YES/NO | N | YES/NO | PASS/FAIL |
311
+ | [table2] | YES/NO | N | YES/NO | PASS/FAIL |
312
+ ```
313
+
314
+ ---
315
+
316
+ ## AUDIT SECTION 5: INJECTION VULNERABILITIES
317
+
318
+ ### 5.1 SQL Injection
319
+ ```bash
320
+ # Find raw SQL (potential injection)
321
+ grep -rn "\.raw\|\.unsafe\|\$queryRaw\|sql\`" src/server/ | grep -v node_modules
322
+ # Review each - ensure no user input concatenation
323
+
324
+ # Find string concatenation in queries
325
+ grep -rn "\${.*}" src/server/ | grep -i "select\|insert\|update\|delete" | head -20
326
+ # Review for SQL injection
327
+
328
+ # Check for parameterized queries (correct)
329
+ grep -rn "\\$1\|\\$2\|\\?" src/server/ | grep -i "sql" | head -10
330
+ ```
331
+
332
+ ### 5.2 XSS Prevention
333
+ ```bash
334
+ # Find dangerouslySetInnerHTML
335
+ grep -rn "dangerouslySetInnerHTML" src/
336
+ # Review each - ensure content is sanitized
337
+
338
+ # Find innerHTML assignments
339
+ grep -rn "\.innerHTML\s*=" src/ | grep -v node_modules
340
+
341
+ # Check for URL parameters in renders
342
+ grep -rn "searchParams\|query\." src/app/ | grep -v "\.d\.ts"
343
+ ```
344
+
345
+ ### 5.3 Prototype Pollution (CLAUDE.md Critical)
346
+ ```bash
347
+ # Check for prototype as object key
348
+ grep -rn "prototype:" src/ | grep -v "Object.prototype" | wc -l
349
+ # Expected: 0 (CRITICAL violation)
350
+
351
+ # Check for __proto__
352
+ grep -rn "__proto__" src/ | wc -l
353
+ # Expected: 0
354
+ ```
355
+
356
+ ### 5.4 Command Injection
357
+ ```bash
358
+ # Find exec/spawn calls
359
+ grep -rn "exec(\|spawn(\|execSync\|spawnSync" src/ | grep -v node_modules
360
+
361
+ # Find eval usage
362
+ grep -rn "eval(\|new Function(" src/ | grep -v node_modules
363
+ # Expected: 0
364
+ ```
365
+
366
+ ---
367
+
368
+ ## AUDIT SECTION 6: DATA EXPOSURE
369
+
370
+ ### 6.1 Sensitive Data Logging
371
+ ```bash
372
+ # Find console.log with potential sensitive data
373
+ grep -rn "console\.log.*password\|console\.log.*token\|console\.log.*secret" src/
374
+ # Expected: 0
375
+
376
+ # Find error logging with full objects
377
+ grep -rn "console\.error.*error\)" src/ | head -20
378
+ # Review - should not expose stack traces in production
379
+ ```
380
+
381
+ ### 6.2 API Response Exposure
382
+ ```bash
383
+ # Check for password fields in returns
384
+ grep -rn "return.*password\|password.*:" src/server/api/routers/ | grep -v "schema\|zod\|input"
385
+
386
+ # Check for sensitive fields in types
387
+ grep -rn "password\|secret\|token" src/types/ src/server/api/
388
+ ```
389
+
390
+ ### 6.3 Client-Side Exposure
391
+ ```bash
392
+ # Check for server imports in client
393
+ grep -rn "from.*@/lib/db\|from.*prisma" src/app/ src/components/ | grep -v "server"
394
+ # Expected: 0 (causes PrismaClient to bundle)
395
+
396
+ # NEXT_PUBLIC exposure check
397
+ grep -rn "NEXT_PUBLIC_" src/ | grep -v node_modules | grep -oP 'NEXT_PUBLIC_\w+' | sort -u
398
+ # Review - only public-safe values should be exposed
399
+ ```
400
+
401
+ ---
402
+
403
+ ## AUDIT SECTION 7: ADDITIONAL CHECKS
404
+
405
+ ### 7.1 CORS Configuration
406
+ ```bash
407
+ # Find CORS settings
408
+ grep -rn "cors\|CORS\|Access-Control" src/ next.config.* | grep -v node_modules
409
+ ```
410
+
411
+ ### 7.2 Rate Limiting
412
+ ```bash
413
+ # Check for rate limiting
414
+ grep -rn "rateLimit\|rateLimiter\|throttle" src/
415
+ ```
416
+
417
+ ### 7.3 HTTPS Enforcement
418
+ ```bash
419
+ # Check for HTTP URLs (should be HTTPS)
420
+ grep -rn "http://" src/ | grep -v "localhost\|127.0.0.1\|http://\*" | grep -v node_modules
421
+ ```
422
+
423
+ ### 7.4 Dependency Vulnerabilities
424
+ ```bash
425
+ # Run npm audit
426
+ npm audit --production
427
+
428
+ # Check for critical vulnerabilities
429
+ npm audit --production --json | grep -i "critical\|high"
430
+ ```
431
+
432
+ ---
433
+
434
+ ## SECURITY REPORT FORMAT
435
+
436
+ ```markdown
437
+ ## MASSU SECURITY AUDIT REPORT
438
+
439
+ ### Audit Summary
440
+ - **Date**: [timestamp]
441
+ - **Scope**: Full security audit
442
+ - **Critical Issues**: [N]
443
+ - **High Issues**: [N]
444
+ - **Medium Issues**: [N]
445
+ - **Low Issues**: [N]
446
+
447
+ ---
448
+
449
+ ### Section 1: Secrets & Credentials
450
+ | Check | Result | Status |
451
+ |-------|--------|--------|
452
+ | Secrets in git | 0 files | PASS |
453
+ | Hardcoded credentials | 0 matches | PASS |
454
+ | .gitignore patterns | Complete | PASS |
455
+
456
+ ### Section 2: Authentication
457
+ | Check | Result | Status |
458
+ |-------|--------|--------|
459
+ | Session security | [details] | PASS/FAIL |
460
+ | Auth guards | Present | PASS |
461
+ | Protected routes | [N] routes | PASS |
462
+
463
+ ### Section 3: Authorization (tRPC)
464
+ | Check | Result | Status |
465
+ |-------|--------|--------|
466
+ | publicProcedure.mutation | 0 | PASS |
467
+ | Input validation | 100% | PASS |
468
+ | ctx.user.id usage | Yes | PASS |
469
+
470
+ ### Section 4: Database Security (RLS)
471
+ | Environment | Tables with RLS | Policies | service_role Grants |
472
+ |-------------|-----------------|----------|---------------------|
473
+ | DEV | N/N | N | YES |
474
+ | OLD PROD | N/N | N | YES |
475
+ | NEW PROD | N/N | N | YES |
476
+
477
+ ### Section 5: Injection Prevention
478
+ | Check | Result | Status |
479
+ |-------|--------|--------|
480
+ | SQL injection risks | 0 | PASS |
481
+ | XSS risks | 0 | PASS |
482
+ | Prototype pollution | 0 | PASS |
483
+ | Command injection | 0 | PASS |
484
+
485
+ ### Section 6: Data Exposure
486
+ | Check | Result | Status |
487
+ |-------|--------|--------|
488
+ | Sensitive logging | 0 | PASS |
489
+ | API response exposure | 0 | PASS |
490
+ | Client-side leaks | 0 | PASS |
491
+
492
+ ### Section 7: Additional
493
+ | Check | Result | Status |
494
+ |-------|--------|--------|
495
+ | npm audit (critical/high) | 0 | PASS |
496
+ | HTTPS enforcement | Yes | PASS |
497
+
498
+ ---
499
+
500
+ ### Issues Found
501
+
502
+ #### CRITICAL
503
+ [List or "None"]
504
+
505
+ #### HIGH
506
+ [List or "None"]
507
+
508
+ #### MEDIUM
509
+ [List or "None"]
510
+
511
+ #### LOW
512
+ [List or "None"]
513
+
514
+ ---
515
+
516
+ ### Remediation Plan
517
+ | Issue | Fix | Priority | Assignee |
518
+ |-------|-----|----------|----------|
519
+ | [issue] | [fix] | [P0/P1/P2] | [who] |
520
+
521
+ ---
522
+
523
+ **SECURITY AUDIT: PASSED / FAILED**
524
+ **Deployment Allowed: YES / NO**
525
+ ```
526
+
527
+ ---
528
+
529
+ ## SESSION STATE UPDATE
530
+
531
+ After audit, update `session-state/CURRENT.md`:
532
+
533
+ ```markdown
534
+ ## SECURITY AUDIT SESSION
535
+
536
+ ### Audit
537
+ - **Date**: [timestamp]
538
+ - **Type**: Full security audit
539
+ - **Result**: PASSED / FAILED
540
+
541
+ ### Findings
542
+ - Critical: [N]
543
+ - High: [N]
544
+ - Medium: [N]
545
+ - Low: [N]
546
+
547
+ ### Fixes Applied
548
+ [List fixes if any]
549
+
550
+ ### Deployment Status
551
+ [Cleared / Blocked]
552
+ ```
553
+
554
+ ---
555
+
556
+ ## START NOW
557
+
558
+ 1. Run Section 1: Secrets & Credentials
559
+ 2. Run Section 2: Authentication
560
+ 3. Run Section 3: Authorization (tRPC)
561
+ 4. Run Section 4: Database Security (all 3 envs)
562
+ 5. Run Section 5: Injection Vulnerabilities
563
+ 6. Run Section 6: Data Exposure
564
+ 7. Run Section 7: Additional Checks
565
+ 8. Compile findings by severity
566
+ 9. Create remediation plan for any issues
567
+ 10. Run VR-COUPLING check (backend-frontend sync)
568
+ 11. Produce security report
569
+ 12. Update session state
570
+
571
+ ---
572
+
573
+ ## VR-COUPLING VERIFICATION (Added Jan 2026)
574
+
575
+ Security features in backend must be visible/accessible in UI:
576
+
577
+ ```bash
578
+ ./scripts/check-coupling.sh
579
+ # Expected: Exit 0 - all backend features exposed in UI
580
+ ```
581
+
582
+ **Why this matters**: Backend security features (like permission levels, access controls) that aren't exposed in UI leave users unable to configure security properly.
583
+
584
+ ---
585
+
586
+ ## AUTO-LEARNING PROTOCOL (MANDATORY after every fix/finding)
587
+
588
+ **After EVERY fix or finding, the system MUST automatically learn. This is NOT optional.**
589
+
590
+ ### Step 1: Ingest into Memory
591
+ Use `mcp__massu-codegraph__massu_memory_ingest` with type="bugfix"|"pattern", description of what was found/fixed, affected files, and importance (5=security/data, 3=build/type, 2=cosmetic).
592
+
593
+ ### Step 2: Record Correct vs Incorrect Pattern
594
+ Update `memory/MEMORY.md` with the WRONG vs CORRECT pattern discovered.
595
+
596
+ ### Step 3: Add to Pattern Scanner (if grep-able)
597
+ If the bad pattern is detectable by grep, add check to `scripts/pattern-scanner.sh`.
598
+
599
+ ### Step 4: Search Codebase-Wide (CR-9)
600
+ `grep -rn "[bad_pattern]" src/` - fix ALL instances of the same issue.
601
+
602
+ ---
603
+
604
+ **Remember: Zero tolerance for CRITICAL and HIGH issues. Block deployment until fixed.**
605
+
606
+ ---
607
+
608
+ ## Related Audit Commands
609
+
610
+ | Command | Focus | Overlap | When to Use Instead |
611
+ |---------|-------|---------|---------------------|
612
+ | /massu-codebase-audit | Full 20-phase audit | Covers security basics | Comprehensive review |
613
+ | /massu-security | Security deep-dive | Auth, RLS, XSS | Security-focused work |
614
+ | /massu-db-audit | Database integrity | Schema, RLS, stored procs | Database changes |
615
+ | /massu-extended-audit | E2E, load, deps, GDPR | Extended coverage | Pre-release |
616
+ | /massu-learning-audit | Auto-learning effectiveness | Memory, scanner coverage | Post-incident |
617
+ | /massu-import-audit | Import chains, build safety | CR-16/17/19 | Build issues |
618
+ | /massu-config-audit | Config-code alignment | CR-22/29 | Config bugs |
619
+ | /massu-feature-audit | Sentinel feature coverage | CR-32 | Feature gaps |