@claude-flow/security 3.0.0-alpha.1 → 3.0.0-alpha.11
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 +292 -234
- package/__tests__/acceptance/security-compliance.test.ts +674 -674
- package/__tests__/authorization-propagator.test.ts +155 -0
- 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__/keychain-adapter.test.ts +60 -0
- package/__tests__/oauth-browser.test.ts +13 -0
- package/__tests__/oauth-export-surface.test.ts +21 -0
- package/__tests__/oauth-pkce.test.ts +37 -0
- package/__tests__/password-hasher.test.ts +239 -239
- package/__tests__/path-validator.test.ts +302 -302
- package/__tests__/plugin-integrity-verifier.test.ts +199 -0
- package/__tests__/safe-executor.test.ts +292 -292
- package/__tests__/token-generator.test.ts +371 -371
- package/__tests__/tool-output-guardrail.test.ts +256 -0
- 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/CVE-REMEDIATION.d.ts +17 -6
- package/dist/CVE-REMEDIATION.d.ts.map +1 -1
- package/dist/CVE-REMEDIATION.js +328 -12
- package/dist/CVE-REMEDIATION.js.map +1 -1
- package/dist/authorization/propagator.d.ts +148 -0
- package/dist/authorization/propagator.d.ts.map +1 -0
- package/dist/authorization/propagator.js +182 -0
- package/dist/authorization/propagator.js.map +1 -0
- 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 +9 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -1
- package/dist/index.js.map +1 -1
- package/dist/keychain-adapter.d.ts +48 -0
- package/dist/keychain-adapter.d.ts.map +1 -0
- package/dist/keychain-adapter.js +0 -0
- package/dist/keychain-adapter.js.map +1 -0
- package/dist/oauth/browser.d.ts +31 -0
- package/dist/oauth/browser.d.ts.map +1 -0
- package/dist/oauth/browser.js +55 -0
- package/dist/oauth/browser.js.map +1 -0
- package/dist/oauth/callback-server.d.ts +37 -0
- package/dist/oauth/callback-server.d.ts.map +1 -0
- package/dist/oauth/callback-server.js +86 -0
- package/dist/oauth/callback-server.js.map +1 -0
- package/dist/oauth/client.d.ts +57 -0
- package/dist/oauth/client.d.ts.map +1 -0
- package/dist/oauth/client.js +120 -0
- package/dist/oauth/client.js.map +1 -0
- package/dist/oauth/pkce.d.ts +25 -0
- package/dist/oauth/pkce.d.ts.map +1 -0
- package/dist/oauth/pkce.js +36 -0
- package/dist/oauth/pkce.js.map +1 -0
- 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/plugins/integrity-verifier.d.ts +125 -0
- package/dist/plugins/integrity-verifier.d.ts.map +1 -0
- package/dist/plugins/integrity-verifier.js +186 -0
- package/dist/plugins/integrity-verifier.js.map +1 -0
- 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/dist/tool-output-guardrail.d.ts +126 -0
- package/dist/tool-output-guardrail.d.ts.map +1 -0
- package/dist/tool-output-guardrail.js +257 -0
- package/dist/tool-output-guardrail.js.map +1 -0
- package/node_modules-incomplete-release-test/.vite/vitest/da39a3ee5e6b4b0d3255bfef95601890afd80709/results.json +1 -0
- package/package.json +33 -28
- package/scripts/verify-oauth-exports.mjs +29 -0
- package/src/CVE-REMEDIATION.ts +591 -251
- package/src/application/index.ts +10 -10
- package/src/application/services/security-application-service.ts +193 -193
- package/src/authorization/propagator.ts +279 -0
- 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 +340 -271
- package/src/input-validator.ts +466 -466
- package/src/keychain-adapter.ts +0 -0
- package/src/oauth/browser.ts +58 -0
- package/src/oauth/callback-server.ts +97 -0
- package/src/oauth/client.ts +153 -0
- package/src/oauth/pkce.ts +45 -0
- package/src/password-hasher.ts +277 -270
- package/src/path-validator.ts +525 -525
- package/src/plugins/integrity-verifier.ts +265 -0
- package/src/safe-executor.ts +546 -525
- package/src/token-generator.ts +463 -463
- package/src/tool-output-guardrail.ts +360 -0
- 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
package/src/index.ts
CHANGED
|
@@ -1,271 +1,340 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* V3 Security Module
|
|
3
|
-
*
|
|
4
|
-
* Comprehensive security module addressing all identified vulnerabilities:
|
|
5
|
-
* - CVE-2: Weak Password Hashing (password-hasher.ts)
|
|
6
|
-
* - CVE-3: Hardcoded Default Credentials (credential-generator.ts)
|
|
7
|
-
* - HIGH-1: Command Injection (safe-executor.ts)
|
|
8
|
-
* - HIGH-2: Path Traversal (path-validator.ts)
|
|
9
|
-
*
|
|
10
|
-
* Also provides:
|
|
11
|
-
* - Input validation with Zod schemas
|
|
12
|
-
* - Secure token generation
|
|
13
|
-
*
|
|
14
|
-
* @module v3/security
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
// Password Hashing (CVE-2 Fix)
|
|
18
|
-
export {
|
|
19
|
-
PasswordHasher,
|
|
20
|
-
PasswordHashError,
|
|
21
|
-
createPasswordHasher,
|
|
22
|
-
type PasswordHasherConfig,
|
|
23
|
-
type PasswordValidationResult,
|
|
24
|
-
} from './password-hasher.js';
|
|
25
|
-
|
|
26
|
-
// Credential Generation (CVE-3 Fix)
|
|
27
|
-
export {
|
|
28
|
-
CredentialGenerator,
|
|
29
|
-
CredentialGeneratorError,
|
|
30
|
-
createCredentialGenerator,
|
|
31
|
-
generateCredentials,
|
|
32
|
-
type CredentialConfig,
|
|
33
|
-
type GeneratedCredentials,
|
|
34
|
-
type ApiKeyCredential,
|
|
35
|
-
} from './credential-generator.js';
|
|
36
|
-
|
|
37
|
-
// Safe Command Execution (HIGH-1 Fix)
|
|
38
|
-
export {
|
|
39
|
-
SafeExecutor,
|
|
40
|
-
SafeExecutorError,
|
|
41
|
-
createDevelopmentExecutor,
|
|
42
|
-
createReadOnlyExecutor,
|
|
43
|
-
type ExecutorConfig,
|
|
44
|
-
type ExecutionResult,
|
|
45
|
-
type StreamingExecutor,
|
|
46
|
-
} from './safe-executor.js';
|
|
47
|
-
|
|
48
|
-
// Path Validation (HIGH-2 Fix)
|
|
49
|
-
export {
|
|
50
|
-
PathValidator,
|
|
51
|
-
PathValidatorError,
|
|
52
|
-
createProjectPathValidator,
|
|
53
|
-
createFullProjectPathValidator,
|
|
54
|
-
type PathValidatorConfig,
|
|
55
|
-
type PathValidationResult,
|
|
56
|
-
} from './path-validator.js';
|
|
57
|
-
|
|
58
|
-
// Input Validation
|
|
59
|
-
export {
|
|
60
|
-
InputValidator,
|
|
61
|
-
sanitizeString,
|
|
62
|
-
sanitizeHtml,
|
|
63
|
-
sanitizePath,
|
|
64
|
-
// Base schemas
|
|
65
|
-
SafeStringSchema,
|
|
66
|
-
IdentifierSchema,
|
|
67
|
-
FilenameSchema,
|
|
68
|
-
EmailSchema,
|
|
69
|
-
PasswordSchema,
|
|
70
|
-
UUIDSchema,
|
|
71
|
-
HttpsUrlSchema,
|
|
72
|
-
UrlSchema,
|
|
73
|
-
SemverSchema,
|
|
74
|
-
PortSchema,
|
|
75
|
-
IPv4Schema,
|
|
76
|
-
IPSchema,
|
|
77
|
-
// Auth schemas
|
|
78
|
-
UserRoleSchema,
|
|
79
|
-
PermissionSchema,
|
|
80
|
-
LoginRequestSchema,
|
|
81
|
-
CreateUserSchema,
|
|
82
|
-
CreateApiKeySchema,
|
|
83
|
-
// Agent & Task schemas
|
|
84
|
-
AgentTypeSchema,
|
|
85
|
-
SpawnAgentSchema,
|
|
86
|
-
TaskInputSchema,
|
|
87
|
-
// Command & Path schemas
|
|
88
|
-
CommandArgumentSchema,
|
|
89
|
-
PathSchema,
|
|
90
|
-
// Config schemas
|
|
91
|
-
SecurityConfigSchema,
|
|
92
|
-
ExecutorConfigSchema,
|
|
93
|
-
// Utilities
|
|
94
|
-
PATTERNS,
|
|
95
|
-
LIMITS,
|
|
96
|
-
z,
|
|
97
|
-
} from './input-validator.js';
|
|
98
|
-
|
|
99
|
-
// Token Generation
|
|
100
|
-
export {
|
|
101
|
-
TokenGenerator,
|
|
102
|
-
TokenGeneratorError,
|
|
103
|
-
createTokenGenerator,
|
|
104
|
-
getDefaultGenerator,
|
|
105
|
-
quickGenerate,
|
|
106
|
-
type TokenConfig,
|
|
107
|
-
type Token,
|
|
108
|
-
type SignedToken,
|
|
109
|
-
type VerificationCode,
|
|
110
|
-
} from './token-generator.js';
|
|
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
|
-
export
|
|
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
|
-
|
|
1
|
+
/**
|
|
2
|
+
* V3 Security Module
|
|
3
|
+
*
|
|
4
|
+
* Comprehensive security module addressing all identified vulnerabilities:
|
|
5
|
+
* - CVE-2: Weak Password Hashing (password-hasher.ts)
|
|
6
|
+
* - CVE-3: Hardcoded Default Credentials (credential-generator.ts)
|
|
7
|
+
* - HIGH-1: Command Injection (safe-executor.ts)
|
|
8
|
+
* - HIGH-2: Path Traversal (path-validator.ts)
|
|
9
|
+
*
|
|
10
|
+
* Also provides:
|
|
11
|
+
* - Input validation with Zod schemas
|
|
12
|
+
* - Secure token generation
|
|
13
|
+
*
|
|
14
|
+
* @module v3/security
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
// Password Hashing (CVE-2 Fix)
|
|
18
|
+
export {
|
|
19
|
+
PasswordHasher,
|
|
20
|
+
PasswordHashError,
|
|
21
|
+
createPasswordHasher,
|
|
22
|
+
type PasswordHasherConfig,
|
|
23
|
+
type PasswordValidationResult,
|
|
24
|
+
} from './password-hasher.js';
|
|
25
|
+
|
|
26
|
+
// Credential Generation (CVE-3 Fix)
|
|
27
|
+
export {
|
|
28
|
+
CredentialGenerator,
|
|
29
|
+
CredentialGeneratorError,
|
|
30
|
+
createCredentialGenerator,
|
|
31
|
+
generateCredentials,
|
|
32
|
+
type CredentialConfig,
|
|
33
|
+
type GeneratedCredentials,
|
|
34
|
+
type ApiKeyCredential,
|
|
35
|
+
} from './credential-generator.js';
|
|
36
|
+
|
|
37
|
+
// Safe Command Execution (HIGH-1 Fix)
|
|
38
|
+
export {
|
|
39
|
+
SafeExecutor,
|
|
40
|
+
SafeExecutorError,
|
|
41
|
+
createDevelopmentExecutor,
|
|
42
|
+
createReadOnlyExecutor,
|
|
43
|
+
type ExecutorConfig,
|
|
44
|
+
type ExecutionResult,
|
|
45
|
+
type StreamingExecutor,
|
|
46
|
+
} from './safe-executor.js';
|
|
47
|
+
|
|
48
|
+
// Path Validation (HIGH-2 Fix)
|
|
49
|
+
export {
|
|
50
|
+
PathValidator,
|
|
51
|
+
PathValidatorError,
|
|
52
|
+
createProjectPathValidator,
|
|
53
|
+
createFullProjectPathValidator,
|
|
54
|
+
type PathValidatorConfig,
|
|
55
|
+
type PathValidationResult,
|
|
56
|
+
} from './path-validator.js';
|
|
57
|
+
|
|
58
|
+
// Input Validation
|
|
59
|
+
export {
|
|
60
|
+
InputValidator,
|
|
61
|
+
sanitizeString,
|
|
62
|
+
sanitizeHtml,
|
|
63
|
+
sanitizePath,
|
|
64
|
+
// Base schemas
|
|
65
|
+
SafeStringSchema,
|
|
66
|
+
IdentifierSchema,
|
|
67
|
+
FilenameSchema,
|
|
68
|
+
EmailSchema,
|
|
69
|
+
PasswordSchema,
|
|
70
|
+
UUIDSchema,
|
|
71
|
+
HttpsUrlSchema,
|
|
72
|
+
UrlSchema,
|
|
73
|
+
SemverSchema,
|
|
74
|
+
PortSchema,
|
|
75
|
+
IPv4Schema,
|
|
76
|
+
IPSchema,
|
|
77
|
+
// Auth schemas
|
|
78
|
+
UserRoleSchema,
|
|
79
|
+
PermissionSchema,
|
|
80
|
+
LoginRequestSchema,
|
|
81
|
+
CreateUserSchema,
|
|
82
|
+
CreateApiKeySchema,
|
|
83
|
+
// Agent & Task schemas
|
|
84
|
+
AgentTypeSchema,
|
|
85
|
+
SpawnAgentSchema,
|
|
86
|
+
TaskInputSchema,
|
|
87
|
+
// Command & Path schemas
|
|
88
|
+
CommandArgumentSchema,
|
|
89
|
+
PathSchema,
|
|
90
|
+
// Config schemas
|
|
91
|
+
SecurityConfigSchema,
|
|
92
|
+
ExecutorConfigSchema,
|
|
93
|
+
// Utilities
|
|
94
|
+
PATTERNS,
|
|
95
|
+
LIMITS,
|
|
96
|
+
z,
|
|
97
|
+
} from './input-validator.js';
|
|
98
|
+
|
|
99
|
+
// Token Generation
|
|
100
|
+
export {
|
|
101
|
+
TokenGenerator,
|
|
102
|
+
TokenGeneratorError,
|
|
103
|
+
createTokenGenerator,
|
|
104
|
+
getDefaultGenerator,
|
|
105
|
+
quickGenerate,
|
|
106
|
+
type TokenConfig,
|
|
107
|
+
type Token,
|
|
108
|
+
type SignedToken,
|
|
109
|
+
type VerificationCode,
|
|
110
|
+
} from './token-generator.js';
|
|
111
|
+
|
|
112
|
+
// Tool-Output Guardrail (ADR-131 — closes OWASP ASI01 gap; ruvnet/ruflo#2149)
|
|
113
|
+
export {
|
|
114
|
+
ToolOutputGuardrail,
|
|
115
|
+
createToolOutputGuardrail,
|
|
116
|
+
isToolOutputSafe,
|
|
117
|
+
type GuardrailConfig,
|
|
118
|
+
type GuardrailResult,
|
|
119
|
+
type GuardrailAction,
|
|
120
|
+
type InjectionFinding,
|
|
121
|
+
type InjectionSeverity,
|
|
122
|
+
type InjectionCategory,
|
|
123
|
+
} from './tool-output-guardrail.js';
|
|
124
|
+
|
|
125
|
+
// Agent Authorization Propagation (ADR-144 P1 — ruvnet/ruflo#2248)
|
|
126
|
+
// Action-layer: SendMessage envelope + per-action scope check + MCP server
|
|
127
|
+
// identity probe. Wraps the comms layer in P2; wraps the dispatcher in P3.
|
|
128
|
+
export {
|
|
129
|
+
AgentAuthorizationPropagator,
|
|
130
|
+
AuthorizationPropagationError,
|
|
131
|
+
makeLegacyPermissiveScope,
|
|
132
|
+
type AuthScope,
|
|
133
|
+
type SendMessageEnvelope,
|
|
134
|
+
type ToolCallDecision,
|
|
135
|
+
} from './authorization/propagator.js';
|
|
136
|
+
|
|
137
|
+
// OAuth 2.0 + PKCE + OS Keychain (ADR-306)
|
|
138
|
+
// A TypeScript port of meta-proxy's proven oauth/{client,pkce,browser,
|
|
139
|
+
// callback_server}.rs — see src/oauth/client.ts for why this targets the
|
|
140
|
+
// live auth.cognitum.one surface rather than ADR-308's unconfirmed spec.
|
|
141
|
+
export {
|
|
142
|
+
CLIENT_ID as OAUTH_CLIENT_ID,
|
|
143
|
+
SCOPE as OAUTH_SCOPE,
|
|
144
|
+
OOB_REDIRECT_URI,
|
|
145
|
+
OAuthError,
|
|
146
|
+
authorizeUrl,
|
|
147
|
+
exchangeCode,
|
|
148
|
+
refreshToken,
|
|
149
|
+
exchangeManualCode,
|
|
150
|
+
type TokenResponse as OAuthTokenResponse,
|
|
151
|
+
} from './oauth/client.js';
|
|
152
|
+
export { generate as generatePkce, challengeFromVerifier, type PkceRequest } from './oauth/pkce.js';
|
|
153
|
+
export { CallbackServer, CallbackTimeoutError, type CallbackResult } from './oauth/callback-server.js';
|
|
154
|
+
export { openBrowser } from './oauth/browser.js';
|
|
155
|
+
|
|
156
|
+
// OS Keychain Adapter (ADR-306)
|
|
157
|
+
export {
|
|
158
|
+
createKeychainAdapter,
|
|
159
|
+
SessionOnlyKeychainAdapter,
|
|
160
|
+
type KeychainAdapter,
|
|
161
|
+
} from './keychain-adapter.js';
|
|
162
|
+
|
|
163
|
+
// Plugin Integrity Verifier (ADR-145 P1 — ruvnet/ruflo#2254)
|
|
164
|
+
// Install-layer: Ed25519 signature verification + trust-anchor allowlist.
|
|
165
|
+
// Stage-2 semantic-intent scan (SCH defence) lands in P2.
|
|
166
|
+
export {
|
|
167
|
+
PluginIntegrityVerifier,
|
|
168
|
+
canonicalize,
|
|
169
|
+
hashManifest,
|
|
170
|
+
fingerprint,
|
|
171
|
+
findAnchor,
|
|
172
|
+
type PluginManifest,
|
|
173
|
+
type SignedPluginManifest,
|
|
174
|
+
type TrustAnchor,
|
|
175
|
+
type TrustAnchors,
|
|
176
|
+
type VerificationStatus,
|
|
177
|
+
type VerificationResult,
|
|
178
|
+
type VerifierConfig,
|
|
179
|
+
} from './plugins/integrity-verifier.js';
|
|
180
|
+
|
|
181
|
+
// ============================================================================
|
|
182
|
+
// Convenience Factory Functions
|
|
183
|
+
// ============================================================================
|
|
184
|
+
|
|
185
|
+
import { PasswordHasher } from './password-hasher.js';
|
|
186
|
+
import { CredentialGenerator } from './credential-generator.js';
|
|
187
|
+
import { SafeExecutor } from './safe-executor.js';
|
|
188
|
+
import { PathValidator } from './path-validator.js';
|
|
189
|
+
import { TokenGenerator } from './token-generator.js';
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Security module configuration
|
|
193
|
+
*/
|
|
194
|
+
export interface SecurityModuleConfig {
|
|
195
|
+
/**
|
|
196
|
+
* Project root directory for path validation
|
|
197
|
+
*/
|
|
198
|
+
projectRoot: string;
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* HMAC secret for token signing
|
|
202
|
+
*/
|
|
203
|
+
hmacSecret: string;
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Bcrypt rounds for password hashing
|
|
207
|
+
* Default: 12
|
|
208
|
+
*/
|
|
209
|
+
bcryptRounds?: number;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Allowed commands for safe executor
|
|
213
|
+
* Default: ['git', 'npm', 'node']
|
|
214
|
+
*/
|
|
215
|
+
allowedCommands?: string[];
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Complete security module instance
|
|
220
|
+
*/
|
|
221
|
+
export interface SecurityModule {
|
|
222
|
+
passwordHasher: PasswordHasher;
|
|
223
|
+
credentialGenerator: CredentialGenerator;
|
|
224
|
+
safeExecutor: SafeExecutor;
|
|
225
|
+
pathValidator: PathValidator;
|
|
226
|
+
tokenGenerator: TokenGenerator;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Creates a complete security module with all components configured.
|
|
231
|
+
*
|
|
232
|
+
* @param config - Module configuration
|
|
233
|
+
* @returns Complete security module
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* const security = createSecurityModule({
|
|
238
|
+
* projectRoot: '/workspaces/project',
|
|
239
|
+
* hmacSecret: process.env.HMAC_SECRET!,
|
|
240
|
+
* });
|
|
241
|
+
*
|
|
242
|
+
* // Hash password
|
|
243
|
+
* const hash = await security.passwordHasher.hash('password');
|
|
244
|
+
*
|
|
245
|
+
* // Validate path
|
|
246
|
+
* const result = await security.pathValidator.validate('/workspaces/project/src/file.ts');
|
|
247
|
+
*
|
|
248
|
+
* // Execute command safely
|
|
249
|
+
* const output = await security.safeExecutor.execute('git', ['status']);
|
|
250
|
+
* ```
|
|
251
|
+
*/
|
|
252
|
+
export function createSecurityModule(config: SecurityModuleConfig): SecurityModule {
|
|
253
|
+
return {
|
|
254
|
+
passwordHasher: new PasswordHasher({
|
|
255
|
+
rounds: config.bcryptRounds ?? 12,
|
|
256
|
+
}),
|
|
257
|
+
credentialGenerator: new CredentialGenerator(),
|
|
258
|
+
safeExecutor: new SafeExecutor({
|
|
259
|
+
allowedCommands: config.allowedCommands ?? ['git', 'npm', 'node'],
|
|
260
|
+
}),
|
|
261
|
+
pathValidator: new PathValidator({
|
|
262
|
+
allowedPrefixes: [config.projectRoot],
|
|
263
|
+
allowHidden: true,
|
|
264
|
+
}),
|
|
265
|
+
tokenGenerator: new TokenGenerator({
|
|
266
|
+
hmacSecret: config.hmacSecret,
|
|
267
|
+
}),
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// ============================================================================
|
|
272
|
+
// Security Constants
|
|
273
|
+
// ============================================================================
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Minimum recommended bcrypt rounds for production
|
|
277
|
+
*/
|
|
278
|
+
export const MIN_BCRYPT_ROUNDS = 12;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Maximum recommended bcrypt rounds (performance consideration)
|
|
282
|
+
*/
|
|
283
|
+
export const MAX_BCRYPT_ROUNDS = 14;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Minimum password length
|
|
287
|
+
*/
|
|
288
|
+
export const MIN_PASSWORD_LENGTH = 8;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Maximum password length (bcrypt limitation)
|
|
292
|
+
*/
|
|
293
|
+
export const MAX_PASSWORD_LENGTH = 72;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Default token expiration in seconds (1 hour)
|
|
297
|
+
*/
|
|
298
|
+
export const DEFAULT_TOKEN_EXPIRATION = 3600;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Default session expiration in seconds (24 hours)
|
|
302
|
+
*/
|
|
303
|
+
export const DEFAULT_SESSION_EXPIRATION = 86400;
|
|
304
|
+
|
|
305
|
+
// ============================================================================
|
|
306
|
+
// Security Audit Helper
|
|
307
|
+
// ============================================================================
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Checks security configuration for common issues.
|
|
311
|
+
*
|
|
312
|
+
* @param config - Configuration to audit
|
|
313
|
+
* @returns Array of security warnings
|
|
314
|
+
*/
|
|
315
|
+
export function auditSecurityConfig(config: Partial<SecurityModuleConfig>): string[] {
|
|
316
|
+
const warnings: string[] = [];
|
|
317
|
+
|
|
318
|
+
if (config.bcryptRounds && config.bcryptRounds < MIN_BCRYPT_ROUNDS) {
|
|
319
|
+
warnings.push(`bcryptRounds (${config.bcryptRounds}) below recommended minimum (${MIN_BCRYPT_ROUNDS})`);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
if (config.hmacSecret && config.hmacSecret.length < 32) {
|
|
323
|
+
warnings.push('hmacSecret should be at least 32 characters');
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if (!config.projectRoot) {
|
|
327
|
+
warnings.push('projectRoot not configured - path validation may be disabled');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (config.allowedCommands && config.allowedCommands.length === 0) {
|
|
331
|
+
warnings.push('No commands allowed - executor will reject all commands');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
return warnings;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
/**
|
|
338
|
+
* Security module version
|
|
339
|
+
*/
|
|
340
|
+
export const SECURITY_MODULE_VERSION = '3.0.0-alpha.1';
|