@arcis/node 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/core/{index.d.mts → constants.d.ts} +21 -70
  2. package/dist/core/constants.d.ts.map +1 -0
  3. package/dist/core/errors.d.ts +53 -0
  4. package/dist/core/errors.d.ts.map +1 -0
  5. package/dist/core/index.d.ts +6 -168
  6. package/dist/core/index.d.ts.map +1 -0
  7. package/dist/{types-BOkx5YJc.d.mts → core/types.d.ts} +27 -30
  8. package/dist/core/types.d.ts.map +1 -0
  9. package/dist/index.d.ts +71 -166
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +57 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/index.mjs +56 -3
  14. package/dist/index.mjs.map +1 -1
  15. package/dist/logging/index.d.ts +4 -36
  16. package/dist/logging/index.d.ts.map +1 -0
  17. package/dist/logging/{index.d.mts → redactor.d.ts} +5 -9
  18. package/dist/logging/redactor.d.ts.map +1 -0
  19. package/dist/middleware/bot-detection.d.ts +86 -0
  20. package/dist/middleware/bot-detection.d.ts.map +1 -0
  21. package/dist/middleware/cookies.d.ts +48 -0
  22. package/dist/middleware/cookies.d.ts.map +1 -0
  23. package/dist/middleware/cors.d.ts +65 -0
  24. package/dist/middleware/cors.d.ts.map +1 -0
  25. package/dist/middleware/csrf.d.ts +109 -0
  26. package/dist/middleware/csrf.d.ts.map +1 -0
  27. package/dist/middleware/error-handler.d.ts +43 -0
  28. package/dist/middleware/error-handler.d.ts.map +1 -0
  29. package/dist/middleware/headers.d.ts +29 -0
  30. package/dist/middleware/headers.d.ts.map +1 -0
  31. package/dist/middleware/hpp.d.ts +56 -0
  32. package/dist/middleware/hpp.d.ts.map +1 -0
  33. package/dist/middleware/index.d.ts +16 -3
  34. package/dist/middleware/index.d.ts.map +1 -0
  35. package/dist/middleware/index.js +6 -1
  36. package/dist/middleware/index.js.map +1 -1
  37. package/dist/middleware/index.mjs +6 -1
  38. package/dist/middleware/index.mjs.map +1 -1
  39. package/dist/middleware/main.d.ts +40 -0
  40. package/dist/middleware/main.d.ts.map +1 -0
  41. package/dist/middleware/rate-limit-sliding.d.ts +46 -0
  42. package/dist/middleware/rate-limit-sliding.d.ts.map +1 -0
  43. package/dist/middleware/rate-limit-token.d.ts +51 -0
  44. package/dist/middleware/rate-limit-token.d.ts.map +1 -0
  45. package/dist/middleware/rate-limit.d.ts +34 -0
  46. package/dist/middleware/rate-limit.d.ts.map +1 -0
  47. package/dist/sanitizers/command.d.ts +28 -0
  48. package/dist/sanitizers/command.d.ts.map +1 -0
  49. package/dist/sanitizers/encode.d.ts +46 -0
  50. package/dist/sanitizers/encode.d.ts.map +1 -0
  51. package/dist/sanitizers/headers.d.ts +46 -0
  52. package/dist/sanitizers/headers.d.ts.map +1 -0
  53. package/dist/sanitizers/index.d.ts +17 -22
  54. package/dist/sanitizers/index.d.ts.map +1 -0
  55. package/dist/sanitizers/jsonp.d.ts +34 -0
  56. package/dist/sanitizers/jsonp.d.ts.map +1 -0
  57. package/dist/sanitizers/nosql.d.ts +31 -0
  58. package/dist/sanitizers/nosql.d.ts.map +1 -0
  59. package/dist/sanitizers/path.d.ts +28 -0
  60. package/dist/sanitizers/path.d.ts.map +1 -0
  61. package/dist/sanitizers/pii.d.ts +80 -0
  62. package/dist/sanitizers/pii.d.ts.map +1 -0
  63. package/dist/sanitizers/prototype.d.ts +34 -0
  64. package/dist/sanitizers/prototype.d.ts.map +1 -0
  65. package/dist/sanitizers/sanitize.d.ts +51 -0
  66. package/dist/sanitizers/sanitize.d.ts.map +1 -0
  67. package/dist/sanitizers/sql.d.ts +28 -0
  68. package/dist/sanitizers/sql.d.ts.map +1 -0
  69. package/dist/sanitizers/ssti.d.ts +20 -0
  70. package/dist/sanitizers/ssti.d.ts.map +1 -0
  71. package/dist/sanitizers/utils.d.ts +19 -0
  72. package/dist/sanitizers/utils.d.ts.map +1 -0
  73. package/dist/sanitizers/xss.d.ts +35 -0
  74. package/dist/sanitizers/xss.d.ts.map +1 -0
  75. package/dist/sanitizers/xxe.d.ts +20 -0
  76. package/dist/sanitizers/xxe.d.ts.map +1 -0
  77. package/dist/stores/index.d.ts +6 -104
  78. package/dist/stores/index.d.ts.map +1 -0
  79. package/dist/stores/memory.d.ts +35 -0
  80. package/dist/stores/memory.d.ts.map +1 -0
  81. package/dist/stores/{index.d.mts → redis.d.ts} +6 -45
  82. package/dist/stores/redis.d.ts.map +1 -0
  83. package/dist/utils/duration.d.ts +34 -0
  84. package/dist/utils/duration.d.ts.map +1 -0
  85. package/dist/utils/fingerprint.d.ts +64 -0
  86. package/dist/utils/fingerprint.d.ts.map +1 -0
  87. package/dist/utils/index.d.ts +10 -0
  88. package/dist/utils/index.d.ts.map +1 -0
  89. package/dist/utils/index.js +188 -0
  90. package/dist/utils/index.js.map +1 -0
  91. package/dist/utils/index.mjs +182 -0
  92. package/dist/utils/index.mjs.map +1 -0
  93. package/dist/utils/ip.d.ts +70 -0
  94. package/dist/utils/ip.d.ts.map +1 -0
  95. package/dist/validation/email.d.ts +82 -0
  96. package/dist/validation/email.d.ts.map +1 -0
  97. package/dist/validation/file.d.ts +90 -0
  98. package/dist/validation/file.d.ts.map +1 -0
  99. package/dist/validation/index.d.ts +10 -3
  100. package/dist/validation/index.d.ts.map +1 -0
  101. package/dist/validation/redirect.d.ts +64 -0
  102. package/dist/validation/redirect.d.ts.map +1 -0
  103. package/dist/validation/schema.d.ts +36 -0
  104. package/dist/validation/schema.d.ts.map +1 -0
  105. package/dist/validation/url.d.ts +65 -0
  106. package/dist/validation/url.d.ts.map +1 -0
  107. package/package.json +8 -6
  108. package/dist/encode-CrQCGlBq.d.mts +0 -484
  109. package/dist/encode-jl9sOwmA.d.ts +0 -484
  110. package/dist/index-BAhgn9V2.d.ts +0 -532
  111. package/dist/index-BGNKspqH.d.ts +0 -340
  112. package/dist/index-Cd02z-0j.d.mts +0 -340
  113. package/dist/index-DgJtWMSj.d.mts +0 -532
  114. package/dist/index.d.mts +0 -175
  115. package/dist/middleware/index.d.mts +0 -3
  116. package/dist/sanitizers/index.d.mts +0 -24
  117. package/dist/types-BOkx5YJc.d.ts +0 -279
  118. package/dist/validation/index.d.mts +0 -3
@@ -1,484 +0,0 @@
1
- import { RequestHandler } from 'express';
2
- import { i as SanitizeOptions, j as SanitizeResult } from './types-BOkx5YJc.mjs';
3
-
4
- /**
5
- * @module @arcis/node/sanitizers/sanitize
6
- * Main sanitization functions that combine all sanitizers
7
- */
8
-
9
- /**
10
- * Sanitize a string value against multiple attack vectors.
11
- *
12
- * Order matters: We do XSS encoding LAST because:
13
- * 1. Other sanitizers need to see the original patterns (e.g., SQL keywords)
14
- * 2. HTML encoding is the final safe output transformation
15
- * 3. Encoded entities like < shouldn't be treated as SQL/command threats
16
- *
17
- * @param value - The string to sanitize
18
- * @param options - Sanitization options
19
- * @returns The sanitized string
20
- *
21
- * @example
22
- * sanitizeString("<script>alert('xss')</script>")
23
- * // Returns: "&lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;"
24
- *
25
- * @example
26
- * sanitizeString("../../etc/passwd")
27
- * // Returns: "etc/passwd"
28
- */
29
- declare function sanitizeString(value: string, options?: SanitizeOptions): string;
30
- /**
31
- * Sanitize an object recursively, including nested objects and arrays.
32
- * Also removes prototype pollution and NoSQL injection keys.
33
- *
34
- * @param obj - The object to sanitize
35
- * @param options - Sanitization options
36
- * @returns The sanitized object
37
- */
38
- declare function sanitizeObject(obj: unknown, options?: SanitizeOptions): unknown;
39
- /**
40
- * Create Express middleware for request sanitization.
41
- * Sanitizes req.body, req.query, and req.params.
42
- *
43
- * @param options - Sanitization options
44
- * @returns Express middleware
45
- *
46
- * @example
47
- * app.use(createSanitizer());
48
- *
49
- * @example
50
- * app.use(createSanitizer({ xss: true, sql: true, nosql: true }));
51
- */
52
- declare function createSanitizer(options?: SanitizeOptions): RequestHandler;
53
-
54
- /**
55
- * @module @arcis/node/sanitizers/xss
56
- * XSS (Cross-Site Scripting) prevention
57
- */
58
-
59
- /**
60
- * Sanitizes a string to prevent XSS attacks.
61
- *
62
- * Strategy:
63
- * 1. Remove dangerous patterns (script tags, event handlers, etc.)
64
- * 2. HTML-encode the remaining content
65
- *
66
- * @param input - The string to sanitize
67
- * @param collectThreats - Whether to collect threat information (default: false for performance)
68
- * @returns Sanitized string or SanitizeResult if collectThreats is true
69
- *
70
- * @example
71
- * sanitizeXss("<script>alert('xss')</script>")
72
- * // Returns: "&lt;script&gt;alert(&#x27;xss&#x27;)&lt;/script&gt;"
73
- *
74
- * @example
75
- * sanitizeXss("<img onerror='alert(1)'>")
76
- * // Returns: "&lt;img&gt;" (event handler removed)
77
- */
78
- declare function sanitizeXss(input: string, collectThreats?: false, htmlEncode?: boolean): string;
79
- declare function sanitizeXss(input: string, collectThreats: true, htmlEncode?: boolean): SanitizeResult;
80
- /**
81
- * Checks if a string contains potential XSS patterns.
82
- * Does not sanitize — use sanitizeXss() for that.
83
- *
84
- * @param input - The string to check
85
- * @returns True if XSS patterns detected
86
- */
87
- declare function detectXss(input: string): boolean;
88
-
89
- /**
90
- * @module @arcis/node/sanitizers/sql
91
- * SQL injection prevention
92
- */
93
-
94
- /**
95
- * Sanitizes a string to prevent SQL injection attacks.
96
- * Replaces dangerous SQL patterns with [BLOCKED].
97
- *
98
- * @param input - The string to sanitize
99
- * @param collectThreats - Whether to collect threat information (default: false for performance)
100
- * @returns Sanitized string or SanitizeResult if collectThreats is true
101
- *
102
- * @example
103
- * sanitizeSql("'; DROP TABLE users; --")
104
- * // Returns: "'; TABLE users "
105
- */
106
- declare function sanitizeSql(input: string, collectThreats?: false): string;
107
- declare function sanitizeSql(input: string, collectThreats: true): SanitizeResult;
108
- /**
109
- * Checks if a string contains potential SQL injection patterns.
110
- * Does not sanitize — use sanitizeSql() for that.
111
- *
112
- * @param input - The string to check
113
- * @returns True if SQL injection patterns detected
114
- */
115
- declare function detectSql(input: string): boolean;
116
-
117
- /**
118
- * @module @arcis/node/sanitizers/path
119
- * Path traversal prevention
120
- */
121
-
122
- /**
123
- * Sanitizes a string to prevent path traversal attacks.
124
- * Removes ../ and ..\ patterns (including URL-encoded variants).
125
- *
126
- * @param input - The string to sanitize
127
- * @param collectThreats - Whether to collect threat information (default: false for performance)
128
- * @returns Sanitized string or SanitizeResult if collectThreats is true
129
- *
130
- * @example
131
- * sanitizePath("../../etc/passwd")
132
- * // Returns: "etc/passwd"
133
- */
134
- declare function sanitizePath(input: string, collectThreats?: false): string;
135
- declare function sanitizePath(input: string, collectThreats: true): SanitizeResult;
136
- /**
137
- * Checks if a string contains path traversal patterns.
138
- * Does not sanitize — use sanitizePath() for that.
139
- *
140
- * @param input - The string to check
141
- * @returns True if path traversal patterns detected
142
- */
143
- declare function detectPathTraversal(input: string): boolean;
144
-
145
- /**
146
- * @module @arcis/node/sanitizers/command
147
- * Command injection prevention
148
- */
149
-
150
- /**
151
- * Sanitizes a string to prevent command injection attacks.
152
- * Replaces shell metacharacters and dangerous commands with [BLOCKED].
153
- *
154
- * @param input - The string to sanitize
155
- * @param collectThreats - Whether to collect threat information (default: false for performance)
156
- * @returns Sanitized string or SanitizeResult if collectThreats is true
157
- *
158
- * @example
159
- * sanitizeCommand("file.txt; rm -rf /")
160
- * // Returns: "file.txt rm -rf /"
161
- */
162
- declare function sanitizeCommand(input: string, collectThreats?: false): string;
163
- declare function sanitizeCommand(input: string, collectThreats: true): SanitizeResult;
164
- /**
165
- * Checks if a string contains command injection patterns.
166
- * Does not sanitize — use sanitizeCommand() for that.
167
- *
168
- * @param input - The string to check
169
- * @returns True if command injection patterns detected
170
- */
171
- declare function detectCommandInjection(input: string): boolean;
172
-
173
- /**
174
- * @module @arcis/node/sanitizers/ssti
175
- * Server-Side Template Injection (SSTI) prevention
176
- */
177
-
178
- /**
179
- * Sanitizes a string to prevent SSTI attacks.
180
- * Removes template expression syntax.
181
- */
182
- declare function sanitizeSsti(input: string, collectThreats?: false): string;
183
- declare function sanitizeSsti(input: string, collectThreats: true): SanitizeResult;
184
- /**
185
- * Checks if a string contains SSTI patterns.
186
- * Does not sanitize — use sanitizeSsti() for that.
187
- *
188
- * @param input - The string to check
189
- * @returns True if SSTI patterns detected
190
- */
191
- declare function detectSsti(input: string): boolean;
192
-
193
- /**
194
- * @module @arcis/node/sanitizers/xxe
195
- * XML External Entity (XXE) injection prevention
196
- */
197
-
198
- /**
199
- * Sanitizes a string to prevent XXE attacks.
200
- * Removes DOCTYPE, ENTITY, and CDATA constructs.
201
- */
202
- declare function sanitizeXxe(input: string, collectThreats?: false): string;
203
- declare function sanitizeXxe(input: string, collectThreats: true): SanitizeResult;
204
- /**
205
- * Checks if a string contains XXE patterns.
206
- * Does not sanitize — use sanitizeXxe() for that.
207
- *
208
- * @param input - The string to check
209
- * @returns True if XXE patterns detected
210
- */
211
- declare function detectXxe(input: string): boolean;
212
-
213
- /**
214
- * @module @arcis/node/sanitizers/jsonp
215
- * JSONP callback sanitization to prevent XSS via callback parameters
216
- */
217
- /**
218
- * Validates and sanitizes a JSONP callback parameter.
219
- *
220
- * Returns the callback name if safe, or null if the callback is dangerous.
221
- * Use this to validate `?callback=` query parameters before wrapping responses.
222
- *
223
- * @param callback - The callback parameter value
224
- * @param maxLength - Maximum allowed length (default: 128)
225
- * @returns The safe callback name, or null if invalid
226
- *
227
- * @example
228
- * ```ts
229
- * const cb = sanitizeJsonpCallback(req.query.callback);
230
- * if (cb) {
231
- * res.set('Content-Type', 'application/javascript');
232
- * res.send(`${cb}(${JSON.stringify(data)})`);
233
- * } else {
234
- * res.status(400).json({ error: 'Invalid callback' });
235
- * }
236
- * ```
237
- */
238
- declare function sanitizeJsonpCallback(callback: string, maxLength?: number): string | null;
239
- /**
240
- * Checks if a JSONP callback parameter contains potentially dangerous content.
241
- *
242
- * @param callback - The callback parameter value
243
- * @returns True if the callback is dangerous / invalid
244
- */
245
- declare function detectJsonpInjection(callback: string): boolean;
246
-
247
- /**
248
- * @module @arcis/node/sanitizers/nosql
249
- * NoSQL injection prevention (MongoDB operators)
250
- */
251
- /**
252
- * Checks if a key is a dangerous MongoDB operator.
253
- *
254
- * @param key - The key to check
255
- * @returns True if the key is a MongoDB operator
256
- *
257
- * @example
258
- * isDangerousNoSqlKey('$gt') // true
259
- * isDangerousNoSqlKey('name') // false
260
- */
261
- declare function isDangerousNoSqlKey(key: string): boolean;
262
- /**
263
- * Recursively checks if an object contains dangerous MongoDB operators.
264
- *
265
- * @param obj - The object to check
266
- * @param maxDepth - Maximum recursion depth (default: 10)
267
- * @returns True if dangerous operators found
268
- */
269
- declare function detectNoSqlInjection(obj: unknown, maxDepth?: number): boolean;
270
- /**
271
- * Get list of all MongoDB operators considered dangerous.
272
- * Useful for documentation or custom validation.
273
- *
274
- * @returns Array of dangerous operator strings
275
- */
276
- declare function getDangerousOperators(): string[];
277
-
278
- /**
279
- * @module @arcis/node/sanitizers/prototype
280
- * Prototype pollution prevention
281
- */
282
- /**
283
- * Checks if a key is dangerous for prototype pollution.
284
- * Case-insensitive — catches __PROTO__, Constructor, etc.
285
- *
286
- * @param key - The key to check
287
- * @returns True if the key could cause prototype pollution
288
- *
289
- * @example
290
- * isDangerousProtoKey('__proto__') // true
291
- * isDangerousProtoKey('__PROTO__') // true
292
- * isDangerousProtoKey('Constructor') // true
293
- * isDangerousProtoKey('name') // false
294
- */
295
- declare function isDangerousProtoKey(key: string): boolean;
296
- /**
297
- * Recursively checks if an object contains prototype pollution keys.
298
- *
299
- * @param obj - The object to check
300
- * @param maxDepth - Maximum recursion depth (default: 10)
301
- * @returns True if dangerous keys found
302
- */
303
- declare function detectPrototypePollution(obj: unknown, maxDepth?: number): boolean;
304
- /**
305
- * Get list of all keys considered dangerous for prototype pollution.
306
- * Useful for documentation or custom validation.
307
- *
308
- * @returns Array of dangerous key strings
309
- */
310
- declare function getDangerousProtoKeys(): string[];
311
-
312
- /**
313
- * @module @arcis/node/sanitizers/headers
314
- * HTTP Header Injection & CRLF Injection prevention
315
- *
316
- * Prevents attackers from injecting newline characters (\r\n) into HTTP header
317
- * values, which can lead to response splitting, session fixation, XSS via
318
- * injected headers, and cache poisoning.
319
- */
320
-
321
- /**
322
- * Sanitizes a header value by stripping CRLF sequences, bare CR/LF, and null bytes.
323
- *
324
- * @param input - The header value to sanitize
325
- * @param collectThreats - Whether to collect threat information (default: false)
326
- * @returns Sanitized string or SanitizeResult if collectThreats is true
327
- *
328
- * @example
329
- * sanitizeHeaderValue("safe-value")
330
- * // Returns: "safe-value"
331
- *
332
- * sanitizeHeaderValue("value\r\nX-Injected: evil")
333
- * // Returns: "valueX-Injected: evil"
334
- */
335
- declare function sanitizeHeaderValue(input: string, collectThreats?: false): string;
336
- declare function sanitizeHeaderValue(input: string, collectThreats: true): SanitizeResult;
337
- /**
338
- * Sanitizes an object of header key-value pairs.
339
- * Strips CRLF/null bytes from both keys and values.
340
- *
341
- * @param headers - Object with header names as keys and header values as values
342
- * @returns New object with sanitized header names and values
343
- *
344
- * @example
345
- * sanitizeHeaders({ "X-Custom": "safe", "X-Bad\r\n": "value\r\ninjected" })
346
- * // Returns: { "X-Custom": "safe", "X-Bad": "valueinjected" }
347
- */
348
- declare function sanitizeHeaders(headers: Record<string, string>): Record<string, string>;
349
- /**
350
- * Checks if a string contains HTTP header injection patterns (CRLF, null bytes).
351
- * Does not sanitize — use sanitizeHeaderValue() for that.
352
- *
353
- * @param input - The string to check
354
- * @returns True if header injection patterns detected
355
- */
356
- declare function detectHeaderInjection(input: string): boolean;
357
-
358
- /**
359
- * @module @arcis/node/sanitizers/pii
360
- * PII (Personally Identifiable Information) detection and redaction
361
- *
362
- * Detects: email addresses, phone numbers, credit card numbers, SSNs, IP addresses
363
- */
364
- type PiiType = 'email' | 'phone' | 'credit_card' | 'ssn' | 'ip_address';
365
- interface PiiMatch {
366
- type: PiiType;
367
- value: string;
368
- start: number;
369
- end: number;
370
- }
371
- interface PiiScanOptions {
372
- /** PII types to scan for. Default: all types */
373
- types?: PiiType[];
374
- }
375
- interface PiiRedactOptions extends PiiScanOptions {
376
- /** Replacement for redacted values. Default: '[REDACTED]' */
377
- replacement?: string;
378
- /** Use type-specific replacements like '[EMAIL]', '[SSN]'. Default: false */
379
- typeLabels?: boolean;
380
- }
381
- /**
382
- * Scan a string for PII and return all matches.
383
- *
384
- * @param input - String to scan
385
- * @param options - Optional scan configuration
386
- * @returns Array of PII matches with type, value, and position
387
- *
388
- * @example
389
- * scanPii('Call me at 555-123-4567 or email john@example.com')
390
- * // [
391
- * // { type: 'phone', value: '555-123-4567', start: 11, end: 23 },
392
- * // { type: 'email', value: 'john@example.com', start: 33, end: 49 }
393
- * // ]
394
- */
395
- declare function scanPii(input: string, options?: PiiScanOptions): PiiMatch[];
396
- /**
397
- * Check if a string contains any PII.
398
- *
399
- * @param input - String to check
400
- * @param options - Optional scan configuration
401
- * @returns true if PII is detected
402
- */
403
- declare function detectPii(input: string, options?: PiiScanOptions): boolean;
404
- /**
405
- * Redact PII from a string, replacing matches with a placeholder.
406
- *
407
- * @param input - String to redact
408
- * @param options - Redaction options
409
- * @returns String with PII replaced
410
- *
411
- * @example
412
- * redactPii('Email: john@example.com, SSN: 123-45-6789')
413
- * // 'Email: [REDACTED], SSN: [REDACTED]'
414
- *
415
- * redactPii('Email: john@example.com', { typeLabels: true })
416
- * // 'Email: [EMAIL]'
417
- */
418
- declare function redactPii(input: string, options?: PiiRedactOptions): string;
419
- /**
420
- * Scan an object's string values for PII recursively.
421
- *
422
- * @param obj - Object to scan
423
- * @param options - Optional scan configuration
424
- * @returns Array of PII matches with the field path prepended
425
- */
426
- declare function scanObjectPii(obj: Record<string, unknown>, options?: PiiScanOptions, path?: string): (PiiMatch & {
427
- field: string;
428
- })[];
429
- /**
430
- * Redact PII from all string values in an object recursively.
431
- *
432
- * @param obj - Object to redact
433
- * @param options - Redaction options
434
- * @returns New object with PII redacted
435
- */
436
- declare function redactObjectPii<T extends Record<string, unknown>>(obj: T, options?: PiiRedactOptions): T;
437
-
438
- /**
439
- * @module @arcis/node/sanitizers/encode
440
- * Context-aware output encoding for XSS prevention.
441
- *
442
- * Wrong-context encoding is the #1 cause of XSS bypasses in "protected" apps.
443
- * A single sanitize() is not enough when output goes to JS, CSS, or attribute contexts.
444
- */
445
- /**
446
- * Encodes for HTML body context. Entity-encodes & < > " '
447
- *
448
- * Use when outputting to HTML element content:
449
- * `<p>${encodeForHtml(userInput)}</p>`
450
- */
451
- declare function encodeForHtml(value: string): string;
452
- /**
453
- * Encodes for HTML attribute context.
454
- * All non-alphanumeric characters are encoded as `&#xHH;` hex entities.
455
- *
456
- * Use when outputting to HTML attributes:
457
- * `<div title="${encodeForAttribute(userInput)}">`
458
- */
459
- declare function encodeForAttribute(value: string): string;
460
- /**
461
- * Encodes for JavaScript string context.
462
- * Non-alphanumeric characters are escaped as `\xHH` (ASCII) or `\uHHHH` (Unicode).
463
- *
464
- * Use when embedding in JS string literals:
465
- * `var x = '${encodeForJs(userInput)}';`
466
- */
467
- declare function encodeForJs(value: string): string;
468
- /**
469
- * Encodes for URL parameter context. Percent-encodes all non-unreserved chars.
470
- *
471
- * Use when building query strings:
472
- * `?q=${encodeForUrl(userInput)}`
473
- */
474
- declare function encodeForUrl(value: string): string;
475
- /**
476
- * Encodes for CSS value context.
477
- * Non-alphanumeric characters are hex-escaped as `\HH ` (trailing space per CSS spec).
478
- *
479
- * Use when embedding in CSS values:
480
- * `content: '${encodeForCss(userInput)}';`
481
- */
482
- declare function encodeForCss(value: string): string;
483
-
484
- export { sanitizeJsonpCallback as A, sanitizeObject as B, sanitizePath as C, sanitizeSql as D, sanitizeSsti as E, sanitizeString as F, sanitizeXss as G, sanitizeXxe as H, scanObjectPii as I, scanPii as J, type PiiRedactOptions as K, type PiiScanOptions as L, type PiiType as M, type PiiMatch as P, detectHeaderInjection as a, detectJsonpInjection as b, createSanitizer as c, detectCommandInjection as d, detectNoSqlInjection as e, detectPathTraversal as f, detectPii as g, detectPrototypePollution as h, detectSql as i, detectSsti as j, detectXss as k, detectXxe as l, encodeForAttribute as m, encodeForCss as n, encodeForHtml as o, encodeForJs as p, encodeForUrl as q, getDangerousOperators as r, getDangerousProtoKeys as s, isDangerousNoSqlKey as t, isDangerousProtoKey as u, redactObjectPii as v, redactPii as w, sanitizeCommand as x, sanitizeHeaderValue as y, sanitizeHeaders as z };