@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.
- 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/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- 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/mcp-caller-identity.d.ts +101 -0
- package/dist/mcp-caller-identity.d.ts.map +1 -0
- package/dist/mcp-caller-identity.js +0 -0
- package/dist/mcp-caller-identity.js.map +1 -0
- package/dist/mcp-composition-inspector.d.ts +133 -0
- package/dist/mcp-composition-inspector.d.ts.map +1 -0
- package/dist/mcp-composition-inspector.js +254 -0
- package/dist/mcp-composition-inspector.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/path-validator.d.ts +23 -0
- package/dist/path-validator.d.ts.map +1 -1
- package/dist/path-validator.js +128 -5
- package/dist/path-validator.js.map +1 -1
- package/dist/policy/canonical.d.ts +5 -0
- package/dist/policy/canonical.d.ts.map +1 -0
- package/dist/policy/canonical.js +30 -0
- package/dist/policy/canonical.js.map +1 -0
- package/dist/policy/engine.d.ts +34 -0
- package/dist/policy/engine.d.ts.map +1 -0
- package/dist/policy/engine.js +285 -0
- package/dist/policy/engine.js.map +1 -0
- package/dist/policy/envelope.d.ts +9 -0
- package/dist/policy/envelope.d.ts.map +1 -0
- package/dist/policy/envelope.js +90 -0
- package/dist/policy/envelope.js.map +1 -0
- package/dist/policy/evaluator.d.ts +4 -0
- package/dist/policy/evaluator.d.ts.map +1 -0
- package/dist/policy/evaluator.js +119 -0
- package/dist/policy/evaluator.js.map +1 -0
- package/dist/policy/index.d.ts +7 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +7 -0
- package/dist/policy/index.js.map +1 -0
- package/dist/policy/product-plane.d.ts +238 -0
- package/dist/policy/product-plane.d.ts.map +1 -0
- package/dist/policy/product-plane.js +1022 -0
- package/dist/policy/product-plane.js.map +1 -0
- package/dist/policy/types.d.ts +169 -0
- package/dist/policy/types.d.ts.map +1 -0
- package/dist/policy/types.js +2 -0
- package/dist/policy/types.js.map +1 -0
- package/dist/safe-git.d.ts +22 -0
- package/dist/safe-git.d.ts.map +1 -0
- package/dist/safe-git.js +63 -0
- package/dist/safe-git.js.map +1 -0
- package/package.json +17 -5
- package/.claude-flow/data/pending-insights.jsonl +0 -6
- package/.claude-flow/neural/stats.json +0 -6
- package/__tests__/acceptance/security-compliance.test.ts +0 -674
- package/__tests__/authorization-propagator.test.ts +0 -155
- package/__tests__/credential-generator.test.ts +0 -310
- package/__tests__/fixtures/configurations.ts +0 -425
- package/__tests__/fixtures/index.ts +0 -21
- package/__tests__/helpers/create-mock.ts +0 -469
- package/__tests__/helpers/index.ts +0 -32
- package/__tests__/input-validator.test.ts +0 -382
- package/__tests__/integration/security-flow.test.ts +0 -606
- package/__tests__/password-hasher.test.ts +0 -239
- package/__tests__/path-validator.test.ts +0 -302
- package/__tests__/plugin-integrity-verifier.test.ts +0 -199
- package/__tests__/safe-executor.test.ts +0 -292
- package/__tests__/token-generator.test.ts +0 -371
- package/__tests__/tool-output-guardrail.test.ts +0 -256
- package/__tests__/unit/credential-generator.test.ts +0 -182
- package/__tests__/unit/password-hasher.test.ts +0 -359
- package/__tests__/unit/path-validator.test.ts +0 -509
- package/__tests__/unit/safe-executor.test.ts +0 -667
- package/__tests__/unit/token-generator.test.ts +0 -310
- package/ruvector.db +0 -0
- package/src/CVE-REMEDIATION.ts +0 -251
- package/src/application/index.ts +0 -10
- package/src/application/services/security-application-service.ts +0 -193
- package/src/authorization/propagator.ts +0 -279
- package/src/credential-generator.ts +0 -368
- package/src/domain/entities/security-context.ts +0 -173
- package/src/domain/index.ts +0 -17
- package/src/domain/services/security-domain-service.ts +0 -296
- package/src/index.ts +0 -314
- package/src/input-validator.ts +0 -466
- package/src/password-hasher.ts +0 -277
- package/src/path-validator.ts +0 -525
- package/src/plugins/integrity-verifier.ts +0 -265
- package/src/safe-executor.ts +0 -546
- package/src/token-generator.ts +0 -463
- package/src/tool-output-guardrail.ts +0 -360
- package/tmp.json +0 -0
- package/tsconfig.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vitest.config.ts +0 -20
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Security Domain Service - Domain Layer
|
|
3
|
-
*
|
|
4
|
-
* Contains security logic for validation, policy enforcement, and threat detection.
|
|
5
|
-
*
|
|
6
|
-
* @module v3/security/domain/services
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { SecurityContext, PermissionLevel } from '../entities/security-context.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Validation result
|
|
13
|
-
*/
|
|
14
|
-
export interface ValidationResult {
|
|
15
|
-
valid: boolean;
|
|
16
|
-
errors: string[];
|
|
17
|
-
warnings: string[];
|
|
18
|
-
sanitized?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Threat detection result
|
|
23
|
-
*/
|
|
24
|
-
export interface ThreatDetectionResult {
|
|
25
|
-
safe: boolean;
|
|
26
|
-
threats: Array<{
|
|
27
|
-
type: string;
|
|
28
|
-
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
29
|
-
description: string;
|
|
30
|
-
location?: string;
|
|
31
|
-
}>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Security Domain Service
|
|
36
|
-
*/
|
|
37
|
-
export class SecurityDomainService {
|
|
38
|
-
// Dangerous patterns for path traversal
|
|
39
|
-
private static readonly PATH_TRAVERSAL_PATTERNS = [
|
|
40
|
-
/\.\./,
|
|
41
|
-
/~\//,
|
|
42
|
-
/^\/etc\//,
|
|
43
|
-
/^\/tmp\//,
|
|
44
|
-
/^\/var\/log\//,
|
|
45
|
-
/^C:\\Windows/i,
|
|
46
|
-
/^C:\\Users\\[^\\]+\\AppData/i,
|
|
47
|
-
];
|
|
48
|
-
|
|
49
|
-
// Dangerous command patterns
|
|
50
|
-
private static readonly DANGEROUS_COMMANDS = [
|
|
51
|
-
/^rm\s+-rf\s+\//,
|
|
52
|
-
/^rm\s+-rf\s+\*/,
|
|
53
|
-
/^dd\s+if=/,
|
|
54
|
-
/^mkfs\./,
|
|
55
|
-
/^format\s+/i,
|
|
56
|
-
/^del\s+\/s\s+\/q/i,
|
|
57
|
-
/>\s*\/dev\/sd[a-z]/,
|
|
58
|
-
/\|\s*bash$/,
|
|
59
|
-
/\|\s*sh$/,
|
|
60
|
-
/eval\s*\(/,
|
|
61
|
-
/exec\s*\(/,
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
// SQL injection patterns
|
|
65
|
-
private static readonly SQL_INJECTION_PATTERNS = [
|
|
66
|
-
/'\s*OR\s+'1'\s*=\s*'1/i,
|
|
67
|
-
/'\s*OR\s+1\s*=\s*1/i,
|
|
68
|
-
/;\s*DROP\s+TABLE/i,
|
|
69
|
-
/;\s*DELETE\s+FROM/i,
|
|
70
|
-
/UNION\s+SELECT/i,
|
|
71
|
-
/--\s*$/,
|
|
72
|
-
];
|
|
73
|
-
|
|
74
|
-
// XSS patterns
|
|
75
|
-
private static readonly XSS_PATTERNS = [
|
|
76
|
-
/<script[\s>]/i,
|
|
77
|
-
/javascript:/i,
|
|
78
|
-
/on\w+\s*=/i,
|
|
79
|
-
/<iframe/i,
|
|
80
|
-
/<object/i,
|
|
81
|
-
/<embed/i,
|
|
82
|
-
];
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Validate a file path
|
|
86
|
-
*/
|
|
87
|
-
validatePath(path: string, context: SecurityContext): ValidationResult {
|
|
88
|
-
const errors: string[] = [];
|
|
89
|
-
const warnings: string[] = [];
|
|
90
|
-
|
|
91
|
-
// Check path traversal
|
|
92
|
-
for (const pattern of SecurityDomainService.PATH_TRAVERSAL_PATTERNS) {
|
|
93
|
-
if (pattern.test(path)) {
|
|
94
|
-
errors.push(`Path traversal detected: ${pattern.source}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// Check context permissions
|
|
99
|
-
if (!context.canAccessPath(path)) {
|
|
100
|
-
errors.push(`Access denied to path: ${path}`);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Check for suspicious paths
|
|
104
|
-
if (path.includes('..')) {
|
|
105
|
-
warnings.push('Path contains parent directory reference');
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
valid: errors.length === 0,
|
|
110
|
-
errors,
|
|
111
|
-
warnings,
|
|
112
|
-
sanitized: this.sanitizePath(path),
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Validate a command
|
|
118
|
-
*/
|
|
119
|
-
validateCommand(command: string, context: SecurityContext): ValidationResult {
|
|
120
|
-
const errors: string[] = [];
|
|
121
|
-
const warnings: string[] = [];
|
|
122
|
-
|
|
123
|
-
// Check dangerous commands
|
|
124
|
-
for (const pattern of SecurityDomainService.DANGEROUS_COMMANDS) {
|
|
125
|
-
if (pattern.test(command)) {
|
|
126
|
-
errors.push(`Dangerous command pattern detected: ${pattern.source}`);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Check context permissions
|
|
131
|
-
if (!context.canExecuteCommand(command)) {
|
|
132
|
-
errors.push(`Command execution denied: ${command}`);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!context.hasPermission('execute')) {
|
|
136
|
-
errors.push('Execute permission required');
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Check for shell injection
|
|
140
|
-
if (/[;&|`$(){}]/.test(command)) {
|
|
141
|
-
warnings.push('Command contains shell metacharacters');
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
valid: errors.length === 0,
|
|
146
|
-
errors,
|
|
147
|
-
warnings,
|
|
148
|
-
sanitized: this.sanitizeCommand(command),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Validate user input
|
|
154
|
-
*/
|
|
155
|
-
validateInput(input: string): ValidationResult {
|
|
156
|
-
const errors: string[] = [];
|
|
157
|
-
const warnings: string[] = [];
|
|
158
|
-
|
|
159
|
-
// Check for SQL injection
|
|
160
|
-
for (const pattern of SecurityDomainService.SQL_INJECTION_PATTERNS) {
|
|
161
|
-
if (pattern.test(input)) {
|
|
162
|
-
errors.push(`SQL injection pattern detected`);
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Check for XSS
|
|
168
|
-
for (const pattern of SecurityDomainService.XSS_PATTERNS) {
|
|
169
|
-
if (pattern.test(input)) {
|
|
170
|
-
errors.push(`XSS pattern detected`);
|
|
171
|
-
break;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Check length
|
|
176
|
-
if (input.length > 10000) {
|
|
177
|
-
warnings.push('Input exceeds recommended length');
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return {
|
|
181
|
-
valid: errors.length === 0,
|
|
182
|
-
errors,
|
|
183
|
-
warnings,
|
|
184
|
-
sanitized: this.sanitizeInput(input),
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Detect threats in content
|
|
190
|
-
*/
|
|
191
|
-
detectThreats(content: string): ThreatDetectionResult {
|
|
192
|
-
const threats: ThreatDetectionResult['threats'] = [];
|
|
193
|
-
|
|
194
|
-
// Check for various threat patterns
|
|
195
|
-
if (/<script/i.test(content)) {
|
|
196
|
-
threats.push({
|
|
197
|
-
type: 'xss',
|
|
198
|
-
severity: 'high',
|
|
199
|
-
description: 'Script tag detected',
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
if (/password\s*[:=]\s*["'][^"']+["']/i.test(content)) {
|
|
204
|
-
threats.push({
|
|
205
|
-
type: 'credential-exposure',
|
|
206
|
-
severity: 'critical',
|
|
207
|
-
description: 'Hardcoded password detected',
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
if (/api[_-]?key\s*[:=]\s*["'][^"']+["']/i.test(content)) {
|
|
212
|
-
threats.push({
|
|
213
|
-
type: 'credential-exposure',
|
|
214
|
-
severity: 'critical',
|
|
215
|
-
description: 'API key detected',
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
if (/eval\s*\(/.test(content)) {
|
|
220
|
-
threats.push({
|
|
221
|
-
type: 'code-injection',
|
|
222
|
-
severity: 'high',
|
|
223
|
-
description: 'Eval statement detected',
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return {
|
|
228
|
-
safe: threats.length === 0,
|
|
229
|
-
threats,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Sanitize path
|
|
235
|
-
*/
|
|
236
|
-
private sanitizePath(path: string): string {
|
|
237
|
-
return path
|
|
238
|
-
.replace(/\.\./g, '')
|
|
239
|
-
.replace(/\/\//g, '/')
|
|
240
|
-
.replace(/^~\//, '')
|
|
241
|
-
.trim();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
/**
|
|
245
|
-
* Sanitize command
|
|
246
|
-
*/
|
|
247
|
-
private sanitizeCommand(command: string): string {
|
|
248
|
-
return command
|
|
249
|
-
.replace(/[;&|`$]/g, '')
|
|
250
|
-
.replace(/\$\([^)]*\)/g, '')
|
|
251
|
-
.trim();
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Sanitize user input
|
|
256
|
-
*/
|
|
257
|
-
private sanitizeInput(input: string): string {
|
|
258
|
-
return input
|
|
259
|
-
.replace(/</g, '<')
|
|
260
|
-
.replace(/>/g, '>')
|
|
261
|
-
.replace(/"/g, '"')
|
|
262
|
-
.replace(/'/g, ''')
|
|
263
|
-
.replace(/\//g, '/');
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Create security context for agent
|
|
268
|
-
*/
|
|
269
|
-
createAgentContext(
|
|
270
|
-
agentId: string,
|
|
271
|
-
role: string,
|
|
272
|
-
customPaths?: string[]
|
|
273
|
-
): SecurityContext {
|
|
274
|
-
// Default permissions based on role
|
|
275
|
-
const rolePermissions: Record<string, PermissionLevel[]> = {
|
|
276
|
-
'queen-coordinator': ['read', 'write', 'execute', 'admin'],
|
|
277
|
-
'security-architect': ['read', 'write', 'execute', 'admin'],
|
|
278
|
-
'coder': ['read', 'write', 'execute'],
|
|
279
|
-
'reviewer': ['read'],
|
|
280
|
-
'tester': ['read', 'execute'],
|
|
281
|
-
default: ['read'],
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
const permissions = rolePermissions[role] ?? rolePermissions.default;
|
|
285
|
-
|
|
286
|
-
return SecurityContext.create({
|
|
287
|
-
principalId: agentId,
|
|
288
|
-
principalType: 'agent',
|
|
289
|
-
permissions,
|
|
290
|
-
allowedPaths: customPaths ?? ['./src', './tests', './docs'],
|
|
291
|
-
blockedPaths: ['/etc', '/var', '~/', '../'],
|
|
292
|
-
allowedCommands: ['npm', 'node', 'git', 'vitest'],
|
|
293
|
-
blockedCommands: ['rm -rf /', 'dd', 'mkfs', 'format'],
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,314 +0,0 @@
|
|
|
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
|
-
// Plugin Integrity Verifier (ADR-145 P1 — ruvnet/ruflo#2254)
|
|
138
|
-
// Install-layer: Ed25519 signature verification + trust-anchor allowlist.
|
|
139
|
-
// Stage-2 semantic-intent scan (SCH defence) lands in P2.
|
|
140
|
-
export {
|
|
141
|
-
PluginIntegrityVerifier,
|
|
142
|
-
canonicalize,
|
|
143
|
-
hashManifest,
|
|
144
|
-
fingerprint,
|
|
145
|
-
findAnchor,
|
|
146
|
-
type PluginManifest,
|
|
147
|
-
type SignedPluginManifest,
|
|
148
|
-
type TrustAnchor,
|
|
149
|
-
type TrustAnchors,
|
|
150
|
-
type VerificationStatus,
|
|
151
|
-
type VerificationResult,
|
|
152
|
-
type VerifierConfig,
|
|
153
|
-
} from './plugins/integrity-verifier.js';
|
|
154
|
-
|
|
155
|
-
// ============================================================================
|
|
156
|
-
// Convenience Factory Functions
|
|
157
|
-
// ============================================================================
|
|
158
|
-
|
|
159
|
-
import { PasswordHasher } from './password-hasher.js';
|
|
160
|
-
import { CredentialGenerator } from './credential-generator.js';
|
|
161
|
-
import { SafeExecutor } from './safe-executor.js';
|
|
162
|
-
import { PathValidator } from './path-validator.js';
|
|
163
|
-
import { TokenGenerator } from './token-generator.js';
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Security module configuration
|
|
167
|
-
*/
|
|
168
|
-
export interface SecurityModuleConfig {
|
|
169
|
-
/**
|
|
170
|
-
* Project root directory for path validation
|
|
171
|
-
*/
|
|
172
|
-
projectRoot: string;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* HMAC secret for token signing
|
|
176
|
-
*/
|
|
177
|
-
hmacSecret: string;
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* Bcrypt rounds for password hashing
|
|
181
|
-
* Default: 12
|
|
182
|
-
*/
|
|
183
|
-
bcryptRounds?: number;
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Allowed commands for safe executor
|
|
187
|
-
* Default: ['git', 'npm', 'node']
|
|
188
|
-
*/
|
|
189
|
-
allowedCommands?: string[];
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Complete security module instance
|
|
194
|
-
*/
|
|
195
|
-
export interface SecurityModule {
|
|
196
|
-
passwordHasher: PasswordHasher;
|
|
197
|
-
credentialGenerator: CredentialGenerator;
|
|
198
|
-
safeExecutor: SafeExecutor;
|
|
199
|
-
pathValidator: PathValidator;
|
|
200
|
-
tokenGenerator: TokenGenerator;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Creates a complete security module with all components configured.
|
|
205
|
-
*
|
|
206
|
-
* @param config - Module configuration
|
|
207
|
-
* @returns Complete security module
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* ```typescript
|
|
211
|
-
* const security = createSecurityModule({
|
|
212
|
-
* projectRoot: '/workspaces/project',
|
|
213
|
-
* hmacSecret: process.env.HMAC_SECRET!,
|
|
214
|
-
* });
|
|
215
|
-
*
|
|
216
|
-
* // Hash password
|
|
217
|
-
* const hash = await security.passwordHasher.hash('password');
|
|
218
|
-
*
|
|
219
|
-
* // Validate path
|
|
220
|
-
* const result = await security.pathValidator.validate('/workspaces/project/src/file.ts');
|
|
221
|
-
*
|
|
222
|
-
* // Execute command safely
|
|
223
|
-
* const output = await security.safeExecutor.execute('git', ['status']);
|
|
224
|
-
* ```
|
|
225
|
-
*/
|
|
226
|
-
export function createSecurityModule(config: SecurityModuleConfig): SecurityModule {
|
|
227
|
-
return {
|
|
228
|
-
passwordHasher: new PasswordHasher({
|
|
229
|
-
rounds: config.bcryptRounds ?? 12,
|
|
230
|
-
}),
|
|
231
|
-
credentialGenerator: new CredentialGenerator(),
|
|
232
|
-
safeExecutor: new SafeExecutor({
|
|
233
|
-
allowedCommands: config.allowedCommands ?? ['git', 'npm', 'node'],
|
|
234
|
-
}),
|
|
235
|
-
pathValidator: new PathValidator({
|
|
236
|
-
allowedPrefixes: [config.projectRoot],
|
|
237
|
-
allowHidden: true,
|
|
238
|
-
}),
|
|
239
|
-
tokenGenerator: new TokenGenerator({
|
|
240
|
-
hmacSecret: config.hmacSecret,
|
|
241
|
-
}),
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ============================================================================
|
|
246
|
-
// Security Constants
|
|
247
|
-
// ============================================================================
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Minimum recommended bcrypt rounds for production
|
|
251
|
-
*/
|
|
252
|
-
export const MIN_BCRYPT_ROUNDS = 12;
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
* Maximum recommended bcrypt rounds (performance consideration)
|
|
256
|
-
*/
|
|
257
|
-
export const MAX_BCRYPT_ROUNDS = 14;
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Minimum password length
|
|
261
|
-
*/
|
|
262
|
-
export const MIN_PASSWORD_LENGTH = 8;
|
|
263
|
-
|
|
264
|
-
/**
|
|
265
|
-
* Maximum password length (bcrypt limitation)
|
|
266
|
-
*/
|
|
267
|
-
export const MAX_PASSWORD_LENGTH = 72;
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* Default token expiration in seconds (1 hour)
|
|
271
|
-
*/
|
|
272
|
-
export const DEFAULT_TOKEN_EXPIRATION = 3600;
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Default session expiration in seconds (24 hours)
|
|
276
|
-
*/
|
|
277
|
-
export const DEFAULT_SESSION_EXPIRATION = 86400;
|
|
278
|
-
|
|
279
|
-
// ============================================================================
|
|
280
|
-
// Security Audit Helper
|
|
281
|
-
// ============================================================================
|
|
282
|
-
|
|
283
|
-
/**
|
|
284
|
-
* Checks security configuration for common issues.
|
|
285
|
-
*
|
|
286
|
-
* @param config - Configuration to audit
|
|
287
|
-
* @returns Array of security warnings
|
|
288
|
-
*/
|
|
289
|
-
export function auditSecurityConfig(config: Partial<SecurityModuleConfig>): string[] {
|
|
290
|
-
const warnings: string[] = [];
|
|
291
|
-
|
|
292
|
-
if (config.bcryptRounds && config.bcryptRounds < MIN_BCRYPT_ROUNDS) {
|
|
293
|
-
warnings.push(`bcryptRounds (${config.bcryptRounds}) below recommended minimum (${MIN_BCRYPT_ROUNDS})`);
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
if (config.hmacSecret && config.hmacSecret.length < 32) {
|
|
297
|
-
warnings.push('hmacSecret should be at least 32 characters');
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
if (!config.projectRoot) {
|
|
301
|
-
warnings.push('projectRoot not configured - path validation may be disabled');
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
if (config.allowedCommands && config.allowedCommands.length === 0) {
|
|
305
|
-
warnings.push('No commands allowed - executor will reject all commands');
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return warnings;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
/**
|
|
312
|
-
* Security module version
|
|
313
|
-
*/
|
|
314
|
-
export const SECURITY_MODULE_VERSION = '3.0.0-alpha.1';
|