trinity-method-sdk 2.0.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 (191) hide show
  1. package/CHANGELOG.md +116 -0
  2. package/LICENSE +21 -0
  3. package/README.md +555 -0
  4. package/dist/cli/commands/deploy/agents.d.ts +14 -0
  5. package/dist/cli/commands/deploy/agents.js +59 -0
  6. package/dist/cli/commands/deploy/ci-cd.d.ts +13 -0
  7. package/dist/cli/commands/deploy/ci-cd.js +50 -0
  8. package/dist/cli/commands/deploy/claude-setup.d.ts +17 -0
  9. package/dist/cli/commands/deploy/claude-setup.js +91 -0
  10. package/dist/cli/commands/deploy/configuration.d.ts +13 -0
  11. package/dist/cli/commands/deploy/configuration.js +215 -0
  12. package/dist/cli/commands/deploy/directories.d.ts +12 -0
  13. package/dist/cli/commands/deploy/directories.js +38 -0
  14. package/dist/cli/commands/deploy/gitignore.d.ts +12 -0
  15. package/dist/cli/commands/deploy/gitignore.js +53 -0
  16. package/dist/cli/commands/deploy/index.d.ts +38 -0
  17. package/dist/cli/commands/deploy/index.js +156 -0
  18. package/dist/cli/commands/deploy/knowledge-base.d.ts +16 -0
  19. package/dist/cli/commands/deploy/knowledge-base.js +75 -0
  20. package/dist/cli/commands/deploy/linting.d.ts +18 -0
  21. package/dist/cli/commands/deploy/linting.js +51 -0
  22. package/dist/cli/commands/deploy/metrics.d.ts +13 -0
  23. package/dist/cli/commands/deploy/metrics.js +34 -0
  24. package/dist/cli/commands/deploy/pre-flight.d.ts +13 -0
  25. package/dist/cli/commands/deploy/pre-flight.js +29 -0
  26. package/dist/cli/commands/deploy/root-files.d.ts +16 -0
  27. package/dist/cli/commands/deploy/root-files.js +178 -0
  28. package/dist/cli/commands/deploy/sdk-install.d.ts +12 -0
  29. package/dist/cli/commands/deploy/sdk-install.js +57 -0
  30. package/dist/cli/commands/deploy/summary.d.ts +14 -0
  31. package/dist/cli/commands/deploy/summary.js +130 -0
  32. package/dist/cli/commands/deploy/templates.d.ts +14 -0
  33. package/dist/cli/commands/deploy/templates.js +84 -0
  34. package/dist/cli/commands/deploy/types.d.ts +39 -0
  35. package/dist/cli/commands/deploy/types.js +5 -0
  36. package/dist/cli/commands/update/agents.d.ts +14 -0
  37. package/dist/cli/commands/update/agents.js +31 -0
  38. package/dist/cli/commands/update/backup.d.ts +31 -0
  39. package/dist/cli/commands/update/backup.js +97 -0
  40. package/dist/cli/commands/update/commands.d.ts +14 -0
  41. package/dist/cli/commands/update/commands.js +75 -0
  42. package/dist/cli/commands/update/index.d.ts +15 -0
  43. package/dist/cli/commands/update/index.js +118 -0
  44. package/dist/cli/commands/update/knowledge-base.d.ts +14 -0
  45. package/dist/cli/commands/update/knowledge-base.js +38 -0
  46. package/dist/cli/commands/update/pre-flight.d.ts +13 -0
  47. package/dist/cli/commands/update/pre-flight.js +37 -0
  48. package/dist/cli/commands/update/summary.d.ts +20 -0
  49. package/dist/cli/commands/update/summary.js +47 -0
  50. package/dist/cli/commands/update/templates.d.ts +14 -0
  51. package/dist/cli/commands/update/templates.js +25 -0
  52. package/dist/cli/commands/update/types.d.ts +13 -0
  53. package/dist/cli/commands/update/types.js +7 -0
  54. package/dist/cli/commands/update/utils.d.ts +11 -0
  55. package/dist/cli/commands/update/utils.js +19 -0
  56. package/dist/cli/commands/update/verification.d.ts +20 -0
  57. package/dist/cli/commands/update/verification.js +54 -0
  58. package/dist/cli/commands/update/version.d.ts +18 -0
  59. package/dist/cli/commands/update/version.js +36 -0
  60. package/dist/cli/commands/update.d.ts +7 -0
  61. package/dist/cli/commands/update.js +7 -0
  62. package/dist/cli/index.d.ts +3 -0
  63. package/dist/cli/index.js +36 -0
  64. package/dist/cli/types.d.ts +77 -0
  65. package/dist/cli/types.js +5 -0
  66. package/dist/cli/utils/deploy-ci.d.ts +22 -0
  67. package/dist/cli/utils/deploy-ci.js +138 -0
  68. package/dist/cli/utils/deploy-linting.d.ts +3 -0
  69. package/dist/cli/utils/deploy-linting.js +136 -0
  70. package/dist/cli/utils/detect-stack.d.ts +3 -0
  71. package/dist/cli/utils/detect-stack.js +270 -0
  72. package/dist/cli/utils/error-classes.d.ts +63 -0
  73. package/dist/cli/utils/error-classes.js +84 -0
  74. package/dist/cli/utils/error-handler.d.ts +59 -0
  75. package/dist/cli/utils/error-handler.js +127 -0
  76. package/dist/cli/utils/errors.d.ts +52 -0
  77. package/dist/cli/utils/errors.js +102 -0
  78. package/dist/cli/utils/get-sdk-path.d.ts +18 -0
  79. package/dist/cli/utils/get-sdk-path.js +31 -0
  80. package/dist/cli/utils/inject-dependencies.d.ts +2 -0
  81. package/dist/cli/utils/inject-dependencies.js +55 -0
  82. package/dist/cli/utils/linting-tools.d.ts +8 -0
  83. package/dist/cli/utils/linting-tools.js +206 -0
  84. package/dist/cli/utils/metrics/code-quality.d.ts +32 -0
  85. package/dist/cli/utils/metrics/code-quality.js +122 -0
  86. package/dist/cli/utils/metrics/dependency-parser.d.ts +21 -0
  87. package/dist/cli/utils/metrics/dependency-parser.js +153 -0
  88. package/dist/cli/utils/metrics/file-complexity.d.ts +26 -0
  89. package/dist/cli/utils/metrics/file-complexity.js +77 -0
  90. package/dist/cli/utils/metrics/framework-detector.d.ts +17 -0
  91. package/dist/cli/utils/metrics/framework-detector.js +120 -0
  92. package/dist/cli/utils/metrics/git-metrics.d.ts +30 -0
  93. package/dist/cli/utils/metrics/git-metrics.js +83 -0
  94. package/dist/cli/utils/metrics/index.d.ts +28 -0
  95. package/dist/cli/utils/metrics/index.js +100 -0
  96. package/dist/cli/utils/template-processor.d.ts +10 -0
  97. package/dist/cli/utils/template-processor.js +188 -0
  98. package/dist/cli/utils/validate-path.d.ts +80 -0
  99. package/dist/cli/utils/validate-path.js +180 -0
  100. package/dist/index.d.ts +6 -0
  101. package/dist/index.js +8 -0
  102. package/dist/templates/agents/aj-team/apo-documentation-specialist.md.template +572 -0
  103. package/dist/templates/agents/aj-team/bas-quality-gate.md.template +906 -0
  104. package/dist/templates/agents/aj-team/bon-dependency-manager.md.template +636 -0
  105. package/dist/templates/agents/aj-team/cap-configuration-specialist.md.template +670 -0
  106. package/dist/templates/agents/aj-team/dra-code-reviewer.md.template +768 -0
  107. package/dist/templates/agents/aj-team/kil-task-executor.md.template +764 -0
  108. package/dist/templates/agents/aj-team/uro-refactoring-specialist.md.template +759 -0
  109. package/dist/templates/agents/audit/juno-auditor.md.template +447 -0
  110. package/dist/templates/agents/deployment/ein-cicd.md.template +694 -0
  111. package/dist/templates/agents/deployment/ino-context.md.template +733 -0
  112. package/dist/templates/agents/deployment/tan-structure.md.template +661 -0
  113. package/dist/templates/agents/deployment/zen-knowledge.md.template +451 -0
  114. package/dist/templates/agents/leadership/aj-cc.md.template +462 -0
  115. package/dist/templates/agents/leadership/aj-maestro.md.template +943 -0
  116. package/dist/templates/agents/leadership/aly-cto.md.template +407 -0
  117. package/dist/templates/agents/planning/eus-decomposer.md.template +496 -0
  118. package/dist/templates/agents/planning/mon-requirements.md.template +323 -0
  119. package/dist/templates/agents/planning/ror-design.md.template +465 -0
  120. package/dist/templates/agents/planning/tra-planner.md.template +432 -0
  121. package/dist/templates/ci/cd.yml.template +175 -0
  122. package/dist/templates/ci/ci.yml.template +196 -0
  123. package/dist/templates/ci/generic-ci.yml +115 -0
  124. package/dist/templates/ci/github-actions.yml +86 -0
  125. package/dist/templates/ci/gitlab-ci.yml +103 -0
  126. package/dist/templates/claude/EMPLOYEE-DIRECTORY.md.template +545 -0
  127. package/dist/templates/documentation/ROOT-README.md.template +307 -0
  128. package/dist/templates/documentation/SUBDIRECTORY-README.md.template +261 -0
  129. package/dist/templates/investigations/bug.md.template +484 -0
  130. package/dist/templates/investigations/feature.md.template +564 -0
  131. package/dist/templates/investigations/performance.md.template +625 -0
  132. package/dist/templates/investigations/security.md.template +714 -0
  133. package/dist/templates/investigations/technical.md.template +433 -0
  134. package/dist/templates/knowledge-base/AI-DEVELOPMENT-GUIDE.md.template +957 -0
  135. package/dist/templates/knowledge-base/ARCHITECTURE.md.template +452 -0
  136. package/dist/templates/knowledge-base/CODING-PRINCIPLES.md.template +750 -0
  137. package/dist/templates/knowledge-base/DOCUMENTATION-CRITERIA.md.template +1118 -0
  138. package/dist/templates/knowledge-base/ISSUES.md.template +539 -0
  139. package/dist/templates/knowledge-base/TESTING-PRINCIPLES.md.template +894 -0
  140. package/dist/templates/knowledge-base/Technical-Debt.md.template +640 -0
  141. package/dist/templates/knowledge-base/To-do.md.template +407 -0
  142. package/dist/templates/knowledge-base/Trinity.md.template +464 -0
  143. package/dist/templates/linting/flutter/.pre-commit-config.yaml.template +27 -0
  144. package/dist/templates/linting/flutter/analysis_options.yaml.template +26 -0
  145. package/dist/templates/linting/nodejs/.eslintrc-commonjs.json.template +19 -0
  146. package/dist/templates/linting/nodejs/.eslintrc-esm.json.template +19 -0
  147. package/dist/templates/linting/nodejs/.eslintrc-typescript.json.template +22 -0
  148. package/dist/templates/linting/nodejs/.pre-commit-config.yaml.template +51 -0
  149. package/dist/templates/linting/nodejs/.prettierrc.json.template +10 -0
  150. package/dist/templates/linting/python/.flake8.template +16 -0
  151. package/dist/templates/linting/python/.pre-commit-config.yaml.template +30 -0
  152. package/dist/templates/linting/python/pyproject.toml.template +38 -0
  153. package/dist/templates/linting/rust/.pre-commit-config.yaml.template +28 -0
  154. package/dist/templates/linting/rust/clippy.toml.template +14 -0
  155. package/dist/templates/linting/rust/rustfmt.toml.template +12 -0
  156. package/dist/templates/root/CLAUDE.md.template +65 -0
  157. package/dist/templates/root/TRINITY.md.template +52 -0
  158. package/dist/templates/shared/claude-commands/trinity-agents.md.template +168 -0
  159. package/dist/templates/shared/claude-commands/trinity-audit.md.template +646 -0
  160. package/dist/templates/shared/claude-commands/trinity-changelog.md.template +624 -0
  161. package/dist/templates/shared/claude-commands/trinity-continue.md.template +549 -0
  162. package/dist/templates/shared/claude-commands/trinity-create-investigation.md.template +232 -0
  163. package/dist/templates/shared/claude-commands/trinity-decompose.md.template +181 -0
  164. package/dist/templates/shared/claude-commands/trinity-design.md.template +347 -0
  165. package/dist/templates/shared/claude-commands/trinity-docs.md.template +2093 -0
  166. package/dist/templates/shared/claude-commands/trinity-end.md.template +397 -0
  167. package/dist/templates/shared/claude-commands/trinity-init.md.template +606 -0
  168. package/dist/templates/shared/claude-commands/trinity-investigate-templates.md.template +725 -0
  169. package/dist/templates/shared/claude-commands/trinity-orchestrate.md.template +1061 -0
  170. package/dist/templates/shared/claude-commands/trinity-plan-investigation.md.template +135 -0
  171. package/dist/templates/shared/claude-commands/trinity-plan.md.template +201 -0
  172. package/dist/templates/shared/claude-commands/trinity-readme.md.template +1971 -0
  173. package/dist/templates/shared/claude-commands/trinity-requirements.md.template +148 -0
  174. package/dist/templates/shared/claude-commands/trinity-start.md.template +268 -0
  175. package/dist/templates/shared/claude-commands/trinity-verify.md.template +453 -0
  176. package/dist/templates/shared/claude-commands/trinity-workorder.md.template +249 -0
  177. package/dist/templates/source/base-CLAUDE.md.template +310 -0
  178. package/dist/templates/source/flutter-CLAUDE.md.template +593 -0
  179. package/dist/templates/source/nodejs-CLAUDE.md.template +531 -0
  180. package/dist/templates/source/python-CLAUDE.md.template +510 -0
  181. package/dist/templates/source/react-CLAUDE.md.template +513 -0
  182. package/dist/templates/source/rust-CLAUDE.md.template +653 -0
  183. package/dist/templates/source/tests-CLAUDE.md.template +432 -0
  184. package/dist/templates/trinity/CLAUDE.md.template +372 -0
  185. package/dist/templates/work-orders/ANALYSIS-TEMPLATE.md.template +276 -0
  186. package/dist/templates/work-orders/AUDIT-TEMPLATE.md.template +262 -0
  187. package/dist/templates/work-orders/IMPLEMENTATION-TEMPLATE.md.template +260 -0
  188. package/dist/templates/work-orders/INVESTIGATION-TEMPLATE.md.template +206 -0
  189. package/dist/templates/work-orders/PATTERN-TEMPLATE.md.template +320 -0
  190. package/dist/templates/work-orders/VERIFICATION-TEMPLATE.md.template +273 -0
  191. package/package.json +94 -0
@@ -0,0 +1,714 @@
1
+ # Security Investigation: {{title}}
2
+
3
+ **Investigation ID:** {{investigationId}}
4
+ **Created:** {{createdAt}}
5
+ **Investigator:** {{investigator}}
6
+ **Status:** {{status}}
7
+ **Priority:** {{priority}}
8
+ **Severity:** {{severity}}
9
+
10
+ ---
11
+
12
+ ## 🔒 Security Issue Summary
13
+
14
+ **Brief Description:**
15
+ {{description}}
16
+
17
+ **Vulnerability Type:**
18
+ - [ ] SQL Injection
19
+ - [ ] Cross-Site Scripting (XSS)
20
+ - [ ] Cross-Site Request Forgery (CSRF)
21
+ - [ ] Authentication/Authorization bypass
22
+ - [ ] Sensitive data exposure
23
+ - [ ] Dependency vulnerability
24
+ - [ ] Configuration issue
25
+ - [ ] Cryptographic failure
26
+ - [ ] Other: [specify]
27
+
28
+ **CVSS Score:** [0.0 - 10.0]
29
+ **CVSS Vector:** [CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H]
30
+
31
+ **Affected Components:**
32
+ -
33
+
34
+ **Attack Vector:**
35
+ - [ ] Network
36
+ - [ ] Adjacent Network
37
+ - [ ] Local
38
+ - [ ] Physical
39
+
40
+ **Attack Complexity:**
41
+ - [ ] Low
42
+ - [ ] High
43
+
44
+ **Privileges Required:**
45
+ - [ ] None
46
+ - [ ] Low
47
+ - [ ] High
48
+
49
+ ---
50
+
51
+ ## 🔍 Trinity Method Guided Questions
52
+
53
+ ### Vulnerability Discovery
54
+
55
+ **1. How was this discovered?**
56
+ - [ ] Security scan (tool: )
57
+ - [ ] Penetration test
58
+ - [ ] Bug bounty report
59
+ - [ ] Internal audit
60
+ - [ ] User report
61
+ - [ ] Incident response
62
+ - [ ] Dependency alert (Dependabot, Snyk)
63
+
64
+ **2. Is this being actively exploited?**
65
+ - [ ] Yes, active exploitation detected
66
+ - [ ] No evidence of exploitation
67
+ - [ ] Unknown
68
+
69
+ Evidence:
70
+
71
+ **3. When was the vulnerability introduced?**
72
+ - Date/Version:
73
+ - Git commit:
74
+ ```bash
75
+ git log --all -- path/to/vulnerable/file.ts
76
+ git blame path/to/vulnerable/file.ts
77
+ ```
78
+
79
+ ### Impact Assessment
80
+
81
+ **4. Confidentiality Impact**
82
+ - [ ] None - No data exposure
83
+ - [ ] Low - Minimal data exposure
84
+ - [ ] High - Sensitive data exposure
85
+
86
+ **What data could be exposed?**
87
+ -
88
+
89
+ **5. Integrity Impact**
90
+ - [ ] None - No data modification
91
+ - [ ] Low - Limited modification
92
+ - [ ] High - Unrestricted modification
93
+
94
+ **What could an attacker modify?**
95
+ -
96
+
97
+ **6. Availability Impact**
98
+ - [ ] None - No service disruption
99
+ - [ ] Low - Limited disruption
100
+ - [ ] High - Complete service denial
101
+
102
+ **What could an attacker disrupt?**
103
+ -
104
+
105
+ ### Scope Analysis
106
+
107
+ **7. Attack Prerequisites**
108
+ - What does an attacker need?
109
+ - [ ] No authentication required
110
+ - [ ] Valid user account
111
+ - [ ] Admin privileges
112
+ - [ ] Physical access
113
+ - [ ] Social engineering
114
+ - [ ] Other:
115
+
116
+ **8. Affected Systems**
117
+ - [ ] Production
118
+ - [ ] Staging
119
+ - [ ] Development
120
+ - [ ] All environments
121
+
122
+ - [ ] Web application
123
+ - [ ] API
124
+ - [ ] Database
125
+ - [ ] Infrastructure
126
+ - [ ] Third-party integration
127
+
128
+ **9. User Impact**
129
+ - How many users are affected?
130
+ - [ ] All users
131
+ - [ ] Subset of users (specify):
132
+ - [ ] Admin users only
133
+
134
+ ---
135
+
136
+ ## 🛡️ Vulnerability Details
137
+
138
+ ### Technical Description
139
+ [Detailed technical explanation of the vulnerability]
140
+
141
+ ### Proof of Concept (PoC)
142
+ ```http
143
+ # Example attack request
144
+ POST /api/endpoint HTTP/1.1
145
+ Host: example.com
146
+ Content-Type: application/json
147
+
148
+ {
149
+ "payload": "malicious input"
150
+ }
151
+ ```
152
+
153
+ **Attack Steps:**
154
+ 1.
155
+ 2.
156
+ 3.
157
+
158
+ **Expected Result (Vulnerable):**
159
+ [What happens when vulnerability is exploited]
160
+
161
+ **Expected Result (Patched):**
162
+ [What should happen after fix]
163
+
164
+ ### Code Analysis
165
+ **Vulnerable Code:**
166
+ ```typescript
167
+ // File: path/to/file.ts
168
+ // Line: XX
169
+ function vulnerableFunction(userInput) {
170
+ // Unsafe operation
171
+ db.query(`SELECT * FROM users WHERE id = ${userInput}`);
172
+ }
173
+ ```
174
+
175
+ **Why is this vulnerable?**
176
+ [Explanation]
177
+
178
+ ---
179
+
180
+ ## 🔬 Investigation Plan
181
+
182
+ ### Phase 1: Verify & Reproduce
183
+ **Goal:** Confirm vulnerability and understand exploitability
184
+
185
+ **Steps:**
186
+ 1. [ ] Review vulnerability report/CVE details
187
+ 2. [ ] Set up isolated test environment
188
+ 3. [ ] Reproduce vulnerability with PoC
189
+ 4. [ ] Document attack vector
190
+ 5. [ ] Assess real-world exploitability
191
+ 6. [ ] Determine if already exploited (check logs)
192
+
193
+ **Test Environment:**
194
+ ```bash
195
+ # Setup commands
196
+ docker-compose up -d test-env
197
+ npm run test:security
198
+ ```
199
+
200
+ **Reproduction Confirmed:**
201
+ - [ ] Yes, reproduced vulnerability
202
+ - [ ] No, cannot reproduce (false positive)
203
+ - [ ] Partially reproduced (conditions required)
204
+
205
+ ### Phase 2: Assess Impact
206
+ **Goal:** Understand full scope and impact
207
+
208
+ **Steps:**
209
+ 1. [ ] Identify all affected code paths
210
+ 2. [ ] Check for similar vulnerabilities (grep, pattern search)
211
+ 3. [ ] Assess data exposure risk
212
+ 4. [ ] Review access logs for suspicious activity
213
+ 5. [ ] Determine disclosure timeline
214
+ 6. [ ] Estimate remediation effort
215
+
216
+ **Similar Vulnerabilities Found:**
217
+ -
218
+
219
+ **Log Analysis:**
220
+ ```bash
221
+ # Check for exploitation attempts
222
+ grep "suspicious_pattern" logs/*.log
223
+ awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20
224
+ ```
225
+
226
+ **Findings:**
227
+ -
228
+
229
+ ### Phase 3: Develop Remediation
230
+ **Goal:** Create and test security fix
231
+
232
+ **Steps:**
233
+ 1. [ ] Research fix approaches
234
+ 2. [ ] Design secure implementation
235
+ 3. [ ] Implement fix
236
+ 4. [ ] Write security tests
237
+ 5. [ ] Test fix in isolation
238
+ 6. [ ] Verify no functionality regression
239
+ 7. [ ] Security review fix
240
+
241
+ **Fix Approach:**
242
+ [Description of fix strategy]
243
+
244
+ ---
245
+
246
+ ## 🎯 Remediation Strategy
247
+
248
+ ### Immediate Actions (Now)
249
+ **Goal:** Stop active exploitation
250
+
251
+ 1. [ ] Block malicious IPs (if exploitation detected)
252
+ 2. [ ] Disable vulnerable endpoint (if safe)
253
+ 3. [ ] Rotate compromised credentials
254
+ 4. [ ] Enable additional logging/monitoring
255
+ 5. [ ] Notify security team
256
+
257
+ **Emergency Commands:**
258
+ ```bash
259
+ # Block IPs
260
+ iptables -A INPUT -s malicious.ip -j DROP
261
+
262
+ # Disable feature
263
+ curl -X POST /admin/feature-toggle/vulnerable-feature/disable
264
+
265
+ # Rotate secrets
266
+ aws secretsmanager rotate-secret --secret-id prod/api-key
267
+ ```
268
+
269
+ ### Short-term Fix (24-48 hours)
270
+ **Goal:** Implement temporary mitigation
271
+
272
+ 1. [ ] Input validation
273
+ 2. [ ] Rate limiting
274
+ 3. [ ] WAF rules
275
+ 4. [ ] Access controls
276
+ 5. [ ] Monitoring alerts
277
+
278
+ **Mitigation Code:**
279
+ ```typescript
280
+ // Temporary input validation
281
+ function sanitizeInput(input: string): string {
282
+ // Remove dangerous characters
283
+ return input.replace(/[^a-zA-Z0-9]/g, '');
284
+ }
285
+ ```
286
+
287
+ ### Long-term Fix (1-2 weeks)
288
+ **Goal:** Permanent security enhancement
289
+
290
+ 1. [ ] Refactor vulnerable code
291
+ 2. [ ] Implement proper security controls
292
+ 3. [ ] Add comprehensive tests
293
+ 4. [ ] Update security policies
294
+ 5. [ ] Security training for team
295
+
296
+ **Secure Implementation:**
297
+ ```typescript
298
+ // Permanent fix using parameterized queries
299
+ async function getUserById(userId: string): Promise<User> {
300
+ // Input validation
301
+ if (!/^\d+$/.test(userId)) {
302
+ throw new ValidationError('Invalid user ID format');
303
+ }
304
+
305
+ // Parameterized query (prevents SQL injection)
306
+ const result = await db.query(
307
+ 'SELECT * FROM users WHERE id = $1',
308
+ [userId]
309
+ );
310
+
311
+ return result.rows[0];
312
+ }
313
+ ```
314
+
315
+ ---
316
+
317
+ ## 🔐 Security Controls
318
+
319
+ ### Input Validation
320
+ ```typescript
321
+ // Whitelist validation
322
+ function validateEmail(email: string): boolean {
323
+ const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
324
+ return emailRegex.test(email);
325
+ }
326
+
327
+ // Sanitization
328
+ import DOMPurify from 'dompurify';
329
+ const clean = DOMPurify.sanitize(dirty);
330
+ ```
331
+
332
+ ### Output Encoding
333
+ ```typescript
334
+ // HTML encoding
335
+ function escapeHtml(unsafe: string): string {
336
+ return unsafe
337
+ .replace(/&/g, "&amp;")
338
+ .replace(/</g, "&lt;")
339
+ .replace(/>/g, "&gt;")
340
+ .replace(/"/g, "&quot;")
341
+ .replace(/'/g, "&#039;");
342
+ }
343
+
344
+ // SQL parameterization
345
+ const result = await db.query(
346
+ 'SELECT * FROM users WHERE email = $1',
347
+ [userEmail] // Parameter binding prevents injection
348
+ );
349
+ ```
350
+
351
+ ### Authentication & Authorization
352
+ ```typescript
353
+ // Require authentication
354
+ app.use('/api/admin', requireAuth, requireRole('admin'));
355
+
356
+ // Check authorization
357
+ function checkPermission(user: User, resource: Resource): boolean {
358
+ return user.permissions.includes(resource.requiredPermission);
359
+ }
360
+ ```
361
+
362
+ ### Cryptography
363
+ ```typescript
364
+ // Password hashing
365
+ import bcrypt from 'bcrypt';
366
+ const saltRounds = 12;
367
+ const hashedPassword = await bcrypt.hash(plainPassword, saltRounds);
368
+
369
+ // Secure random tokens
370
+ import crypto from 'crypto';
371
+ const token = crypto.randomBytes(32).toString('hex');
372
+
373
+ // Encryption (AES-256-GCM)
374
+ const algorithm = 'aes-256-gcm';
375
+ const key = crypto.randomBytes(32);
376
+ const iv = crypto.randomBytes(16);
377
+ const cipher = crypto.createCipheriv(algorithm, key, iv);
378
+ ```
379
+
380
+ ### HTTPS/TLS
381
+ ```typescript
382
+ // Enforce HTTPS
383
+ app.use((req, res, next) => {
384
+ if (!req.secure && process.env.NODE_ENV === 'production') {
385
+ return res.redirect(`https://${req.headers.host}${req.url}`);
386
+ }
387
+ next();
388
+ });
389
+
390
+ // Security headers
391
+ import helmet from 'helmet';
392
+ app.use(helmet());
393
+ ```
394
+
395
+ ---
396
+
397
+ ## 🧪 Security Testing
398
+
399
+ ### Automated Security Tests
400
+ ```typescript
401
+ describe('Security: SQL Injection Prevention', () => {
402
+ it('should reject SQL injection attempts', async () => {
403
+ const maliciousInput = "1' OR '1'='1";
404
+
405
+ await expect(getUserById(maliciousInput))
406
+ .rejects
407
+ .toThrow(ValidationError);
408
+ });
409
+
410
+ it('should use parameterized queries', async () => {
411
+ const spy = jest.spyOn(db, 'query');
412
+
413
+ await getUserById('123');
414
+
415
+ expect(spy).toHaveBeenCalledWith(
416
+ expect.stringContaining('$1'),
417
+ expect.arrayContaining(['123'])
418
+ );
419
+ });
420
+ });
421
+
422
+ describe('Security: XSS Prevention', () => {
423
+ it('should escape HTML in user input', () => {
424
+ const malicious = '<script>alert("XSS")</script>';
425
+ const safe = escapeHtml(malicious);
426
+
427
+ expect(safe).not.toContain('<script>');
428
+ expect(safe).toContain('&lt;script&gt;');
429
+ });
430
+ });
431
+ ```
432
+
433
+ ### Manual Security Testing
434
+ - [ ] Test with common attack payloads
435
+ - [ ] Fuzzing with malformed input
436
+ - [ ] Authentication bypass attempts
437
+ - [ ] Authorization escalation attempts
438
+ - [ ] Session hijacking tests
439
+ - [ ] CSRF token validation
440
+ - [ ] Rate limiting verification
441
+
442
+ **Tools:**
443
+ ```bash
444
+ # OWASP ZAP
445
+ zap-cli quick-scan https://target.com
446
+
447
+ # Burp Suite
448
+ # Manual testing with Burp Suite Proxy
449
+
450
+ # SQLMap
451
+ sqlmap -u "http://target.com/page?id=1" --dbs
452
+
453
+ # Nikto
454
+ nikto -h https://target.com
455
+ ```
456
+
457
+ ---
458
+
459
+ ## 📊 CVSS Scoring
460
+
461
+ ### CVSS v3.1 Calculator
462
+
463
+ **Base Score Metrics:**
464
+ - Attack Vector (AV): [N/A/L/P]
465
+ - Attack Complexity (AC): [L/H]
466
+ - Privileges Required (PR): [N/L/H]
467
+ - User Interaction (UI): [N/R]
468
+ - Scope (S): [U/C]
469
+ - Confidentiality (C): [N/L/H]
470
+ - Integrity (I): [N/L/H]
471
+ - Availability (A): [N/L/H]
472
+
473
+ **Vector String:**
474
+ ```
475
+ CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
476
+ ```
477
+
478
+ **Scores:**
479
+ - Base Score: X.X [None/Low/Medium/High/Critical]
480
+ - Temporal Score: X.X
481
+ - Environmental Score: X.X
482
+
483
+ **Severity Level:**
484
+ - [ ] None (0.0)
485
+ - [ ] Low (0.1-3.9)
486
+ - [ ] Medium (4.0-6.9)
487
+ - [ ] High (7.0-8.9)
488
+ - [ ] Critical (9.0-10.0)
489
+
490
+ ---
491
+
492
+ ## 💡 Root Cause Analysis
493
+
494
+ ### Security Weakness
495
+ [Explanation of underlying security issue]
496
+
497
+ ### Why Analysis
498
+ 1. **Why was this vulnerability introduced?**
499
+ Answer:
500
+
501
+ 2. **Why wasn't it caught in code review?**
502
+ Answer:
503
+
504
+ 3. **Why didn't security testing find it?**
505
+ Answer:
506
+
507
+ 4. **Why didn't security training prevent it?**
508
+ Answer:
509
+
510
+ 5. **What systemic issue allowed this?**
511
+ Answer: [Root cause]
512
+
513
+ ---
514
+
515
+ ## 🔧 Fix Implementation
516
+
517
+ ### Code Changes
518
+ **Files Modified:**
519
+ - `path/to/vulnerable/file.ts`
520
+ - `path/to/tests/security.spec.ts`
521
+
522
+ **Security Fix:**
523
+ ```diff
524
+ - // Vulnerable code
525
+ + // Secure code
526
+ ```
527
+
528
+ ### Configuration Changes
529
+ ```yaml
530
+ # Security headers
531
+ security:
532
+ hsts: true
533
+ csp: "default-src 'self'"
534
+ xssProtection: true
535
+ ```
536
+
537
+ ### Infrastructure Updates
538
+ -
539
+
540
+ ---
541
+
542
+ ## ✅ Success Criteria
543
+
544
+ **Vulnerability Remediated:**
545
+ - [ ] Vulnerability cannot be reproduced
546
+ - [ ] Security tests pass
547
+ - [ ] No similar vulnerabilities exist
548
+ - [ ] Fix reviewed by security team
549
+ - [ ] Deployed to all environments
550
+ - [ ] No functionality regressions
551
+
552
+ **Validation:**
553
+ - [ ] Penetration test confirms fix
554
+ - [ ] Security scan shows no vulnerabilities
555
+ - [ ] Code review approved
556
+ - [ ] No exploitation attempts in logs
557
+
558
+ ---
559
+
560
+ ## 📢 Disclosure & Communication
561
+
562
+ ### Internal Communication
563
+ - [ ] Security team notified
564
+ - [ ] Engineering team notified
565
+ - [ ] Management notified (if high/critical)
566
+ - [ ] Incident report created
567
+
568
+ ### External Communication
569
+ **If vulnerability is in open source dependency:**
570
+ - [ ] Upstream maintainer notified
571
+ - [ ] CVE requested (if applicable)
572
+ - [ ] Security advisory published
573
+
574
+ **If user data was exposed:**
575
+ - [ ] Legal team consulted
576
+ - [ ] Affected users notified
577
+ - [ ] Regulatory bodies notified (GDPR, etc)
578
+
579
+ **Disclosure Timeline:**
580
+ - Discovery: [date]
581
+ - Vendor notification: [date]
582
+ - Fix released: [date]
583
+ - Public disclosure: [date +90 days]
584
+
585
+ ---
586
+
587
+ ## 🛡️ Prevention Strategy
588
+
589
+ ### Secure Coding Practices
590
+ - [ ] Use parameterized queries (prevent SQL injection)
591
+ - [ ] Validate and sanitize all input
592
+ - [ ] Encode all output
593
+ - [ ] Use security libraries (helmet, DOMPurify)
594
+ - [ ] Implement principle of least privilege
595
+ - [ ] Enable security linters (ESLint security rules)
596
+
597
+ ### Security Testing
598
+ - [ ] Add security tests to CI/CD
599
+ - [ ] Regular SAST scans (static analysis)
600
+ - [ ] Regular DAST scans (dynamic analysis)
601
+ - [ ] Dependency vulnerability scanning
602
+ - [ ] Annual penetration testing
603
+
604
+ ### Training & Awareness
605
+ - [ ] Security training for developers
606
+ - [ ] Secure code review checklist
607
+ - [ ] OWASP Top 10 awareness
608
+ - [ ] Threat modeling sessions
609
+
610
+ ---
611
+
612
+ ## 📚 References
613
+
614
+ **OWASP Resources:**
615
+ - [OWASP Top 10](https://owasp.org/www-project-top-ten/)
616
+ - [OWASP Cheat Sheet Series](https://cheatsheetseries.owasp.org/)
617
+
618
+ **CVE/CWE:**
619
+ - CVE-YYYY-XXXXX: [link]
620
+ - CWE-###: [weakness type]
621
+
622
+ **Security Advisories:**
623
+ - [GitHub Advisory]
624
+ - [Vendor Advisory]
625
+
626
+ **Related Incidents:**
627
+ -
628
+
629
+ ---
630
+
631
+ ## 📋 DELIVERABLE REQUIREMENTS
632
+
633
+ ### Investigation Report Format
634
+ **Filename:** `INV-{{investigationId}}-findings-[TIMESTAMP].md`
635
+ **Location:** `trinity/reports/`
636
+
637
+ ### Required Sections
638
+ 1. **Investigation Summary** - Vulnerability overview, type, and severity (CVSS score)
639
+ 2. **Findings** - Complete vulnerability analysis with proof of concept
640
+ 3. **Impact Assessment** - Confidentiality, integrity, availability impacts
641
+ 4. **Remediation Strategy** - Immediate, short-term, and long-term fixes
642
+ 5. **Fix Validation** - Security tests confirming vulnerability is resolved
643
+ 6. **Recommendations** - Prevention strategy, security controls to add, monitoring requirements
644
+
645
+ ### Evidence to Provide
646
+ - Proof of concept (PoC) code demonstrating vulnerability
647
+ - CVSS v3.1 scoring breakdown
648
+ - Security scan results (before/after)
649
+ - Code changes with security review
650
+ - Penetration test results validating fix
651
+ - Log analysis showing no exploitation
652
+
653
+ ---
654
+
655
+ ## ✅ AFTER COMPLETION
656
+
657
+ When investigation is complete:
658
+ 1. **Create Investigation Report:**
659
+ - [ ] Save findings report to `trinity/reports/INV-{{investigationId}}-findings-[TIMESTAMP].md`
660
+ - [ ] Include all required sections listed above
661
+ - [ ] Attach all evidence and supporting documentation
662
+ - [ ] **CRITICAL:** Ensure report does NOT contain sensitive exploit details that could enable attacks
663
+
664
+ 2. **Move Investigation File:**
665
+ - [ ] Move this investigation file (INV-{{investigationId}}.md) to `trinity/sessions/`
666
+ - [ ] Keep report in `trinity/reports/` until end of session
667
+
668
+ 3. **Session Cleanup:**
669
+ - [ ] Run `/trinity-end` to archive both investigation and report
670
+ - [ ] Investigation will be archived to `trinity/archive/investigations/YYYY-MM-DD/`
671
+ - [ ] Report will be archived to `trinity/archive/reports/YYYY-MM-DD/`
672
+
673
+ 4. **Clean Slate:**
674
+ - [ ] Verify `trinity/sessions/` is empty (ready for next session)
675
+ - [ ] Verify `trinity/reports/` is empty (ready for next session)
676
+
677
+ 5. **Security-Specific Actions:**
678
+ - [ ] Notify security team of findings
679
+ - [ ] Update threat model if applicable
680
+ - [ ] Review disclosure timeline (for public vulnerabilities)
681
+
682
+ ---
683
+
684
+ ## 📚 Trinity Method Reference Documentation
685
+
686
+ **Trinity Method Core:**
687
+ - [Trinity Method Protocols](../../CLAUDE.md) - Root Trinity guidance
688
+ - [Investigation Requirements](../../trinity/CLAUDE.md#investigation-protocols) - Investigation-first methodology
689
+ - [Agent Directory](../../.claude/EMPLOYEE-DIRECTORY.md) - 19-agent Trinity team
690
+
691
+ **Knowledge Base:**
692
+ - [Architecture](../../trinity/knowledge-base/ARCHITECTURE.md) - System architecture and patterns
693
+ - [Known Issues](../../trinity/knowledge-base/ISSUES.md) - Issue patterns database
694
+ - [Technical Debt](../../trinity/knowledge-base/Technical-Debt.md) - Debt tracking
695
+ - [Testing Standards](../../trinity/knowledge-base/TESTING-PRINCIPLES.md) - Test requirements
696
+ - [Coding Standards](../../trinity/knowledge-base/CODING-PRINCIPLES.md) - Code quality
697
+
698
+ **Investigation Protocols:**
699
+ - READ-ONLY: No file modifications during investigation
700
+ - Document findings thoroughly
701
+ - Provide evidence-based recommendations
702
+ - Implementation requires separate approval
703
+
704
+ ---
705
+
706
+ **Investigation Status:** {{status}}
707
+ **Priority:** {{priority}}
708
+ **Created:** {{createdAt}}
709
+ **Last Updated:** {{lastUpdated}}
710
+ **Next Review:** {{nextReview}}
711
+ **Investigator:** {{investigator}}
712
+
713
+ **Severity:** {{severity}}
714
+ **Remediation Status:** [Not Started / In Progress / Completed]