@claude-flow/security 3.0.0-alpha.7 → 3.0.0-alpha.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 (61) hide show
  1. package/.claude-flow/data/pending-insights.jsonl +6 -0
  2. package/.claude-flow/neural/stats.json +6 -0
  3. package/README.md +292 -234
  4. package/__tests__/acceptance/security-compliance.test.ts +674 -674
  5. package/__tests__/authorization-propagator.test.ts +155 -0
  6. package/__tests__/credential-generator.test.ts +310 -310
  7. package/__tests__/fixtures/configurations.ts +425 -425
  8. package/__tests__/fixtures/index.ts +21 -21
  9. package/__tests__/helpers/create-mock.ts +469 -469
  10. package/__tests__/helpers/index.ts +32 -32
  11. package/__tests__/input-validator.test.ts +382 -382
  12. package/__tests__/integration/security-flow.test.ts +606 -606
  13. package/__tests__/password-hasher.test.ts +239 -239
  14. package/__tests__/path-validator.test.ts +302 -302
  15. package/__tests__/plugin-integrity-verifier.test.ts +199 -0
  16. package/__tests__/safe-executor.test.ts +292 -292
  17. package/__tests__/token-generator.test.ts +371 -371
  18. package/__tests__/tool-output-guardrail.test.ts +256 -0
  19. package/__tests__/unit/credential-generator.test.ts +182 -182
  20. package/__tests__/unit/password-hasher.test.ts +359 -359
  21. package/__tests__/unit/path-validator.test.ts +509 -509
  22. package/__tests__/unit/safe-executor.test.ts +667 -667
  23. package/__tests__/unit/token-generator.test.ts +310 -310
  24. package/dist/authorization/propagator.d.ts +148 -0
  25. package/dist/authorization/propagator.d.ts.map +1 -0
  26. package/dist/authorization/propagator.js +182 -0
  27. package/dist/authorization/propagator.js.map +1 -0
  28. package/dist/credential-generator.js +9 -9
  29. package/dist/index.d.ts +3 -0
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +10 -0
  32. package/dist/index.js.map +1 -1
  33. package/dist/plugins/integrity-verifier.d.ts +125 -0
  34. package/dist/plugins/integrity-verifier.d.ts.map +1 -0
  35. package/dist/plugins/integrity-verifier.js +186 -0
  36. package/dist/plugins/integrity-verifier.js.map +1 -0
  37. package/dist/tool-output-guardrail.d.ts +126 -0
  38. package/dist/tool-output-guardrail.d.ts.map +1 -0
  39. package/dist/tool-output-guardrail.js +257 -0
  40. package/dist/tool-output-guardrail.js.map +1 -0
  41. package/package.json +27 -27
  42. package/ruvector.db +0 -0
  43. package/src/CVE-REMEDIATION.ts +251 -251
  44. package/src/application/index.ts +10 -10
  45. package/src/application/services/security-application-service.ts +193 -193
  46. package/src/authorization/propagator.ts +279 -0
  47. package/src/credential-generator.ts +368 -368
  48. package/src/domain/entities/security-context.ts +173 -173
  49. package/src/domain/index.ts +17 -17
  50. package/src/domain/services/security-domain-service.ts +296 -296
  51. package/src/index.ts +314 -271
  52. package/src/input-validator.ts +466 -466
  53. package/src/password-hasher.ts +277 -277
  54. package/src/path-validator.ts +525 -525
  55. package/src/plugins/integrity-verifier.ts +265 -0
  56. package/src/safe-executor.ts +546 -546
  57. package/src/token-generator.ts +463 -463
  58. package/src/tool-output-guardrail.ts +360 -0
  59. package/tsconfig.json +9 -9
  60. package/tsconfig.tsbuildinfo +1 -1
  61. package/vitest.config.ts +20 -20
@@ -1,251 +1,251 @@
1
- /**
2
- * CVE Remediation Tracking
3
- *
4
- * This file documents all security vulnerabilities addressed in the V3 security module
5
- * and provides programmatic tracking of remediation status.
6
- *
7
- * @module v3/security/CVE-REMEDIATION
8
- */
9
-
10
- export interface CVEEntry {
11
- id: string;
12
- title: string;
13
- severity: 'critical' | 'high' | 'medium' | 'low';
14
- description: string;
15
- affectedFiles: string[];
16
- remediationFile: string;
17
- remediationStatus: 'fixed' | 'in_progress' | 'pending';
18
- testFile: string;
19
- testStatus: 'passing' | 'failing' | 'pending';
20
- timeline: {
21
- identified: string;
22
- remediated?: string;
23
- verified?: string;
24
- };
25
- }
26
-
27
- /**
28
- * Complete list of addressed CVEs and security issues
29
- */
30
- export const CVE_REGISTRY: CVEEntry[] = [
31
- {
32
- id: 'CVE-1',
33
- title: 'Dependency Vulnerabilities',
34
- severity: 'high',
35
- description: 'Vulnerable versions of @anthropic-ai/claude-code and @modelcontextprotocol/sdk',
36
- affectedFiles: [
37
- 'package.json',
38
- ],
39
- remediationFile: 'package.json (dependency updates)',
40
- remediationStatus: 'fixed',
41
- testFile: 'npm audit',
42
- testStatus: 'passing',
43
- timeline: {
44
- identified: '2026-01-03',
45
- remediated: '2026-01-05',
46
- verified: '2026-01-05',
47
- },
48
- },
49
- {
50
- id: 'CVE-2',
51
- title: 'Weak Password Hashing',
52
- severity: 'critical',
53
- description: 'SHA-256 with hardcoded salt used for password hashing instead of bcrypt',
54
- affectedFiles: [
55
- 'v2/src/api/auth-service.ts:580-588',
56
- ],
57
- remediationFile: 'v3/security/password-hasher.ts',
58
- remediationStatus: 'fixed',
59
- testFile: 'v3/__tests__/security/password-hasher.test.ts',
60
- testStatus: 'passing',
61
- timeline: {
62
- identified: '2025-01-01',
63
- remediated: '2025-01-04',
64
- verified: '2025-01-04',
65
- },
66
- },
67
- {
68
- id: 'CVE-3',
69
- title: 'Hardcoded Default Credentials',
70
- severity: 'critical',
71
- description: 'Default admin/service credentials hardcoded in auth service initialization',
72
- affectedFiles: [
73
- 'v2/src/api/auth-service.ts:602-643',
74
- ],
75
- remediationFile: 'v3/security/credential-generator.ts',
76
- remediationStatus: 'fixed',
77
- testFile: 'v3/__tests__/security/credential-generator.test.ts',
78
- testStatus: 'passing',
79
- timeline: {
80
- identified: '2025-01-01',
81
- remediated: '2025-01-04',
82
- verified: '2025-01-04',
83
- },
84
- },
85
- {
86
- id: 'HIGH-1',
87
- title: 'Command Injection via Shell Execution',
88
- severity: 'high',
89
- description: 'spawn() and exec() calls with shell:true enable command injection',
90
- affectedFiles: [
91
- 'Multiple spawn() locations across codebase',
92
- ],
93
- remediationFile: 'v3/security/safe-executor.ts',
94
- remediationStatus: 'fixed',
95
- testFile: 'v3/__tests__/security/safe-executor.test.ts',
96
- testStatus: 'passing',
97
- timeline: {
98
- identified: '2025-01-01',
99
- remediated: '2025-01-04',
100
- verified: '2025-01-04',
101
- },
102
- },
103
- {
104
- id: 'HIGH-2',
105
- title: 'Path Traversal Vulnerability',
106
- severity: 'high',
107
- description: 'Unvalidated file paths allow directory traversal attacks',
108
- affectedFiles: [
109
- 'All file operation modules',
110
- ],
111
- remediationFile: 'v3/security/path-validator.ts',
112
- remediationStatus: 'fixed',
113
- testFile: 'v3/__tests__/security/path-validator.test.ts',
114
- testStatus: 'passing',
115
- timeline: {
116
- identified: '2025-01-01',
117
- remediated: '2025-01-04',
118
- verified: '2025-01-04',
119
- },
120
- },
121
- ];
122
-
123
- /**
124
- * Security patterns implemented
125
- */
126
- export const SECURITY_PATTERNS = {
127
- passwordHashing: {
128
- algorithm: 'bcrypt',
129
- rounds: 12,
130
- rationale: 'Industry standard adaptive hashing with automatic salt generation',
131
- },
132
- credentialGeneration: {
133
- method: 'crypto.randomBytes',
134
- minPasswordLength: 32,
135
- minSecretLength: 64,
136
- rationale: 'Cryptographically secure random generation with sufficient entropy',
137
- },
138
- commandExecution: {
139
- method: 'execFile',
140
- shell: false,
141
- allowlist: true,
142
- rationale: 'No shell interpretation, command allowlist prevents injection',
143
- },
144
- pathValidation: {
145
- method: 'path.resolve + prefix check',
146
- symlinks: 'resolved',
147
- blockedPatterns: ['..', '%2e', null],
148
- rationale: 'Canonicalization prevents all traversal variations',
149
- },
150
- inputValidation: {
151
- library: 'zod',
152
- sanitization: true,
153
- rationale: 'Type-safe validation with runtime checks',
154
- },
155
- };
156
-
157
- /**
158
- * Summary of security improvements
159
- */
160
- export const SECURITY_SUMMARY = {
161
- cveCount: 5,
162
- fixedCount: 5,
163
- pendingCount: 0,
164
- criticalFixed: 2,
165
- highFixed: 3,
166
- testCoverage: '>95%',
167
- documentsCreated: [
168
- 'v3/security/password-hasher.ts',
169
- 'v3/security/credential-generator.ts',
170
- 'v3/security/safe-executor.ts',
171
- 'v3/security/path-validator.ts',
172
- 'v3/security/input-validator.ts',
173
- 'v3/security/token-generator.ts',
174
- 'v3/security/index.ts',
175
- 'v3/security/CVE-REMEDIATION.ts',
176
- ],
177
- testsCreated: [
178
- 'v3/__tests__/security/password-hasher.test.ts',
179
- 'v3/__tests__/security/credential-generator.test.ts',
180
- 'v3/__tests__/security/safe-executor.test.ts',
181
- 'v3/__tests__/security/path-validator.test.ts',
182
- 'v3/__tests__/security/input-validator.test.ts',
183
- 'v3/__tests__/security/token-generator.test.ts',
184
- ],
185
- };
186
-
187
- /**
188
- * Validates that all CVEs are addressed
189
- */
190
- export function validateRemediation(): {
191
- allFixed: boolean;
192
- issues: string[];
193
- } {
194
- const issues: string[] = [];
195
-
196
- for (const cve of CVE_REGISTRY) {
197
- if (cve.remediationStatus !== 'fixed') {
198
- issues.push(`${cve.id}: Remediation not complete (${cve.remediationStatus})`);
199
- }
200
- if (cve.testStatus !== 'passing') {
201
- issues.push(`${cve.id}: Tests not passing (${cve.testStatus})`);
202
- }
203
- }
204
-
205
- return {
206
- allFixed: issues.length === 0,
207
- issues,
208
- };
209
- }
210
-
211
- /**
212
- * Gets remediation report
213
- */
214
- export function getRemediationReport(): string {
215
- const lines = [
216
- '# V3 Security Remediation Report',
217
- '',
218
- '## Summary',
219
- `- Total CVEs/Issues: ${SECURITY_SUMMARY.cveCount}`,
220
- `- Fixed: ${SECURITY_SUMMARY.fixedCount}`,
221
- `- Pending: ${SECURITY_SUMMARY.pendingCount}`,
222
- `- Test Coverage: ${SECURITY_SUMMARY.testCoverage}`,
223
- '',
224
- '## Detailed Status',
225
- '',
226
- ];
227
-
228
- for (const cve of CVE_REGISTRY) {
229
- lines.push(`### ${cve.id}: ${cve.title}`);
230
- lines.push(`- Severity: ${cve.severity.toUpperCase()}`);
231
- lines.push(`- Status: ${cve.remediationStatus}`);
232
- lines.push(`- Test Status: ${cve.testStatus}`);
233
- lines.push(`- Remediation: \`${cve.remediationFile}\``);
234
- lines.push('');
235
- }
236
-
237
- lines.push('## Security Patterns Implemented');
238
- lines.push('');
239
- lines.push('| Pattern | Implementation | Rationale |');
240
- lines.push('|---------|---------------|-----------|');
241
-
242
- for (const [pattern, config] of Object.entries(SECURITY_PATTERNS)) {
243
- const impl = Object.entries(config)
244
- .filter(([k]) => k !== 'rationale')
245
- .map(([k, v]) => `${k}: ${v}`)
246
- .join(', ');
247
- lines.push(`| ${pattern} | ${impl} | ${config.rationale} |`);
248
- }
249
-
250
- return lines.join('\n');
251
- }
1
+ /**
2
+ * CVE Remediation Tracking
3
+ *
4
+ * This file documents all security vulnerabilities addressed in the V3 security module
5
+ * and provides programmatic tracking of remediation status.
6
+ *
7
+ * @module v3/security/CVE-REMEDIATION
8
+ */
9
+
10
+ export interface CVEEntry {
11
+ id: string;
12
+ title: string;
13
+ severity: 'critical' | 'high' | 'medium' | 'low';
14
+ description: string;
15
+ affectedFiles: string[];
16
+ remediationFile: string;
17
+ remediationStatus: 'fixed' | 'in_progress' | 'pending';
18
+ testFile: string;
19
+ testStatus: 'passing' | 'failing' | 'pending';
20
+ timeline: {
21
+ identified: string;
22
+ remediated?: string;
23
+ verified?: string;
24
+ };
25
+ }
26
+
27
+ /**
28
+ * Complete list of addressed CVEs and security issues
29
+ */
30
+ export const CVE_REGISTRY: CVEEntry[] = [
31
+ {
32
+ id: 'CVE-1',
33
+ title: 'Dependency Vulnerabilities',
34
+ severity: 'high',
35
+ description: 'Vulnerable versions of @anthropic-ai/claude-code and @modelcontextprotocol/sdk',
36
+ affectedFiles: [
37
+ 'package.json',
38
+ ],
39
+ remediationFile: 'package.json (dependency updates)',
40
+ remediationStatus: 'fixed',
41
+ testFile: 'npm audit',
42
+ testStatus: 'passing',
43
+ timeline: {
44
+ identified: '2026-01-03',
45
+ remediated: '2026-01-05',
46
+ verified: '2026-01-05',
47
+ },
48
+ },
49
+ {
50
+ id: 'CVE-2',
51
+ title: 'Weak Password Hashing',
52
+ severity: 'critical',
53
+ description: 'SHA-256 with hardcoded salt used for password hashing instead of bcrypt',
54
+ affectedFiles: [
55
+ 'v2/src/api/auth-service.ts:580-588',
56
+ ],
57
+ remediationFile: 'v3/security/password-hasher.ts',
58
+ remediationStatus: 'fixed',
59
+ testFile: 'v3/__tests__/security/password-hasher.test.ts',
60
+ testStatus: 'passing',
61
+ timeline: {
62
+ identified: '2025-01-01',
63
+ remediated: '2025-01-04',
64
+ verified: '2025-01-04',
65
+ },
66
+ },
67
+ {
68
+ id: 'CVE-3',
69
+ title: 'Hardcoded Default Credentials',
70
+ severity: 'critical',
71
+ description: 'Default admin/service credentials hardcoded in auth service initialization',
72
+ affectedFiles: [
73
+ 'v2/src/api/auth-service.ts:602-643',
74
+ ],
75
+ remediationFile: 'v3/security/credential-generator.ts',
76
+ remediationStatus: 'fixed',
77
+ testFile: 'v3/__tests__/security/credential-generator.test.ts',
78
+ testStatus: 'passing',
79
+ timeline: {
80
+ identified: '2025-01-01',
81
+ remediated: '2025-01-04',
82
+ verified: '2025-01-04',
83
+ },
84
+ },
85
+ {
86
+ id: 'HIGH-1',
87
+ title: 'Command Injection via Shell Execution',
88
+ severity: 'high',
89
+ description: 'spawn() and exec() calls with shell:true enable command injection',
90
+ affectedFiles: [
91
+ 'Multiple spawn() locations across codebase',
92
+ ],
93
+ remediationFile: 'v3/security/safe-executor.ts',
94
+ remediationStatus: 'fixed',
95
+ testFile: 'v3/__tests__/security/safe-executor.test.ts',
96
+ testStatus: 'passing',
97
+ timeline: {
98
+ identified: '2025-01-01',
99
+ remediated: '2025-01-04',
100
+ verified: '2025-01-04',
101
+ },
102
+ },
103
+ {
104
+ id: 'HIGH-2',
105
+ title: 'Path Traversal Vulnerability',
106
+ severity: 'high',
107
+ description: 'Unvalidated file paths allow directory traversal attacks',
108
+ affectedFiles: [
109
+ 'All file operation modules',
110
+ ],
111
+ remediationFile: 'v3/security/path-validator.ts',
112
+ remediationStatus: 'fixed',
113
+ testFile: 'v3/__tests__/security/path-validator.test.ts',
114
+ testStatus: 'passing',
115
+ timeline: {
116
+ identified: '2025-01-01',
117
+ remediated: '2025-01-04',
118
+ verified: '2025-01-04',
119
+ },
120
+ },
121
+ ];
122
+
123
+ /**
124
+ * Security patterns implemented
125
+ */
126
+ export const SECURITY_PATTERNS = {
127
+ passwordHashing: {
128
+ algorithm: 'bcrypt',
129
+ rounds: 12,
130
+ rationale: 'Industry standard adaptive hashing with automatic salt generation',
131
+ },
132
+ credentialGeneration: {
133
+ method: 'crypto.randomBytes',
134
+ minPasswordLength: 32,
135
+ minSecretLength: 64,
136
+ rationale: 'Cryptographically secure random generation with sufficient entropy',
137
+ },
138
+ commandExecution: {
139
+ method: 'execFile',
140
+ shell: false,
141
+ allowlist: true,
142
+ rationale: 'No shell interpretation, command allowlist prevents injection',
143
+ },
144
+ pathValidation: {
145
+ method: 'path.resolve + prefix check',
146
+ symlinks: 'resolved',
147
+ blockedPatterns: ['..', '%2e', null],
148
+ rationale: 'Canonicalization prevents all traversal variations',
149
+ },
150
+ inputValidation: {
151
+ library: 'zod',
152
+ sanitization: true,
153
+ rationale: 'Type-safe validation with runtime checks',
154
+ },
155
+ };
156
+
157
+ /**
158
+ * Summary of security improvements
159
+ */
160
+ export const SECURITY_SUMMARY = {
161
+ cveCount: 5,
162
+ fixedCount: 5,
163
+ pendingCount: 0,
164
+ criticalFixed: 2,
165
+ highFixed: 3,
166
+ testCoverage: '>95%',
167
+ documentsCreated: [
168
+ 'v3/security/password-hasher.ts',
169
+ 'v3/security/credential-generator.ts',
170
+ 'v3/security/safe-executor.ts',
171
+ 'v3/security/path-validator.ts',
172
+ 'v3/security/input-validator.ts',
173
+ 'v3/security/token-generator.ts',
174
+ 'v3/security/index.ts',
175
+ 'v3/security/CVE-REMEDIATION.ts',
176
+ ],
177
+ testsCreated: [
178
+ 'v3/__tests__/security/password-hasher.test.ts',
179
+ 'v3/__tests__/security/credential-generator.test.ts',
180
+ 'v3/__tests__/security/safe-executor.test.ts',
181
+ 'v3/__tests__/security/path-validator.test.ts',
182
+ 'v3/__tests__/security/input-validator.test.ts',
183
+ 'v3/__tests__/security/token-generator.test.ts',
184
+ ],
185
+ };
186
+
187
+ /**
188
+ * Validates that all CVEs are addressed
189
+ */
190
+ export function validateRemediation(): {
191
+ allFixed: boolean;
192
+ issues: string[];
193
+ } {
194
+ const issues: string[] = [];
195
+
196
+ for (const cve of CVE_REGISTRY) {
197
+ if (cve.remediationStatus !== 'fixed') {
198
+ issues.push(`${cve.id}: Remediation not complete (${cve.remediationStatus})`);
199
+ }
200
+ if (cve.testStatus !== 'passing') {
201
+ issues.push(`${cve.id}: Tests not passing (${cve.testStatus})`);
202
+ }
203
+ }
204
+
205
+ return {
206
+ allFixed: issues.length === 0,
207
+ issues,
208
+ };
209
+ }
210
+
211
+ /**
212
+ * Gets remediation report
213
+ */
214
+ export function getRemediationReport(): string {
215
+ const lines = [
216
+ '# V3 Security Remediation Report',
217
+ '',
218
+ '## Summary',
219
+ `- Total CVEs/Issues: ${SECURITY_SUMMARY.cveCount}`,
220
+ `- Fixed: ${SECURITY_SUMMARY.fixedCount}`,
221
+ `- Pending: ${SECURITY_SUMMARY.pendingCount}`,
222
+ `- Test Coverage: ${SECURITY_SUMMARY.testCoverage}`,
223
+ '',
224
+ '## Detailed Status',
225
+ '',
226
+ ];
227
+
228
+ for (const cve of CVE_REGISTRY) {
229
+ lines.push(`### ${cve.id}: ${cve.title}`);
230
+ lines.push(`- Severity: ${cve.severity.toUpperCase()}`);
231
+ lines.push(`- Status: ${cve.remediationStatus}`);
232
+ lines.push(`- Test Status: ${cve.testStatus}`);
233
+ lines.push(`- Remediation: \`${cve.remediationFile}\``);
234
+ lines.push('');
235
+ }
236
+
237
+ lines.push('## Security Patterns Implemented');
238
+ lines.push('');
239
+ lines.push('| Pattern | Implementation | Rationale |');
240
+ lines.push('|---------|---------------|-----------|');
241
+
242
+ for (const [pattern, config] of Object.entries(SECURITY_PATTERNS)) {
243
+ const impl = Object.entries(config)
244
+ .filter(([k]) => k !== 'rationale')
245
+ .map(([k, v]) => `${k}: ${v}`)
246
+ .join(', ');
247
+ lines.push(`| ${pattern} | ${impl} | ${config.rationale} |`);
248
+ }
249
+
250
+ return lines.join('\n');
251
+ }
@@ -1,10 +1,10 @@
1
- /**
2
- * Security Application Layer - Public Exports
3
- *
4
- * @module v3/security/application
5
- */
6
-
7
- export {
8
- SecurityApplicationService,
9
- type SecurityAuditResult,
10
- } from './services/security-application-service.js';
1
+ /**
2
+ * Security Application Layer - Public Exports
3
+ *
4
+ * @module v3/security/application
5
+ */
6
+
7
+ export {
8
+ SecurityApplicationService,
9
+ type SecurityAuditResult,
10
+ } from './services/security-application-service.js';