ai-database 2.1.1 → 2.1.3

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 (63) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/LICENSE +21 -0
  3. package/README.md +667 -1
  4. package/dist/ai-promise-db.d.ts +3 -0
  5. package/dist/ai-promise-db.d.ts.map +1 -1
  6. package/dist/ai-promise-db.js +98 -105
  7. package/dist/ai-promise-db.js.map +1 -1
  8. package/dist/index.d.ts +3 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js +7 -1
  11. package/dist/index.js.map +1 -1
  12. package/dist/memory-provider.d.ts +1 -0
  13. package/dist/memory-provider.d.ts.map +1 -1
  14. package/dist/memory-provider.js.map +1 -1
  15. package/dist/schema/cascade.d.ts +8 -0
  16. package/dist/schema/cascade.d.ts.map +1 -1
  17. package/dist/schema/cascade.js +25 -6
  18. package/dist/schema/cascade.js.map +1 -1
  19. package/dist/schema/dependency-graph.d.ts +133 -0
  20. package/dist/schema/dependency-graph.d.ts.map +1 -0
  21. package/dist/schema/dependency-graph.js +355 -0
  22. package/dist/schema/dependency-graph.js.map +1 -0
  23. package/dist/schema/generation-context.d.ts +202 -0
  24. package/dist/schema/generation-context.d.ts.map +1 -0
  25. package/dist/schema/generation-context.js +393 -0
  26. package/dist/schema/generation-context.js.map +1 -0
  27. package/dist/schema/index.d.ts +4 -0
  28. package/dist/schema/index.d.ts.map +1 -1
  29. package/dist/schema/index.js +11 -1
  30. package/dist/schema/index.js.map +1 -1
  31. package/dist/schema/parse.d.ts.map +1 -1
  32. package/dist/schema/parse.js +9 -1
  33. package/dist/schema/parse.js.map +1 -1
  34. package/dist/schema/provider.d.ts +1 -0
  35. package/dist/schema/provider.d.ts.map +1 -1
  36. package/dist/schema/resolve.d.ts.map +1 -1
  37. package/dist/schema/resolve.js +103 -28
  38. package/dist/schema/resolve.js.map +1 -1
  39. package/dist/schema/semantic.d.ts +1 -0
  40. package/dist/schema/semantic.d.ts.map +1 -1
  41. package/dist/schema/semantic.js +144 -56
  42. package/dist/schema/semantic.js.map +1 -1
  43. package/dist/schema/union-fallback.d.ts +219 -0
  44. package/dist/schema/union-fallback.d.ts.map +1 -0
  45. package/dist/schema/union-fallback.js +325 -0
  46. package/dist/schema/union-fallback.js.map +1 -0
  47. package/dist/schema/verb-derivation.d.ts +167 -0
  48. package/dist/schema/verb-derivation.d.ts.map +1 -0
  49. package/dist/schema/verb-derivation.js +281 -0
  50. package/dist/schema/verb-derivation.js.map +1 -0
  51. package/dist/schema.d.ts +1 -0
  52. package/dist/schema.d.ts.map +1 -1
  53. package/dist/schema.js +4 -0
  54. package/dist/schema.js.map +1 -1
  55. package/dist/type-guards.d.ts +167 -0
  56. package/dist/type-guards.d.ts.map +1 -0
  57. package/dist/type-guards.js +247 -0
  58. package/dist/type-guards.js.map +1 -0
  59. package/dist/validation.d.ts +168 -0
  60. package/dist/validation.d.ts.map +1 -0
  61. package/dist/validation.js +667 -0
  62. package/dist/validation.js.map +1 -0
  63. package/package.json +13 -13
@@ -0,0 +1,667 @@
1
+ /**
2
+ * Input Validation Module
3
+ *
4
+ * Security-focused validation for all provider inputs to prevent:
5
+ * - SQL injection attacks
6
+ * - NoSQL injection attacks
7
+ * - Path traversal attacks
8
+ * - Prototype pollution
9
+ * - Resource exhaustion (excessive length/depth)
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ // =============================================================================
14
+ // Validation Constants
15
+ // =============================================================================
16
+ /** Maximum allowed length for type names */
17
+ export const MAX_TYPE_LENGTH = 256;
18
+ /** Maximum allowed length for entity IDs */
19
+ export const MAX_ID_LENGTH = 512;
20
+ /** Maximum allowed length for search queries */
21
+ export const MAX_QUERY_LENGTH = 10000;
22
+ /** Maximum allowed nesting depth for objects */
23
+ export const MAX_OBJECT_DEPTH = 100;
24
+ /** Maximum allowed length for relation names */
25
+ export const MAX_RELATION_LENGTH = 256;
26
+ /** Maximum allowed length for field names */
27
+ export const MAX_FIELD_LENGTH = 256;
28
+ // =============================================================================
29
+ // Allowlist-Based Validation (Security Hardened)
30
+ // =============================================================================
31
+ /**
32
+ * Allowed characters for identifiers using allowlist approach.
33
+ * This is more secure than regex which can have bypass vulnerabilities.
34
+ */
35
+ /** Allowed uppercase letters (A-Z) */
36
+ const ALLOWED_UPPERCASE = new Set('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
37
+ /** Allowed lowercase letters (a-z) */
38
+ const ALLOWED_LOWERCASE = new Set('abcdefghijklmnopqrstuvwxyz');
39
+ /** Allowed digits (0-9) */
40
+ const ALLOWED_DIGITS = new Set('0123456789');
41
+ /** Allowed letters (a-z, A-Z) */
42
+ const ALLOWED_LETTERS = new Set([...ALLOWED_UPPERCASE, ...ALLOWED_LOWERCASE]);
43
+ /** Allowed identifier characters (letters, digits, underscore) */
44
+ const ALLOWED_IDENTIFIER_CHARS = new Set([
45
+ ...ALLOWED_LETTERS,
46
+ ...ALLOWED_DIGITS,
47
+ '_',
48
+ ]);
49
+ /** Allowed ID characters (letters, digits, underscore, hyphen, dot, forward slash for path-like IDs) */
50
+ const ALLOWED_ID_CHARS = new Set([
51
+ ...ALLOWED_LETTERS,
52
+ ...ALLOWED_DIGITS,
53
+ '_',
54
+ '-',
55
+ '.',
56
+ '/',
57
+ ]);
58
+ /** Allowed action type characters (letters, digits, underscore, hyphen) */
59
+ const ALLOWED_ACTION_CHARS = new Set([
60
+ ...ALLOWED_LETTERS,
61
+ ...ALLOWED_DIGITS,
62
+ '_',
63
+ '-',
64
+ ]);
65
+ /**
66
+ * Check if a character is in the allowlist
67
+ * Uses code point to ensure we only accept ASCII characters
68
+ */
69
+ function isAllowedChar(char, allowedSet) {
70
+ // Must be exactly one character
71
+ if (char.length !== 1)
72
+ return false;
73
+ // Must be ASCII (code point < 128)
74
+ const codePoint = char.charCodeAt(0);
75
+ if (codePoint >= 128)
76
+ return false;
77
+ // Must be in the allowed set
78
+ return allowedSet.has(char);
79
+ }
80
+ /**
81
+ * Check if a string contains only allowed characters
82
+ * This is the core allowlist validation function
83
+ */
84
+ function containsOnlyAllowedChars(str, allowedSet) {
85
+ for (const char of str) {
86
+ if (!isAllowedChar(char, allowedSet)) {
87
+ return false;
88
+ }
89
+ }
90
+ return true;
91
+ }
92
+ /**
93
+ * Check if a character is a letter (ASCII only)
94
+ */
95
+ function isLetter(char) {
96
+ return isAllowedChar(char, ALLOWED_LETTERS);
97
+ }
98
+ /**
99
+ * Validate type name format using allowlist approach
100
+ */
101
+ function isValidTypeNameFormat(name) {
102
+ if (name.length === 0)
103
+ return false;
104
+ // First character must be a letter
105
+ if (!isLetter(name[0]))
106
+ return false;
107
+ // All characters must be in the allowed set
108
+ return containsOnlyAllowedChars(name, ALLOWED_IDENTIFIER_CHARS);
109
+ }
110
+ /**
111
+ * Validate entity ID format using allowlist approach
112
+ * IDs can contain letters, digits, underscores, and hyphens (for UUIDs and slugs)
113
+ */
114
+ function isValidEntityIdFormat(id) {
115
+ if (id.length === 0)
116
+ return false;
117
+ // All characters must be in the allowed set
118
+ return containsOnlyAllowedChars(id, ALLOWED_ID_CHARS);
119
+ }
120
+ /**
121
+ * Validate relation name format using allowlist approach
122
+ */
123
+ function isValidRelationNameFormat(name) {
124
+ if (name.length === 0)
125
+ return false;
126
+ // First character must be a letter
127
+ if (!isLetter(name[0]))
128
+ return false;
129
+ // All characters must be in the allowed set
130
+ return containsOnlyAllowedChars(name, ALLOWED_IDENTIFIER_CHARS);
131
+ }
132
+ /**
133
+ * Validate field name format using allowlist approach
134
+ * Field names can optionally start with $
135
+ */
136
+ function isValidFieldNameFormat(name) {
137
+ if (name.length === 0)
138
+ return false;
139
+ let startIndex = 0;
140
+ // Handle optional $ prefix
141
+ if (name[0] === '$') {
142
+ if (name.length === 1)
143
+ return false;
144
+ startIndex = 1;
145
+ }
146
+ // Character after $ (or first char) must be a letter
147
+ if (!isLetter(name[startIndex]))
148
+ return false;
149
+ // All remaining characters must be in the allowed set
150
+ for (let i = startIndex; i < name.length; i++) {
151
+ if (!isAllowedChar(name[i], ALLOWED_IDENTIFIER_CHARS)) {
152
+ return false;
153
+ }
154
+ }
155
+ return true;
156
+ }
157
+ /**
158
+ * Validate action type format using allowlist approach
159
+ * Action types can contain letters, digits, underscores, and hyphens
160
+ */
161
+ function isValidActionTypeFormat(name) {
162
+ if (name.length === 0)
163
+ return false;
164
+ // First character must be a letter
165
+ if (!isLetter(name[0]))
166
+ return false;
167
+ // All characters must be in the allowed set (including hyphens)
168
+ return containsOnlyAllowedChars(name, ALLOWED_ACTION_CHARS);
169
+ }
170
+ // =============================================================================
171
+ // Validation Patterns (kept for event pattern validation only)
172
+ // =============================================================================
173
+ /**
174
+ * Pattern for valid event patterns: Type.action, type:action, or wildcards
175
+ * Supports both dot notation (Post.created) and colon notation (entity:created)
176
+ * This is kept as regex because it needs to validate pattern syntax,
177
+ * but the underlying type names are validated with allowlist
178
+ */
179
+ const EVENT_PATTERN_REGEX = /^(\*|\*\.[A-Za-z_]+|[A-Za-z_]+\.\*|[A-Za-z_]+\.[A-Za-z_:]+|[A-Za-z_]+:[A-Za-z_]+)$/;
180
+ // =============================================================================
181
+ // SQL Injection Patterns
182
+ // =============================================================================
183
+ /**
184
+ * Common SQL injection patterns to detect
185
+ */
186
+ const SQL_INJECTION_PATTERNS = [
187
+ /;\s*(DROP|DELETE|UPDATE|INSERT|ALTER|CREATE|TRUNCATE)/i,
188
+ /'\s*OR\s*'?\d*'?\s*=\s*'?\d*/i,
189
+ /"\s*OR\s*"?\d*"?\s*=\s*"?\d*/i,
190
+ /UNION\s+(ALL\s+)?SELECT/i,
191
+ /\/\*.*\*\//,
192
+ /--/,
193
+ /EXEC\s+/i,
194
+ /EXECUTE\s+/i,
195
+ /xp_cmdshell/i,
196
+ /WAITFOR\s+DELAY/i,
197
+ /SLEEP\s*\(/i,
198
+ /%27/i, // URL-encoded single quote
199
+ /%22/i, // URL-encoded double quote
200
+ ];
201
+ /**
202
+ * Path traversal patterns to detect
203
+ */
204
+ const PATH_TRAVERSAL_PATTERNS = [
205
+ /\.\.\//,
206
+ /\.\.\\/,
207
+ /%2e%2e%2f/i,
208
+ /%2e%2e\//i,
209
+ /\.\.%2f/i,
210
+ /%2e%2e%5c/i,
211
+ ];
212
+ /**
213
+ * Protocol injection patterns to detect in URLs
214
+ */
215
+ const PROTOCOL_INJECTION_PATTERNS = [
216
+ /^file:/i,
217
+ /^javascript:/i,
218
+ /^data:/i,
219
+ /^ftp:/i,
220
+ /^gopher:/i,
221
+ /^ldap:/i,
222
+ ];
223
+ /**
224
+ * Dangerous control characters that should be rejected
225
+ */
226
+ const CONTROL_CHARACTERS = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/;
227
+ /**
228
+ * Prototype pollution property names to reject
229
+ */
230
+ const DANGEROUS_PROPERTIES = new Set([
231
+ '__proto__',
232
+ 'constructor',
233
+ 'prototype',
234
+ ]);
235
+ // =============================================================================
236
+ // Validation Errors
237
+ // =============================================================================
238
+ export class ValidationError extends Error {
239
+ field;
240
+ value;
241
+ constructor(message, field, value) {
242
+ super(message);
243
+ this.field = field;
244
+ this.value = value;
245
+ this.name = 'ValidationError';
246
+ }
247
+ }
248
+ // =============================================================================
249
+ // Validation Functions
250
+ // =============================================================================
251
+ /**
252
+ * Check if a string contains SQL injection patterns
253
+ */
254
+ function containsSqlInjection(value) {
255
+ return SQL_INJECTION_PATTERNS.some((pattern) => pattern.test(value));
256
+ }
257
+ /**
258
+ * Check if a string contains path traversal patterns
259
+ */
260
+ function containsPathTraversal(value) {
261
+ return PATH_TRAVERSAL_PATTERNS.some((pattern) => pattern.test(value));
262
+ }
263
+ /**
264
+ * Check if a string contains protocol injection patterns
265
+ */
266
+ function containsProtocolInjection(value) {
267
+ return PROTOCOL_INJECTION_PATTERNS.some((pattern) => pattern.test(value));
268
+ }
269
+ /**
270
+ * Check if a string contains dangerous control characters
271
+ */
272
+ function containsControlCharacters(value) {
273
+ return CONTROL_CHARACTERS.test(value);
274
+ }
275
+ /**
276
+ * Validate a type name
277
+ *
278
+ * Requirements:
279
+ * - Must be a string
280
+ * - Must not be empty
281
+ * - Must match alphanumeric pattern (with underscores)
282
+ * - Must not exceed max length
283
+ * - Must not contain SQL injection patterns
284
+ * - Must not contain control characters
285
+ *
286
+ * @throws ValidationError if validation fails
287
+ */
288
+ export function validateTypeName(type) {
289
+ // Check string type
290
+ if (typeof type !== 'string') {
291
+ throw new ValidationError(`Invalid type: must be a string, got ${type === null ? 'null' : typeof type}`, 'type', type);
292
+ }
293
+ // Check empty
294
+ if (type.length === 0) {
295
+ throw new ValidationError('Invalid type: must not be empty', 'type', type);
296
+ }
297
+ // Check length
298
+ if (type.length > MAX_TYPE_LENGTH) {
299
+ throw new ValidationError(`Invalid type: exceeds maximum length of ${MAX_TYPE_LENGTH}`, 'type', type);
300
+ }
301
+ // Check control characters
302
+ if (containsControlCharacters(type)) {
303
+ throw new ValidationError('Invalid type: contains special characters that are not allowed', 'type', type);
304
+ }
305
+ // Check SQL injection
306
+ if (containsSqlInjection(type)) {
307
+ throw new ValidationError('Invalid type: contains injection patterns that are not allowed', 'type', type);
308
+ }
309
+ // Check pattern (alphanumeric + underscore) using allowlist
310
+ if (!isValidTypeNameFormat(type)) {
311
+ throw new ValidationError('Invalid type: must be alphanumeric with underscores, starting with a letter', 'type', type);
312
+ }
313
+ }
314
+ /**
315
+ * Validate an entity ID
316
+ *
317
+ * Requirements:
318
+ * - Must be a string
319
+ * - Must not be empty
320
+ * - Must match safe ID pattern
321
+ * - Must not exceed max length
322
+ * - Must not contain SQL injection patterns
323
+ * - Must not contain path traversal patterns
324
+ * - Must not contain control characters
325
+ *
326
+ * @throws ValidationError if validation fails
327
+ */
328
+ export function validateEntityId(id) {
329
+ // Check string type
330
+ if (typeof id !== 'string') {
331
+ throw new ValidationError(`Invalid id: must be a string, got ${id === null ? 'null' : typeof id}`, 'id', id);
332
+ }
333
+ // Check empty
334
+ if (id.length === 0) {
335
+ throw new ValidationError('Invalid id: must not be empty', 'id', id);
336
+ }
337
+ // Check length
338
+ if (id.length > MAX_ID_LENGTH) {
339
+ throw new ValidationError(`Invalid id: exceeds maximum length of ${MAX_ID_LENGTH}`, 'id', id);
340
+ }
341
+ // Check control characters
342
+ if (containsControlCharacters(id)) {
343
+ throw new ValidationError('Invalid id: contains special characters that are not allowed', 'id', id);
344
+ }
345
+ // Check SQL injection
346
+ if (containsSqlInjection(id)) {
347
+ throw new ValidationError('Invalid id: contains injection patterns that are not allowed', 'id', id);
348
+ }
349
+ // Check path traversal
350
+ if (containsPathTraversal(id)) {
351
+ throw new ValidationError('Invalid id: contains path traversal patterns that are not allowed', 'id', id);
352
+ }
353
+ // Check pattern (alphanumeric + underscore + hyphen) using allowlist
354
+ if (!isValidEntityIdFormat(id)) {
355
+ throw new ValidationError('Invalid id: must contain only alphanumeric characters, underscores, and hyphens', 'id', id);
356
+ }
357
+ }
358
+ /**
359
+ * Validate a search query
360
+ *
361
+ * Requirements:
362
+ * - Must be a string
363
+ * - Must not exceed max length
364
+ *
365
+ * Note: Search queries are more permissive since they're typically used
366
+ * for full-text search and the provider should handle them safely.
367
+ *
368
+ * @throws ValidationError if validation fails
369
+ */
370
+ export function validateSearchQuery(query) {
371
+ if (typeof query !== 'string') {
372
+ throw new ValidationError(`Invalid query: must be a string, got ${query === null ? 'null' : typeof query}`, 'query', query);
373
+ }
374
+ if (query.length > MAX_QUERY_LENGTH) {
375
+ throw new ValidationError(`Invalid query: exceeds maximum length of ${MAX_QUERY_LENGTH}`, 'query', query);
376
+ }
377
+ }
378
+ /**
379
+ * Calculate the depth of a nested object
380
+ */
381
+ function calculateObjectDepth(obj, currentDepth = 0) {
382
+ if (currentDepth > MAX_OBJECT_DEPTH) {
383
+ return currentDepth; // Stop early if we've exceeded max
384
+ }
385
+ if (obj === null || typeof obj !== 'object') {
386
+ return currentDepth;
387
+ }
388
+ if (Array.isArray(obj)) {
389
+ let maxDepth = currentDepth;
390
+ for (const item of obj) {
391
+ const depth = calculateObjectDepth(item, currentDepth + 1);
392
+ if (depth > maxDepth)
393
+ maxDepth = depth;
394
+ }
395
+ return maxDepth;
396
+ }
397
+ let maxDepth = currentDepth;
398
+ for (const value of Object.values(obj)) {
399
+ const depth = calculateObjectDepth(value, currentDepth + 1);
400
+ if (depth > maxDepth)
401
+ maxDepth = depth;
402
+ }
403
+ return maxDepth;
404
+ }
405
+ /**
406
+ * Check for prototype pollution in object data
407
+ */
408
+ function containsPrototypePollution(obj) {
409
+ if (obj === null || typeof obj !== 'object') {
410
+ return false;
411
+ }
412
+ if (Array.isArray(obj)) {
413
+ return obj.some(containsPrototypePollution);
414
+ }
415
+ for (const key of Object.keys(obj)) {
416
+ if (DANGEROUS_PROPERTIES.has(key)) {
417
+ return true;
418
+ }
419
+ if (containsPrototypePollution(obj[key])) {
420
+ return true;
421
+ }
422
+ }
423
+ return false;
424
+ }
425
+ /**
426
+ * Validate entity data
427
+ *
428
+ * Requirements:
429
+ * - Must be an object
430
+ * - Must not exceed max nesting depth
431
+ * - Must not contain prototype pollution attempts
432
+ *
433
+ * @throws ValidationError if validation fails
434
+ */
435
+ export function validateEntityData(data) {
436
+ if (data === null || typeof data !== 'object' || Array.isArray(data)) {
437
+ throw new ValidationError('Invalid data: must be an object', 'data', data);
438
+ }
439
+ // Check depth
440
+ const depth = calculateObjectDepth(data);
441
+ if (depth > MAX_OBJECT_DEPTH) {
442
+ throw new ValidationError(`Invalid data: nested too deep, maximum depth is ${MAX_OBJECT_DEPTH}`, 'data');
443
+ }
444
+ // Check for prototype pollution - but only reject 'constructor' at top level
445
+ // __proto__ is harmless in JSON.parse'd objects
446
+ const record = data;
447
+ if ('constructor' in record && typeof record['constructor'] === 'object') {
448
+ throw new ValidationError('Invalid data: constructor property not allowed', 'data');
449
+ }
450
+ }
451
+ /**
452
+ * Validate a relation name
453
+ *
454
+ * Requirements:
455
+ * - Must be a string
456
+ * - Must not be empty
457
+ * - Must match alphanumeric pattern
458
+ * - Must not exceed max length
459
+ * - Must not contain SQL injection patterns
460
+ *
461
+ * @throws ValidationError if validation fails
462
+ */
463
+ export function validateRelationName(relation) {
464
+ if (typeof relation !== 'string') {
465
+ throw new ValidationError(`Invalid relation: must be a string, got ${relation === null ? 'null' : typeof relation}`, 'relation', relation);
466
+ }
467
+ if (relation.length === 0) {
468
+ throw new ValidationError('Invalid relation: must not be empty', 'relation', relation);
469
+ }
470
+ if (relation.length > MAX_RELATION_LENGTH) {
471
+ throw new ValidationError(`Invalid relation: exceeds maximum length of ${MAX_RELATION_LENGTH}`, 'relation', relation);
472
+ }
473
+ if (containsSqlInjection(relation)) {
474
+ throw new ValidationError('Invalid relation: contains injection patterns that are not allowed', 'relation', relation);
475
+ }
476
+ // Check pattern using allowlist
477
+ if (!isValidRelationNameFormat(relation)) {
478
+ throw new ValidationError('Invalid relation: must be alphanumeric with underscores, starting with a letter', 'relation', relation);
479
+ }
480
+ }
481
+ /**
482
+ * Validate an event pattern
483
+ *
484
+ * Requirements:
485
+ * - Must be a string
486
+ * - Must match valid event pattern format
487
+ * - Must not contain SQL injection patterns
488
+ *
489
+ * @throws ValidationError if validation fails
490
+ */
491
+ export function validateEventPattern(pattern) {
492
+ if (typeof pattern !== 'string') {
493
+ throw new ValidationError(`Invalid pattern: must be a string, got ${pattern === null ? 'null' : typeof pattern}`, 'pattern', pattern);
494
+ }
495
+ if (containsSqlInjection(pattern)) {
496
+ throw new ValidationError('Invalid pattern: contains injection patterns that are not allowed', 'pattern', pattern);
497
+ }
498
+ if (!EVENT_PATTERN_REGEX.test(pattern)) {
499
+ throw new ValidationError('Invalid pattern: must be a valid event pattern (Type.action, *.action, Type.*, or *)', 'pattern', pattern);
500
+ }
501
+ }
502
+ /**
503
+ * Validate an action type
504
+ *
505
+ * Requirements:
506
+ * - Must be a string
507
+ * - Must match alphanumeric pattern
508
+ * - Must not contain SQL injection patterns
509
+ *
510
+ * @throws ValidationError if validation fails
511
+ */
512
+ export function validateActionType(actionType) {
513
+ if (typeof actionType !== 'string') {
514
+ throw new ValidationError(`Invalid type: must be a string, got ${actionType === null ? 'null' : typeof actionType}`, 'type', actionType);
515
+ }
516
+ if (containsSqlInjection(actionType)) {
517
+ throw new ValidationError('Invalid type: contains injection patterns that are not allowed', 'type', actionType);
518
+ }
519
+ // Check pattern using allowlist
520
+ if (!isValidActionTypeFormat(actionType)) {
521
+ throw new ValidationError('Invalid type: must be alphanumeric with underscores, starting with a letter', 'type', actionType);
522
+ }
523
+ }
524
+ /**
525
+ * Validate an artifact URL
526
+ *
527
+ * Requirements:
528
+ * - Must be a string
529
+ * - Must not contain path traversal patterns
530
+ * - Must not contain protocol injection
531
+ *
532
+ * @throws ValidationError if validation fails
533
+ */
534
+ export function validateArtifactUrl(url) {
535
+ if (typeof url !== 'string') {
536
+ throw new ValidationError(`Invalid url: must be a string, got ${url === null ? 'null' : typeof url}`, 'url', url);
537
+ }
538
+ if (containsPathTraversal(url)) {
539
+ throw new ValidationError('Invalid url: path traversal not allowed', 'url', url);
540
+ }
541
+ if (containsProtocolInjection(url)) {
542
+ throw new ValidationError('Invalid url: protocol not allowed', 'url', url);
543
+ }
544
+ }
545
+ /**
546
+ * Validate a field name for search
547
+ *
548
+ * Requirements:
549
+ * - Must be a string
550
+ * - Must match valid field pattern or be $all
551
+ * - Must not contain SQL injection patterns
552
+ * - Must not be a dangerous property name
553
+ *
554
+ * @throws ValidationError if validation fails
555
+ */
556
+ export function validateFieldName(field) {
557
+ if (typeof field !== 'string') {
558
+ throw new ValidationError(`Invalid field: must be a string, got ${field === null ? 'null' : typeof field}`, 'field', field);
559
+ }
560
+ // $all is a special valid field name
561
+ if (field === '$all') {
562
+ return;
563
+ }
564
+ if (containsSqlInjection(field)) {
565
+ throw new ValidationError('Invalid field: contains injection patterns that are not allowed', 'field', field);
566
+ }
567
+ if (field.length > MAX_FIELD_LENGTH) {
568
+ throw new ValidationError(`Invalid field: exceeds maximum length of ${MAX_FIELD_LENGTH}`, 'field', field);
569
+ }
570
+ // Check pattern using allowlist
571
+ if (!isValidFieldNameFormat(field)) {
572
+ throw new ValidationError('Invalid field: must be alphanumeric with underscores', 'field', field);
573
+ }
574
+ }
575
+ /**
576
+ * Check if a field name is a dangerous property
577
+ */
578
+ export function isDangerousField(field) {
579
+ return DANGEROUS_PROPERTIES.has(field);
580
+ }
581
+ /**
582
+ * Validate list options
583
+ *
584
+ * Requirements:
585
+ * - limit must be a non-negative number if provided
586
+ * - offset must be a non-negative number if provided
587
+ * - orderBy must be a valid field name if provided
588
+ *
589
+ * @throws ValidationError if validation fails
590
+ */
591
+ export function validateListOptions(options) {
592
+ if (options === null || options === undefined) {
593
+ return;
594
+ }
595
+ if (typeof options !== 'object') {
596
+ throw new ValidationError('Invalid options: must be an object', 'options', options);
597
+ }
598
+ const opts = options;
599
+ // Validate limit
600
+ if (opts.limit !== undefined) {
601
+ if (typeof opts.limit !== 'number') {
602
+ throw new ValidationError(`Invalid limit: must be a number, got ${typeof opts.limit}`, 'limit', opts.limit);
603
+ }
604
+ if (opts.limit < 0) {
605
+ throw new ValidationError('Invalid limit: must be positive or zero', 'limit', opts.limit);
606
+ }
607
+ }
608
+ // Validate offset
609
+ if (opts.offset !== undefined) {
610
+ if (typeof opts.offset !== 'number') {
611
+ throw new ValidationError(`Invalid offset: must be a number, got ${typeof opts.offset}`, 'offset', opts.offset);
612
+ }
613
+ if (opts.offset < 0) {
614
+ throw new ValidationError('Invalid offset: must be positive or zero', 'offset', opts.offset);
615
+ }
616
+ }
617
+ // Validate orderBy
618
+ if (opts.orderBy !== undefined) {
619
+ if (typeof opts.orderBy !== 'string') {
620
+ throw new ValidationError(`Invalid orderBy: must be a string, got ${typeof opts.orderBy}`, 'orderBy', opts.orderBy);
621
+ }
622
+ if (containsSqlInjection(opts.orderBy)) {
623
+ throw new ValidationError('Invalid orderBy: contains injection patterns that are not allowed', 'orderBy', opts.orderBy);
624
+ }
625
+ // Check pattern using allowlist
626
+ if (!isValidFieldNameFormat(opts.orderBy)) {
627
+ throw new ValidationError('Invalid orderBy field: must be alphanumeric with underscores', 'orderBy', opts.orderBy);
628
+ }
629
+ }
630
+ }
631
+ /**
632
+ * Validate search options including fields array
633
+ *
634
+ * @throws ValidationError if validation fails
635
+ */
636
+ export function validateSearchOptions(options) {
637
+ if (options === null || options === undefined) {
638
+ return;
639
+ }
640
+ // First validate the base list options
641
+ validateListOptions(options);
642
+ const opts = options;
643
+ // Validate fields array
644
+ if (opts.fields !== undefined) {
645
+ if (!Array.isArray(opts.fields)) {
646
+ throw new ValidationError('Invalid fields: must be an array', 'fields', opts.fields);
647
+ }
648
+ for (const field of opts.fields) {
649
+ // Skip dangerous field names silently - they will be filtered out by the search method
650
+ // This allows the search to return empty results rather than throwing
651
+ if (typeof field === 'string' && DANGEROUS_PROPERTIES.has(field)) {
652
+ continue;
653
+ }
654
+ validateFieldName(field);
655
+ }
656
+ }
657
+ }
658
+ /**
659
+ * Sanitize a search query by escaping special regex characters
660
+ *
661
+ * This prevents regex injection in search operations.
662
+ */
663
+ export function sanitizeSearchQuery(query) {
664
+ // Escape regex special characters for safe string matching
665
+ return query.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
666
+ }
667
+ //# sourceMappingURL=validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF,4CAA4C;AAC5C,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,CAAA;AAElC,4CAA4C;AAC5C,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,CAAA;AAEhC,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAErC,gDAAgD;AAChD,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,CAAA;AAEnC,gDAAgD;AAChD,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAG,CAAA;AAEtC,6CAA6C;AAC7C,MAAM,CAAC,MAA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