@claude-flow/security 3.0.0-alpha.9 → 3.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 (116) hide show
  1. package/dist/CVE-REMEDIATION.d.ts +17 -6
  2. package/dist/CVE-REMEDIATION.d.ts.map +1 -1
  3. package/dist/CVE-REMEDIATION.js +328 -12
  4. package/dist/CVE-REMEDIATION.js.map +1 -1
  5. package/dist/index.d.ts +8 -0
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +26 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/keychain-adapter.d.ts +48 -0
  10. package/dist/keychain-adapter.d.ts.map +1 -0
  11. package/dist/keychain-adapter.js +0 -0
  12. package/dist/keychain-adapter.js.map +1 -0
  13. package/dist/mcp-caller-identity.d.ts +101 -0
  14. package/dist/mcp-caller-identity.d.ts.map +1 -0
  15. package/dist/mcp-caller-identity.js +0 -0
  16. package/dist/mcp-caller-identity.js.map +1 -0
  17. package/dist/mcp-composition-inspector.d.ts +133 -0
  18. package/dist/mcp-composition-inspector.d.ts.map +1 -0
  19. package/dist/mcp-composition-inspector.js +254 -0
  20. package/dist/mcp-composition-inspector.js.map +1 -0
  21. package/dist/oauth/browser.d.ts +31 -0
  22. package/dist/oauth/browser.d.ts.map +1 -0
  23. package/dist/oauth/browser.js +55 -0
  24. package/dist/oauth/browser.js.map +1 -0
  25. package/dist/oauth/callback-server.d.ts +37 -0
  26. package/dist/oauth/callback-server.d.ts.map +1 -0
  27. package/dist/oauth/callback-server.js +86 -0
  28. package/dist/oauth/callback-server.js.map +1 -0
  29. package/dist/oauth/client.d.ts +57 -0
  30. package/dist/oauth/client.d.ts.map +1 -0
  31. package/dist/oauth/client.js +120 -0
  32. package/dist/oauth/client.js.map +1 -0
  33. package/dist/oauth/pkce.d.ts +25 -0
  34. package/dist/oauth/pkce.d.ts.map +1 -0
  35. package/dist/oauth/pkce.js +36 -0
  36. package/dist/oauth/pkce.js.map +1 -0
  37. package/dist/path-validator.d.ts +23 -0
  38. package/dist/path-validator.d.ts.map +1 -1
  39. package/dist/path-validator.js +128 -5
  40. package/dist/path-validator.js.map +1 -1
  41. package/dist/policy/canonical.d.ts +5 -0
  42. package/dist/policy/canonical.d.ts.map +1 -0
  43. package/dist/policy/canonical.js +30 -0
  44. package/dist/policy/canonical.js.map +1 -0
  45. package/dist/policy/engine.d.ts +34 -0
  46. package/dist/policy/engine.d.ts.map +1 -0
  47. package/dist/policy/engine.js +285 -0
  48. package/dist/policy/engine.js.map +1 -0
  49. package/dist/policy/envelope.d.ts +9 -0
  50. package/dist/policy/envelope.d.ts.map +1 -0
  51. package/dist/policy/envelope.js +90 -0
  52. package/dist/policy/envelope.js.map +1 -0
  53. package/dist/policy/evaluator.d.ts +4 -0
  54. package/dist/policy/evaluator.d.ts.map +1 -0
  55. package/dist/policy/evaluator.js +119 -0
  56. package/dist/policy/evaluator.js.map +1 -0
  57. package/dist/policy/index.d.ts +7 -0
  58. package/dist/policy/index.d.ts.map +1 -0
  59. package/dist/policy/index.js +7 -0
  60. package/dist/policy/index.js.map +1 -0
  61. package/dist/policy/product-plane.d.ts +238 -0
  62. package/dist/policy/product-plane.d.ts.map +1 -0
  63. package/dist/policy/product-plane.js +1022 -0
  64. package/dist/policy/product-plane.js.map +1 -0
  65. package/dist/policy/types.d.ts +169 -0
  66. package/dist/policy/types.d.ts.map +1 -0
  67. package/dist/policy/types.js +2 -0
  68. package/dist/policy/types.js.map +1 -0
  69. package/dist/safe-git.d.ts +22 -0
  70. package/dist/safe-git.d.ts.map +1 -0
  71. package/dist/safe-git.js +63 -0
  72. package/dist/safe-git.js.map +1 -0
  73. package/package.json +17 -5
  74. package/.claude-flow/data/pending-insights.jsonl +0 -6
  75. package/.claude-flow/neural/stats.json +0 -6
  76. package/__tests__/acceptance/security-compliance.test.ts +0 -674
  77. package/__tests__/authorization-propagator.test.ts +0 -155
  78. package/__tests__/credential-generator.test.ts +0 -310
  79. package/__tests__/fixtures/configurations.ts +0 -425
  80. package/__tests__/fixtures/index.ts +0 -21
  81. package/__tests__/helpers/create-mock.ts +0 -469
  82. package/__tests__/helpers/index.ts +0 -32
  83. package/__tests__/input-validator.test.ts +0 -382
  84. package/__tests__/integration/security-flow.test.ts +0 -606
  85. package/__tests__/password-hasher.test.ts +0 -239
  86. package/__tests__/path-validator.test.ts +0 -302
  87. package/__tests__/plugin-integrity-verifier.test.ts +0 -199
  88. package/__tests__/safe-executor.test.ts +0 -292
  89. package/__tests__/token-generator.test.ts +0 -371
  90. package/__tests__/tool-output-guardrail.test.ts +0 -256
  91. package/__tests__/unit/credential-generator.test.ts +0 -182
  92. package/__tests__/unit/password-hasher.test.ts +0 -359
  93. package/__tests__/unit/path-validator.test.ts +0 -509
  94. package/__tests__/unit/safe-executor.test.ts +0 -667
  95. package/__tests__/unit/token-generator.test.ts +0 -310
  96. package/ruvector.db +0 -0
  97. package/src/CVE-REMEDIATION.ts +0 -251
  98. package/src/application/index.ts +0 -10
  99. package/src/application/services/security-application-service.ts +0 -193
  100. package/src/authorization/propagator.ts +0 -279
  101. package/src/credential-generator.ts +0 -368
  102. package/src/domain/entities/security-context.ts +0 -173
  103. package/src/domain/index.ts +0 -17
  104. package/src/domain/services/security-domain-service.ts +0 -296
  105. package/src/index.ts +0 -314
  106. package/src/input-validator.ts +0 -466
  107. package/src/password-hasher.ts +0 -277
  108. package/src/path-validator.ts +0 -525
  109. package/src/plugins/integrity-verifier.ts +0 -265
  110. package/src/safe-executor.ts +0 -546
  111. package/src/token-generator.ts +0 -463
  112. package/src/tool-output-guardrail.ts +0 -360
  113. package/tmp.json +0 -0
  114. package/tsconfig.json +0 -9
  115. package/tsconfig.tsbuildinfo +0 -1
  116. package/vitest.config.ts +0 -20
@@ -1,277 +0,0 @@
1
- /**
2
- * Password Hasher - CVE-2 Remediation
3
- *
4
- * Fixes weak password hashing by replacing SHA-256 with hardcoded salt
5
- * with bcrypt using 12 rounds (configurable).
6
- *
7
- * Security Properties:
8
- * - bcrypt with adaptive cost factor (12 rounds)
9
- * - Automatic salt generation per password
10
- * - Timing-safe comparison
11
- * - Minimum password length enforcement
12
- *
13
- * @module v3/security/password-hasher
14
- */
15
-
16
- // #1608 — switched from `bcrypt` to `bcryptjs` to drop the
17
- // `@mapbox/node-pre-gyp → tar <=7.5.10` transitive chain that pulled in
18
- // 6 HIGH-severity CVEs (GHSA-34x7-hfp2-rc4v, GHSA-8qq5-rm4j-mr97, etc.).
19
- // `bcryptjs` is a pure-JS implementation that produces the same `$2a$` /
20
- // `$2b$` hash format and exposes the same `hash()` / `compare()` API
21
- // surface this module uses, so the swap is transparent to callers and to
22
- // any persisted hashes.
23
- import * as bcrypt from 'bcryptjs';
24
-
25
- export interface PasswordHasherConfig {
26
- /**
27
- * Number of bcrypt rounds (cost factor).
28
- * Default: 12 (recommended minimum for production)
29
- * Each increment doubles the computation time.
30
- */
31
- rounds?: number;
32
-
33
- /**
34
- * Minimum password length.
35
- * Default: 8 characters
36
- */
37
- minLength?: number;
38
-
39
- /**
40
- * Maximum password length.
41
- * Default: 128 characters (bcrypt limit is 72 bytes)
42
- */
43
- maxLength?: number;
44
-
45
- /**
46
- * Require at least one uppercase letter.
47
- * Default: true
48
- */
49
- requireUppercase?: boolean;
50
-
51
- /**
52
- * Require at least one lowercase letter.
53
- * Default: true
54
- */
55
- requireLowercase?: boolean;
56
-
57
- /**
58
- * Require at least one digit.
59
- * Default: true
60
- */
61
- requireDigit?: boolean;
62
-
63
- /**
64
- * Require at least one special character.
65
- * Default: false
66
- */
67
- requireSpecial?: boolean;
68
- }
69
-
70
- export interface PasswordValidationResult {
71
- isValid: boolean;
72
- errors: string[];
73
- }
74
-
75
- export class PasswordHashError extends Error {
76
- constructor(
77
- message: string,
78
- public readonly code: string,
79
- ) {
80
- super(message);
81
- this.name = 'PasswordHashError';
82
- }
83
- }
84
-
85
- /**
86
- * Secure password hasher using bcrypt.
87
- *
88
- * This class replaces the vulnerable SHA-256 + hardcoded salt implementation
89
- * with industry-standard bcrypt hashing.
90
- *
91
- * @example
92
- * ```typescript
93
- * const hasher = new PasswordHasher({ rounds: 12 });
94
- * const hash = await hasher.hash('securePassword123');
95
- * const isValid = await hasher.verify('securePassword123', hash);
96
- * ```
97
- */
98
- export class PasswordHasher {
99
- private readonly config: Required<PasswordHasherConfig>;
100
-
101
- constructor(config: PasswordHasherConfig = {}) {
102
- this.config = {
103
- rounds: config.rounds ?? 12,
104
- minLength: config.minLength ?? 8,
105
- maxLength: config.maxLength ?? 128,
106
- requireUppercase: config.requireUppercase ?? true,
107
- requireLowercase: config.requireLowercase ?? true,
108
- requireDigit: config.requireDigit ?? true,
109
- requireSpecial: config.requireSpecial ?? false,
110
- };
111
-
112
- // Validate configuration
113
- if (this.config.rounds < 10 || this.config.rounds > 20) {
114
- throw new PasswordHashError(
115
- 'Bcrypt rounds must be between 10 and 20 for security and performance balance',
116
- 'INVALID_ROUNDS'
117
- );
118
- }
119
-
120
- if (this.config.minLength < 8) {
121
- throw new PasswordHashError(
122
- 'Minimum password length must be at least 8 characters',
123
- 'INVALID_MIN_LENGTH'
124
- );
125
- }
126
- }
127
-
128
- /**
129
- * Validates password against configured requirements.
130
- *
131
- * @param password - The password to validate
132
- * @returns Validation result with errors if any
133
- */
134
- validate(password: string): PasswordValidationResult {
135
- const errors: string[] = [];
136
-
137
- if (!password) {
138
- errors.push('Password is required');
139
- return { isValid: false, errors };
140
- }
141
-
142
- if (password.length < this.config.minLength) {
143
- errors.push(`Password must be at least ${this.config.minLength} characters`);
144
- }
145
-
146
- if (password.length > this.config.maxLength) {
147
- errors.push(`Password must not exceed ${this.config.maxLength} characters`);
148
- }
149
-
150
- if (this.config.requireUppercase && !/[A-Z]/.test(password)) {
151
- errors.push('Password must contain at least one uppercase letter');
152
- }
153
-
154
- if (this.config.requireLowercase && !/[a-z]/.test(password)) {
155
- errors.push('Password must contain at least one lowercase letter');
156
- }
157
-
158
- if (this.config.requireDigit && !/\d/.test(password)) {
159
- errors.push('Password must contain at least one digit');
160
- }
161
-
162
- if (this.config.requireSpecial && !/[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?]/.test(password)) {
163
- errors.push('Password must contain at least one special character');
164
- }
165
-
166
- return {
167
- isValid: errors.length === 0,
168
- errors,
169
- };
170
- }
171
-
172
- /**
173
- * Hashes a password using bcrypt.
174
- *
175
- * @param password - The plaintext password to hash
176
- * @returns The bcrypt hash
177
- * @throws PasswordHashError if password is invalid
178
- */
179
- async hash(password: string): Promise<string> {
180
- const validation = this.validate(password);
181
-
182
- if (!validation.isValid) {
183
- throw new PasswordHashError(
184
- validation.errors.join('; '),
185
- 'VALIDATION_FAILED'
186
- );
187
- }
188
-
189
- try {
190
- // bcrypt automatically generates a random salt per hash
191
- return await bcrypt.hash(password, this.config.rounds);
192
- } catch (error) {
193
- throw new PasswordHashError(
194
- 'Failed to hash password',
195
- 'HASH_FAILED'
196
- );
197
- }
198
- }
199
-
200
- /**
201
- * Verifies a password against a bcrypt hash.
202
- * Uses timing-safe comparison internally.
203
- *
204
- * @param password - The plaintext password to verify
205
- * @param hash - The bcrypt hash to compare against
206
- * @returns True if password matches, false otherwise
207
- */
208
- async verify(password: string, hash: string): Promise<boolean> {
209
- if (!password || !hash) {
210
- return false;
211
- }
212
-
213
- // Validate hash format (bcrypt hashes start with $2a$, $2b$, or $2y$)
214
- if (!this.isValidBcryptHash(hash)) {
215
- return false;
216
- }
217
-
218
- try {
219
- // bcrypt.compare uses timing-safe comparison
220
- return await bcrypt.compare(password, hash);
221
- } catch (error) {
222
- // Return false on any error to prevent timing attacks
223
- return false;
224
- }
225
- }
226
-
227
- /**
228
- * Checks if a hash needs to be rehashed with updated parameters.
229
- * Useful for upgrading hash strength over time.
230
- *
231
- * @param hash - The bcrypt hash to check
232
- * @returns True if hash should be updated
233
- */
234
- needsRehash(hash: string): boolean {
235
- if (!this.isValidBcryptHash(hash)) {
236
- return true;
237
- }
238
-
239
- // Extract rounds from hash (format: $2b$XX$...)
240
- const match = hash.match(/^\$2[aby]\$(\d{2})\$/);
241
- if (!match) {
242
- return true;
243
- }
244
-
245
- const hashRounds = parseInt(match[1], 10);
246
- return hashRounds < this.config.rounds;
247
- }
248
-
249
- /**
250
- * Validates bcrypt hash format.
251
- *
252
- * @param hash - The hash to validate
253
- * @returns True if valid bcrypt hash format
254
- */
255
- private isValidBcryptHash(hash: string): boolean {
256
- // bcrypt hash format: $2a$XX$22charsSalt31charsHash
257
- // Total length: 60 characters
258
- return /^\$2[aby]\$\d{2}\$[./A-Za-z0-9]{53}$/.test(hash);
259
- }
260
-
261
- /**
262
- * Returns current configuration (without sensitive defaults).
263
- */
264
- getConfig(): Readonly<Omit<Required<PasswordHasherConfig>, never>> {
265
- return { ...this.config };
266
- }
267
- }
268
-
269
- /**
270
- * Factory function to create a production-ready password hasher.
271
- *
272
- * @param rounds - Bcrypt rounds (default: 12)
273
- * @returns Configured PasswordHasher instance
274
- */
275
- export function createPasswordHasher(rounds = 12): PasswordHasher {
276
- return new PasswordHasher({ rounds });
277
- }