@sparkleideas/security 3.0.0-alpha.20 → 3.0.0-alpha.29
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 +86 -0
- package/dist/CVE-REMEDIATION.d.ts.map +1 -0
- package/dist/CVE-REMEDIATION.js +221 -0
- package/dist/CVE-REMEDIATION.js.map +1 -0
- package/dist/application/index.d.ts +7 -0
- package/dist/application/index.d.ts.map +1 -0
- package/dist/application/index.js +7 -0
- package/dist/application/index.js.map +1 -0
- package/dist/application/services/security-application-service.d.ts +71 -0
- package/dist/application/services/security-application-service.d.ts.map +1 -0
- package/dist/application/services/security-application-service.js +153 -0
- package/dist/application/services/security-application-service.js.map +1 -0
- package/dist/credential-generator.d.ts +176 -0
- package/dist/credential-generator.d.ts.map +1 -0
- package/dist/credential-generator.js +272 -0
- package/dist/credential-generator.js.map +1 -0
- package/dist/domain/entities/security-context.d.ts +68 -0
- package/dist/domain/entities/security-context.d.ts.map +1 -0
- package/dist/domain/entities/security-context.js +132 -0
- package/dist/domain/entities/security-context.js.map +1 -0
- package/dist/domain/index.d.ts +8 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +8 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/services/security-domain-service.d.ts +71 -0
- package/dist/domain/services/security-domain-service.d.ts.map +1 -0
- package/dist/domain/services/security-domain-service.js +237 -0
- package/dist/domain/services/security-domain-service.js.map +1 -0
- package/dist/index.d.ts +119 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/input-validator.d.ts +338 -0
- package/dist/input-validator.d.ts.map +1 -0
- package/dist/input-validator.js +393 -0
- package/dist/input-validator.js.map +1 -0
- package/dist/password-hasher.d.ts +128 -0
- package/dist/password-hasher.d.ts.map +1 -0
- package/dist/password-hasher.js +183 -0
- package/dist/password-hasher.js.map +1 -0
- package/dist/path-validator.d.ts +148 -0
- package/dist/path-validator.d.ts.map +1 -0
- package/dist/path-validator.js +421 -0
- package/dist/path-validator.js.map +1 -0
- package/dist/safe-executor.d.ts +173 -0
- package/dist/safe-executor.d.ts.map +1 -0
- package/dist/safe-executor.js +370 -0
- package/dist/safe-executor.js.map +1 -0
- package/dist/token-generator.d.ts +224 -0
- package/dist/token-generator.d.ts.map +1 -0
- package/dist/token-generator.js +351 -0
- package/dist/token-generator.js.map +1 -0
- package/package.json +1 -1
- package/tsconfig.build.tsbuildinfo +1 -0
|
@@ -0,0 +1,393 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Input Validator - Comprehensive Input Validation
|
|
3
|
+
*
|
|
4
|
+
* Provides Zod-based validation schemas for all security-critical inputs.
|
|
5
|
+
*
|
|
6
|
+
* Security Properties:
|
|
7
|
+
* - Type-safe validation
|
|
8
|
+
* - Custom error messages
|
|
9
|
+
* - Sanitization transforms
|
|
10
|
+
* - Reusable schemas
|
|
11
|
+
*
|
|
12
|
+
* @module v3/security/input-validator
|
|
13
|
+
*/
|
|
14
|
+
import { z } from 'zod';
|
|
15
|
+
/**
|
|
16
|
+
* Custom error map for security-focused messages
|
|
17
|
+
*/
|
|
18
|
+
const securityErrorMap = (issue, ctx) => {
|
|
19
|
+
switch (issue.code) {
|
|
20
|
+
case z.ZodIssueCode.too_big:
|
|
21
|
+
return { message: `Input exceeds maximum allowed size` };
|
|
22
|
+
case z.ZodIssueCode.too_small:
|
|
23
|
+
return { message: `Input below minimum required size` };
|
|
24
|
+
case z.ZodIssueCode.invalid_string:
|
|
25
|
+
if (issue.validation === 'email') {
|
|
26
|
+
return { message: 'Invalid email format' };
|
|
27
|
+
}
|
|
28
|
+
if (issue.validation === 'url') {
|
|
29
|
+
return { message: 'Invalid URL format' };
|
|
30
|
+
}
|
|
31
|
+
if (issue.validation === 'uuid') {
|
|
32
|
+
return { message: 'Invalid UUID format' };
|
|
33
|
+
}
|
|
34
|
+
return { message: 'Invalid string format' };
|
|
35
|
+
default:
|
|
36
|
+
return { message: ctx.defaultError };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
// Apply custom error map globally for this module
|
|
40
|
+
z.setErrorMap(securityErrorMap);
|
|
41
|
+
/**
|
|
42
|
+
* Common validation patterns as reusable regex
|
|
43
|
+
*/
|
|
44
|
+
const PATTERNS = {
|
|
45
|
+
// Safe identifier: alphanumeric with underscore/hyphen
|
|
46
|
+
SAFE_IDENTIFIER: /^[a-zA-Z][a-zA-Z0-9_-]*$/,
|
|
47
|
+
// Safe filename: alphanumeric with dot, underscore, hyphen
|
|
48
|
+
SAFE_FILENAME: /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/,
|
|
49
|
+
// Safe path segment: no traversal
|
|
50
|
+
SAFE_PATH_SEGMENT: /^[^<>:"|?*\x00-\x1f]+$/,
|
|
51
|
+
// No shell metacharacters
|
|
52
|
+
NO_SHELL_CHARS: /^[^;&|`$(){}><\n\r\0]+$/,
|
|
53
|
+
// Semantic version
|
|
54
|
+
SEMVER: /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/,
|
|
55
|
+
};
|
|
56
|
+
/**
|
|
57
|
+
* Validation limits
|
|
58
|
+
*/
|
|
59
|
+
const LIMITS = {
|
|
60
|
+
MIN_PASSWORD_LENGTH: 8,
|
|
61
|
+
MAX_PASSWORD_LENGTH: 128,
|
|
62
|
+
MAX_EMAIL_LENGTH: 254,
|
|
63
|
+
MAX_IDENTIFIER_LENGTH: 64,
|
|
64
|
+
MAX_PATH_LENGTH: 4096,
|
|
65
|
+
MAX_CONTENT_LENGTH: 1024 * 1024, // 1MB
|
|
66
|
+
MAX_ARRAY_LENGTH: 1000,
|
|
67
|
+
MAX_OBJECT_KEYS: 100,
|
|
68
|
+
};
|
|
69
|
+
// ============================================================================
|
|
70
|
+
// Base Validation Schemas
|
|
71
|
+
// ============================================================================
|
|
72
|
+
/**
|
|
73
|
+
* Safe string that cannot contain shell metacharacters
|
|
74
|
+
*/
|
|
75
|
+
export const SafeStringSchema = z.string()
|
|
76
|
+
.min(1, 'String cannot be empty')
|
|
77
|
+
.max(LIMITS.MAX_CONTENT_LENGTH, 'String too long')
|
|
78
|
+
.regex(PATTERNS.NO_SHELL_CHARS, 'String contains invalid characters');
|
|
79
|
+
/**
|
|
80
|
+
* Safe identifier for IDs, names, etc.
|
|
81
|
+
*/
|
|
82
|
+
export const IdentifierSchema = z.string()
|
|
83
|
+
.min(1, 'Identifier cannot be empty')
|
|
84
|
+
.max(LIMITS.MAX_IDENTIFIER_LENGTH, 'Identifier too long')
|
|
85
|
+
.regex(PATTERNS.SAFE_IDENTIFIER, 'Invalid identifier format');
|
|
86
|
+
/**
|
|
87
|
+
* Safe filename
|
|
88
|
+
*/
|
|
89
|
+
export const FilenameSchema = z.string()
|
|
90
|
+
.min(1, 'Filename cannot be empty')
|
|
91
|
+
.max(255, 'Filename too long')
|
|
92
|
+
.regex(PATTERNS.SAFE_FILENAME, 'Invalid filename format');
|
|
93
|
+
/**
|
|
94
|
+
* Email schema with length limit
|
|
95
|
+
*/
|
|
96
|
+
export const EmailSchema = z.string()
|
|
97
|
+
.email('Invalid email format')
|
|
98
|
+
.max(LIMITS.MAX_EMAIL_LENGTH, 'Email too long')
|
|
99
|
+
.toLowerCase();
|
|
100
|
+
/**
|
|
101
|
+
* Password schema with complexity requirements
|
|
102
|
+
*/
|
|
103
|
+
export const PasswordSchema = z.string()
|
|
104
|
+
.min(LIMITS.MIN_PASSWORD_LENGTH, `Password must be at least ${LIMITS.MIN_PASSWORD_LENGTH} characters`)
|
|
105
|
+
.max(LIMITS.MAX_PASSWORD_LENGTH, `Password must not exceed ${LIMITS.MAX_PASSWORD_LENGTH} characters`)
|
|
106
|
+
.refine((val) => /[A-Z]/.test(val), 'Password must contain uppercase letter')
|
|
107
|
+
.refine((val) => /[a-z]/.test(val), 'Password must contain lowercase letter')
|
|
108
|
+
.refine((val) => /\d/.test(val), 'Password must contain digit');
|
|
109
|
+
/**
|
|
110
|
+
* UUID schema
|
|
111
|
+
*/
|
|
112
|
+
export const UUIDSchema = z.string().uuid('Invalid UUID format');
|
|
113
|
+
/**
|
|
114
|
+
* URL schema with HTTPS enforcement
|
|
115
|
+
*/
|
|
116
|
+
export const HttpsUrlSchema = z.string()
|
|
117
|
+
.url('Invalid URL format')
|
|
118
|
+
.refine((val) => val.startsWith('https://'), 'URL must use HTTPS');
|
|
119
|
+
/**
|
|
120
|
+
* URL schema (allows HTTP for development)
|
|
121
|
+
*/
|
|
122
|
+
export const UrlSchema = z.string()
|
|
123
|
+
.url('Invalid URL format');
|
|
124
|
+
/**
|
|
125
|
+
* Semantic version schema
|
|
126
|
+
*/
|
|
127
|
+
export const SemverSchema = z.string()
|
|
128
|
+
.regex(PATTERNS.SEMVER, 'Invalid semantic version format');
|
|
129
|
+
/**
|
|
130
|
+
* Port number schema
|
|
131
|
+
*/
|
|
132
|
+
export const PortSchema = z.number()
|
|
133
|
+
.int('Port must be an integer')
|
|
134
|
+
.min(1, 'Port must be at least 1')
|
|
135
|
+
.max(65535, 'Port must be at most 65535');
|
|
136
|
+
/**
|
|
137
|
+
* IP address schema (v4)
|
|
138
|
+
*/
|
|
139
|
+
export const IPv4Schema = z.string()
|
|
140
|
+
.ip({ version: 'v4', message: 'Invalid IPv4 address' });
|
|
141
|
+
/**
|
|
142
|
+
* IP address schema (v4 or v6)
|
|
143
|
+
*/
|
|
144
|
+
export const IPSchema = z.string()
|
|
145
|
+
.ip({ message: 'Invalid IP address' });
|
|
146
|
+
// ============================================================================
|
|
147
|
+
// Authentication Schemas
|
|
148
|
+
// ============================================================================
|
|
149
|
+
/**
|
|
150
|
+
* User role schema
|
|
151
|
+
*/
|
|
152
|
+
export const UserRoleSchema = z.enum([
|
|
153
|
+
'admin',
|
|
154
|
+
'operator',
|
|
155
|
+
'developer',
|
|
156
|
+
'viewer',
|
|
157
|
+
'service',
|
|
158
|
+
]);
|
|
159
|
+
/**
|
|
160
|
+
* Permission schema
|
|
161
|
+
*/
|
|
162
|
+
export const PermissionSchema = z.enum([
|
|
163
|
+
'swarm.create',
|
|
164
|
+
'swarm.read',
|
|
165
|
+
'swarm.update',
|
|
166
|
+
'swarm.delete',
|
|
167
|
+
'swarm.scale',
|
|
168
|
+
'agent.spawn',
|
|
169
|
+
'agent.read',
|
|
170
|
+
'agent.terminate',
|
|
171
|
+
'task.create',
|
|
172
|
+
'task.read',
|
|
173
|
+
'task.cancel',
|
|
174
|
+
'metrics.read',
|
|
175
|
+
'system.admin',
|
|
176
|
+
'api.access',
|
|
177
|
+
]);
|
|
178
|
+
/**
|
|
179
|
+
* Login request schema
|
|
180
|
+
*/
|
|
181
|
+
export const LoginRequestSchema = z.object({
|
|
182
|
+
email: EmailSchema,
|
|
183
|
+
password: z.string().min(1, 'Password is required'),
|
|
184
|
+
mfaCode: z.string().length(6, 'MFA code must be 6 digits').optional(),
|
|
185
|
+
});
|
|
186
|
+
/**
|
|
187
|
+
* User creation schema
|
|
188
|
+
*/
|
|
189
|
+
export const CreateUserSchema = z.object({
|
|
190
|
+
email: EmailSchema,
|
|
191
|
+
password: PasswordSchema,
|
|
192
|
+
role: UserRoleSchema,
|
|
193
|
+
permissions: z.array(PermissionSchema).optional(),
|
|
194
|
+
isActive: z.boolean().optional().default(true),
|
|
195
|
+
});
|
|
196
|
+
/**
|
|
197
|
+
* API key creation schema
|
|
198
|
+
*/
|
|
199
|
+
export const CreateApiKeySchema = z.object({
|
|
200
|
+
name: IdentifierSchema,
|
|
201
|
+
permissions: z.array(PermissionSchema).optional(),
|
|
202
|
+
expiresAt: z.date().optional(),
|
|
203
|
+
});
|
|
204
|
+
// ============================================================================
|
|
205
|
+
// Agent & Task Schemas
|
|
206
|
+
// ============================================================================
|
|
207
|
+
/**
|
|
208
|
+
* Agent type schema
|
|
209
|
+
*/
|
|
210
|
+
export const AgentTypeSchema = z.enum([
|
|
211
|
+
'coder',
|
|
212
|
+
'reviewer',
|
|
213
|
+
'tester',
|
|
214
|
+
'planner',
|
|
215
|
+
'researcher',
|
|
216
|
+
'security-architect',
|
|
217
|
+
'security-auditor',
|
|
218
|
+
'memory-specialist',
|
|
219
|
+
'swarm-specialist',
|
|
220
|
+
'integration-architect',
|
|
221
|
+
'performance-engineer',
|
|
222
|
+
'core-architect',
|
|
223
|
+
'test-architect',
|
|
224
|
+
'queen-coordinator',
|
|
225
|
+
'project-coordinator',
|
|
226
|
+
]);
|
|
227
|
+
/**
|
|
228
|
+
* Agent spawn request schema
|
|
229
|
+
*/
|
|
230
|
+
export const SpawnAgentSchema = z.object({
|
|
231
|
+
type: AgentTypeSchema,
|
|
232
|
+
id: IdentifierSchema.optional(),
|
|
233
|
+
config: z.record(z.unknown()).optional(),
|
|
234
|
+
timeout: z.number().positive().optional(),
|
|
235
|
+
});
|
|
236
|
+
/**
|
|
237
|
+
* Task input schema
|
|
238
|
+
*/
|
|
239
|
+
export const TaskInputSchema = z.object({
|
|
240
|
+
taskId: UUIDSchema,
|
|
241
|
+
content: SafeStringSchema.max(10000, 'Task content too long'),
|
|
242
|
+
agentType: AgentTypeSchema,
|
|
243
|
+
priority: z.enum(['low', 'medium', 'high', 'critical']).optional(),
|
|
244
|
+
metadata: z.record(z.unknown()).optional(),
|
|
245
|
+
});
|
|
246
|
+
// ============================================================================
|
|
247
|
+
// Command & Path Schemas
|
|
248
|
+
// ============================================================================
|
|
249
|
+
/**
|
|
250
|
+
* Command argument schema
|
|
251
|
+
*/
|
|
252
|
+
export const CommandArgumentSchema = z.string()
|
|
253
|
+
.max(1024, 'Argument too long')
|
|
254
|
+
.refine((val) => !val.includes('\0'), 'Argument contains null byte')
|
|
255
|
+
.refine((val) => !/[;&|`$(){}><]/.test(val), 'Argument contains shell metacharacters');
|
|
256
|
+
/**
|
|
257
|
+
* Path schema
|
|
258
|
+
*/
|
|
259
|
+
export const PathSchema = z.string()
|
|
260
|
+
.max(LIMITS.MAX_PATH_LENGTH, 'Path too long')
|
|
261
|
+
.refine((val) => !val.includes('\0'), 'Path contains null byte')
|
|
262
|
+
.refine((val) => !val.includes('..'), 'Path contains traversal pattern');
|
|
263
|
+
// ============================================================================
|
|
264
|
+
// Configuration Schemas
|
|
265
|
+
// ============================================================================
|
|
266
|
+
/**
|
|
267
|
+
* Security configuration schema
|
|
268
|
+
*/
|
|
269
|
+
export const SecurityConfigSchema = z.object({
|
|
270
|
+
bcryptRounds: z.number().int().min(10).max(20).default(12),
|
|
271
|
+
jwtExpiresIn: z.string().default('24h'),
|
|
272
|
+
sessionTimeout: z.number().positive().default(3600000),
|
|
273
|
+
maxLoginAttempts: z.number().int().positive().default(5),
|
|
274
|
+
lockoutDuration: z.number().positive().default(900000),
|
|
275
|
+
requireMFA: z.boolean().default(false),
|
|
276
|
+
});
|
|
277
|
+
/**
|
|
278
|
+
* Executor configuration schema
|
|
279
|
+
*/
|
|
280
|
+
export const ExecutorConfigSchema = z.object({
|
|
281
|
+
allowedCommands: z.array(IdentifierSchema).min(1),
|
|
282
|
+
blockedPatterns: z.array(z.string()).optional(),
|
|
283
|
+
timeout: z.number().positive().default(30000),
|
|
284
|
+
maxBuffer: z.number().positive().default(10 * 1024 * 1024),
|
|
285
|
+
cwd: PathSchema.optional(),
|
|
286
|
+
allowSudo: z.boolean().default(false),
|
|
287
|
+
});
|
|
288
|
+
// ============================================================================
|
|
289
|
+
// Sanitization Functions
|
|
290
|
+
// ============================================================================
|
|
291
|
+
/**
|
|
292
|
+
* Sanitizes a string by removing dangerous characters
|
|
293
|
+
*/
|
|
294
|
+
export function sanitizeString(input) {
|
|
295
|
+
return input
|
|
296
|
+
.replace(/\0/g, '') // Remove null bytes
|
|
297
|
+
.replace(/[<>]/g, '') // Remove HTML brackets
|
|
298
|
+
.replace(/javascript:/gi, '') // Remove javascript: protocol
|
|
299
|
+
.replace(/data:/gi, '') // Remove data: protocol
|
|
300
|
+
.trim();
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Sanitizes HTML entities
|
|
304
|
+
*/
|
|
305
|
+
export function sanitizeHtml(input) {
|
|
306
|
+
return input
|
|
307
|
+
.replace(/&/g, '&')
|
|
308
|
+
.replace(/</g, '<')
|
|
309
|
+
.replace(/>/g, '>')
|
|
310
|
+
.replace(/"/g, '"')
|
|
311
|
+
.replace(/'/g, ''');
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Sanitizes a path by removing traversal patterns
|
|
315
|
+
*/
|
|
316
|
+
export function sanitizePath(input) {
|
|
317
|
+
return input
|
|
318
|
+
.replace(/\0/g, '') // Remove null bytes
|
|
319
|
+
.replace(/\.\./g, '') // Remove traversal patterns
|
|
320
|
+
.replace(/\/+/g, '/') // Normalize slashes
|
|
321
|
+
.replace(/^\//, '') // Remove leading slash
|
|
322
|
+
.trim();
|
|
323
|
+
}
|
|
324
|
+
// ============================================================================
|
|
325
|
+
// Validation Helper Class
|
|
326
|
+
// ============================================================================
|
|
327
|
+
export class InputValidator {
|
|
328
|
+
/**
|
|
329
|
+
* Validates input against a schema
|
|
330
|
+
*/
|
|
331
|
+
static validate(schema, input) {
|
|
332
|
+
return schema.parse(input);
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Safely validates input, returning result
|
|
336
|
+
*/
|
|
337
|
+
static safeParse(schema, input) {
|
|
338
|
+
return schema.safeParse(input);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Validates email
|
|
342
|
+
*/
|
|
343
|
+
static validateEmail(email) {
|
|
344
|
+
return EmailSchema.parse(email);
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Validates password
|
|
348
|
+
*/
|
|
349
|
+
static validatePassword(password) {
|
|
350
|
+
return PasswordSchema.parse(password);
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Validates identifier
|
|
354
|
+
*/
|
|
355
|
+
static validateIdentifier(id) {
|
|
356
|
+
return IdentifierSchema.parse(id);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Validates path
|
|
360
|
+
*/
|
|
361
|
+
static validatePath(path) {
|
|
362
|
+
return PathSchema.parse(path);
|
|
363
|
+
}
|
|
364
|
+
/**
|
|
365
|
+
* Validates command argument
|
|
366
|
+
*/
|
|
367
|
+
static validateCommandArg(arg) {
|
|
368
|
+
return CommandArgumentSchema.parse(arg);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Validates login request
|
|
372
|
+
*/
|
|
373
|
+
static validateLoginRequest(data) {
|
|
374
|
+
return LoginRequestSchema.parse(data);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Validates user creation request
|
|
378
|
+
*/
|
|
379
|
+
static validateCreateUser(data) {
|
|
380
|
+
return CreateUserSchema.parse(data);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Validates task input
|
|
384
|
+
*/
|
|
385
|
+
static validateTaskInput(data) {
|
|
386
|
+
return TaskInputSchema.parse(data);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// ============================================================================
|
|
390
|
+
// Export all schemas for direct use
|
|
391
|
+
// ============================================================================
|
|
392
|
+
export { z, PATTERNS, LIMITS, };
|
|
393
|
+
//# sourceMappingURL=input-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-validator.js","sourceRoot":"","sources":["../src/input-validator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,gBAAgB,GAAkB,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;IACrD,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,CAAC,CAAC,YAAY,CAAC,OAAO;YACzB,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ED;;OAEG;IACH,MAAM,CAAC,gBAAgB,CAAC,QAAgB;QACtC,OAAO,cAAc,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,EAAU;QAClC,OAAO,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,IAAY;QAC9B,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,GAAW;QACnC,OAAO,qBAAqB,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC1C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,oBAAoB,CAAC,IAAa;QACvC,OAAO,kBAAkB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,IAAa;QACrC,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,iBAAiB,CAAC,IAAa;QACpC,OAAO,eAAe,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAED,+EAA+E;AAC/E,oCAAoC;AACpC,+EAA+E;AAE/E,OAAO,EACL,CAAC,EACD,QAAQ,EACR,MAAM,GACP,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
export interface PasswordHasherConfig {
|
|
16
|
+
/**
|
|
17
|
+
* Number of bcrypt rounds (cost factor).
|
|
18
|
+
* Default: 12 (recommended minimum for production)
|
|
19
|
+
* Each increment doubles the computation time.
|
|
20
|
+
*/
|
|
21
|
+
rounds?: number;
|
|
22
|
+
/**
|
|
23
|
+
* Minimum password length.
|
|
24
|
+
* Default: 8 characters
|
|
25
|
+
*/
|
|
26
|
+
minLength?: number;
|
|
27
|
+
/**
|
|
28
|
+
* Maximum password length.
|
|
29
|
+
* Default: 128 characters (bcrypt limit is 72 bytes)
|
|
30
|
+
*/
|
|
31
|
+
maxLength?: number;
|
|
32
|
+
/**
|
|
33
|
+
* Require at least one uppercase letter.
|
|
34
|
+
* Default: true
|
|
35
|
+
*/
|
|
36
|
+
requireUppercase?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Require at least one lowercase letter.
|
|
39
|
+
* Default: true
|
|
40
|
+
*/
|
|
41
|
+
requireLowercase?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Require at least one digit.
|
|
44
|
+
* Default: true
|
|
45
|
+
*/
|
|
46
|
+
requireDigit?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Require at least one special character.
|
|
49
|
+
* Default: false
|
|
50
|
+
*/
|
|
51
|
+
requireSpecial?: boolean;
|
|
52
|
+
}
|
|
53
|
+
export interface PasswordValidationResult {
|
|
54
|
+
isValid: boolean;
|
|
55
|
+
errors: string[];
|
|
56
|
+
}
|
|
57
|
+
export declare class PasswordHashError extends Error {
|
|
58
|
+
readonly code: string;
|
|
59
|
+
constructor(message: string, code: string);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Secure password hasher using bcrypt.
|
|
63
|
+
*
|
|
64
|
+
* This class replaces the vulnerable SHA-256 + hardcoded salt implementation
|
|
65
|
+
* with industry-standard bcrypt hashing.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```typescript
|
|
69
|
+
* const hasher = new PasswordHasher({ rounds: 12 });
|
|
70
|
+
* const hash = await hasher.hash('securePassword123');
|
|
71
|
+
* const isValid = await hasher.verify('securePassword123', hash);
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare class PasswordHasher {
|
|
75
|
+
private readonly config;
|
|
76
|
+
constructor(config?: PasswordHasherConfig);
|
|
77
|
+
/**
|
|
78
|
+
* Validates password against configured requirements.
|
|
79
|
+
*
|
|
80
|
+
* @param password - The password to validate
|
|
81
|
+
* @returns Validation result with errors if any
|
|
82
|
+
*/
|
|
83
|
+
validate(password: string): PasswordValidationResult;
|
|
84
|
+
/**
|
|
85
|
+
* Hashes a password using bcrypt.
|
|
86
|
+
*
|
|
87
|
+
* @param password - The plaintext password to hash
|
|
88
|
+
* @returns The bcrypt hash
|
|
89
|
+
* @throws PasswordHashError if password is invalid
|
|
90
|
+
*/
|
|
91
|
+
hash(password: string): Promise<string>;
|
|
92
|
+
/**
|
|
93
|
+
* Verifies a password against a bcrypt hash.
|
|
94
|
+
* Uses timing-safe comparison internally.
|
|
95
|
+
*
|
|
96
|
+
* @param password - The plaintext password to verify
|
|
97
|
+
* @param hash - The bcrypt hash to compare against
|
|
98
|
+
* @returns True if password matches, false otherwise
|
|
99
|
+
*/
|
|
100
|
+
verify(password: string, hash: string): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Checks if a hash needs to be rehashed with updated parameters.
|
|
103
|
+
* Useful for upgrading hash strength over time.
|
|
104
|
+
*
|
|
105
|
+
* @param hash - The bcrypt hash to check
|
|
106
|
+
* @returns True if hash should be updated
|
|
107
|
+
*/
|
|
108
|
+
needsRehash(hash: string): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* Validates bcrypt hash format.
|
|
111
|
+
*
|
|
112
|
+
* @param hash - The hash to validate
|
|
113
|
+
* @returns True if valid bcrypt hash format
|
|
114
|
+
*/
|
|
115
|
+
private isValidBcryptHash;
|
|
116
|
+
/**
|
|
117
|
+
* Returns current configuration (without sensitive defaults).
|
|
118
|
+
*/
|
|
119
|
+
getConfig(): Readonly<Omit<Required<PasswordHasherConfig>, never>>;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Factory function to create a production-ready password hasher.
|
|
123
|
+
*
|
|
124
|
+
* @param rounds - Bcrypt rounds (default: 12)
|
|
125
|
+
* @returns Configured PasswordHasher instance
|
|
126
|
+
*/
|
|
127
|
+
export declare function createPasswordHasher(rounds?: number): PasswordHasher;
|
|
128
|
+
//# sourceMappingURL=password-hasher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password-hasher.d.ts","sourceRoot":"","sources":["../src/password-hasher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAE3B;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,qBAAa,iBAAkB,SAAQ,KAAK;aAGxB,IAAI,EAAE,MAAM;gBAD5B,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,MAAM;CAK/B;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,MAA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