@arcis/node 1.3.0 → 1.4.2

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 (139) hide show
  1. package/README.md +1 -1
  2. package/dist/core/{index.d.mts → constants.d.ts} +21 -70
  3. package/dist/core/constants.d.ts.map +1 -0
  4. package/dist/core/errors.d.ts +53 -0
  5. package/dist/core/errors.d.ts.map +1 -0
  6. package/dist/core/index.d.ts +6 -168
  7. package/dist/core/index.d.ts.map +1 -0
  8. package/dist/core/index.js +11 -3
  9. package/dist/core/index.js.map +1 -1
  10. package/dist/core/index.mjs +11 -3
  11. package/dist/core/index.mjs.map +1 -1
  12. package/dist/{types-BOkx5YJc.d.mts → core/types.d.ts} +27 -30
  13. package/dist/core/types.d.ts.map +1 -0
  14. package/dist/index.d.ts +71 -166
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +182 -48
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.mjs +182 -50
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/logging/index.d.ts +4 -36
  21. package/dist/logging/index.d.ts.map +1 -0
  22. package/dist/logging/index.js.map +1 -1
  23. package/dist/logging/index.mjs.map +1 -1
  24. package/dist/logging/{index.d.mts → redactor.d.ts} +5 -9
  25. package/dist/logging/redactor.d.ts.map +1 -0
  26. package/dist/middleware/bot-detection.d.ts +86 -0
  27. package/dist/middleware/bot-detection.d.ts.map +1 -0
  28. package/dist/middleware/cookies.d.ts +48 -0
  29. package/dist/middleware/cookies.d.ts.map +1 -0
  30. package/dist/middleware/cors.d.ts +65 -0
  31. package/dist/middleware/cors.d.ts.map +1 -0
  32. package/dist/middleware/csrf.d.ts +109 -0
  33. package/dist/middleware/csrf.d.ts.map +1 -0
  34. package/dist/middleware/error-handler.d.ts +43 -0
  35. package/dist/middleware/error-handler.d.ts.map +1 -0
  36. package/dist/middleware/headers.d.ts +29 -0
  37. package/dist/middleware/headers.d.ts.map +1 -0
  38. package/dist/middleware/hpp.d.ts +56 -0
  39. package/dist/middleware/hpp.d.ts.map +1 -0
  40. package/dist/middleware/index.d.ts +16 -3
  41. package/dist/middleware/index.d.ts.map +1 -0
  42. package/dist/middleware/index.js +68 -31
  43. package/dist/middleware/index.js.map +1 -1
  44. package/dist/middleware/index.mjs +69 -32
  45. package/dist/middleware/index.mjs.map +1 -1
  46. package/dist/middleware/main.d.ts +40 -0
  47. package/dist/middleware/main.d.ts.map +1 -0
  48. package/dist/middleware/rate-limit-sliding.d.ts +46 -0
  49. package/dist/middleware/rate-limit-sliding.d.ts.map +1 -0
  50. package/dist/middleware/rate-limit-token.d.ts +51 -0
  51. package/dist/middleware/rate-limit-token.d.ts.map +1 -0
  52. package/dist/middleware/rate-limit.d.ts +34 -0
  53. package/dist/middleware/rate-limit.d.ts.map +1 -0
  54. package/dist/sanitizers/command.d.ts +28 -0
  55. package/dist/sanitizers/command.d.ts.map +1 -0
  56. package/dist/sanitizers/encode.d.ts +46 -0
  57. package/dist/sanitizers/encode.d.ts.map +1 -0
  58. package/dist/sanitizers/headers.d.ts +46 -0
  59. package/dist/sanitizers/headers.d.ts.map +1 -0
  60. package/dist/sanitizers/index.d.ts +18 -22
  61. package/dist/sanitizers/index.d.ts.map +1 -0
  62. package/dist/sanitizers/index.js +90 -32
  63. package/dist/sanitizers/index.js.map +1 -1
  64. package/dist/sanitizers/index.mjs +88 -33
  65. package/dist/sanitizers/index.mjs.map +1 -1
  66. package/dist/sanitizers/jsonp.d.ts +34 -0
  67. package/dist/sanitizers/jsonp.d.ts.map +1 -0
  68. package/dist/sanitizers/ldap.d.ts +42 -0
  69. package/dist/sanitizers/ldap.d.ts.map +1 -0
  70. package/dist/sanitizers/nosql.d.ts +31 -0
  71. package/dist/sanitizers/nosql.d.ts.map +1 -0
  72. package/dist/sanitizers/path.d.ts +28 -0
  73. package/dist/sanitizers/path.d.ts.map +1 -0
  74. package/dist/sanitizers/pii.d.ts +80 -0
  75. package/dist/sanitizers/pii.d.ts.map +1 -0
  76. package/dist/sanitizers/prototype.d.ts +34 -0
  77. package/dist/sanitizers/prototype.d.ts.map +1 -0
  78. package/dist/sanitizers/sanitize.d.ts +51 -0
  79. package/dist/sanitizers/sanitize.d.ts.map +1 -0
  80. package/dist/sanitizers/sql.d.ts +28 -0
  81. package/dist/sanitizers/sql.d.ts.map +1 -0
  82. package/dist/sanitizers/ssti.d.ts +20 -0
  83. package/dist/sanitizers/ssti.d.ts.map +1 -0
  84. package/dist/sanitizers/utils.d.ts +19 -0
  85. package/dist/sanitizers/utils.d.ts.map +1 -0
  86. package/dist/sanitizers/xss.d.ts +35 -0
  87. package/dist/sanitizers/xss.d.ts.map +1 -0
  88. package/dist/sanitizers/xxe.d.ts +20 -0
  89. package/dist/sanitizers/xxe.d.ts.map +1 -0
  90. package/dist/stores/index.d.ts +6 -104
  91. package/dist/stores/index.d.ts.map +1 -0
  92. package/dist/stores/index.js +21 -1
  93. package/dist/stores/index.js.map +1 -1
  94. package/dist/stores/index.mjs +21 -1
  95. package/dist/stores/index.mjs.map +1 -1
  96. package/dist/stores/memory.d.ts +29 -0
  97. package/dist/stores/memory.d.ts.map +1 -0
  98. package/dist/stores/{index.d.mts → redis.d.ts} +6 -45
  99. package/dist/stores/redis.d.ts.map +1 -0
  100. package/dist/utils/duration.d.ts +34 -0
  101. package/dist/utils/duration.d.ts.map +1 -0
  102. package/dist/utils/fingerprint.d.ts +64 -0
  103. package/dist/utils/fingerprint.d.ts.map +1 -0
  104. package/dist/utils/index.d.ts +10 -0
  105. package/dist/utils/index.d.ts.map +1 -0
  106. package/dist/utils/index.js +188 -0
  107. package/dist/utils/index.js.map +1 -0
  108. package/dist/utils/index.mjs +182 -0
  109. package/dist/utils/index.mjs.map +1 -0
  110. package/dist/utils/ip.d.ts +70 -0
  111. package/dist/utils/ip.d.ts.map +1 -0
  112. package/dist/validation/email.d.ts +82 -0
  113. package/dist/validation/email.d.ts.map +1 -0
  114. package/dist/validation/file.d.ts +90 -0
  115. package/dist/validation/file.d.ts.map +1 -0
  116. package/dist/validation/index.d.ts +10 -3
  117. package/dist/validation/index.d.ts.map +1 -0
  118. package/dist/validation/index.js +38 -21
  119. package/dist/validation/index.js.map +1 -1
  120. package/dist/validation/index.mjs +38 -21
  121. package/dist/validation/index.mjs.map +1 -1
  122. package/dist/validation/redirect.d.ts +64 -0
  123. package/dist/validation/redirect.d.ts.map +1 -0
  124. package/dist/validation/schema.d.ts +36 -0
  125. package/dist/validation/schema.d.ts.map +1 -0
  126. package/dist/validation/url.d.ts +65 -0
  127. package/dist/validation/url.d.ts.map +1 -0
  128. package/package.json +8 -6
  129. package/dist/encode-CrQCGlBq.d.mts +0 -484
  130. package/dist/encode-jl9sOwmA.d.ts +0 -484
  131. package/dist/index-BAhgn9V2.d.ts +0 -532
  132. package/dist/index-BGNKspqH.d.ts +0 -340
  133. package/dist/index-Cd02z-0j.d.mts +0 -340
  134. package/dist/index-DgJtWMSj.d.mts +0 -532
  135. package/dist/index.d.mts +0 -175
  136. package/dist/middleware/index.d.mts +0 -3
  137. package/dist/sanitizers/index.d.mts +0 -24
  138. package/dist/types-BOkx5YJc.d.ts +0 -279
  139. package/dist/validation/index.d.mts +0 -3
@@ -0,0 +1,40 @@
1
+ /**
2
+ * @module @arcis/node/middleware/main
3
+ * Main arcis() middleware factory
4
+ */
5
+ import type { ArcisOptions, ArcisFunction, ArcisMiddlewareStack } from '../core/types';
6
+ /**
7
+ * Create Arcis middleware with all protections enabled.
8
+ *
9
+ * @param options - Configuration options
10
+ * @returns Array of Express middleware
11
+ *
12
+ * @example
13
+ * // Full protection (recommended)
14
+ * app.use(arcis());
15
+ *
16
+ * @example
17
+ * // Custom configuration
18
+ * app.use(arcis({
19
+ * rateLimit: { max: 50 },
20
+ * headers: { frameOptions: 'SAMEORIGIN' }
21
+ * }));
22
+ *
23
+ * @example
24
+ * // Disable specific features
25
+ * app.use(arcis({
26
+ * rateLimit: false,
27
+ * sanitize: { sql: false }
28
+ * }));
29
+ *
30
+ * @example
31
+ * // Cleanup on shutdown
32
+ * const middleware = arcis();
33
+ * app.use(middleware);
34
+ * process.on('SIGTERM', () => middleware.close());
35
+ */
36
+ export declare function arcis(options?: ArcisOptions): ArcisMiddlewareStack;
37
+ declare const arcisWithMethods: ArcisFunction;
38
+ export { arcisWithMethods as arcisFunction };
39
+ export default arcisWithMethods;
40
+ //# sourceMappingURL=main.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"main.d.ts","sourceRoot":"","sources":["../../src/middleware/main.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACV,YAAY,EACZ,aAAa,EACb,oBAAoB,EAIrB,MAAM,eAAe,CAAC;AAQvB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,oBAAoB,CAuCtE;AAGD,QAAA,MAAM,gBAAgB,EAAY,aAAa,CAAC;AAQhD,OAAO,EAAE,gBAAgB,IAAI,aAAa,EAAE,CAAC;AAC7C,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module @arcis/node/middleware/rate-limit-sliding
3
+ * Sliding window rate limiting middleware.
4
+ *
5
+ * More accurate than fixed window — uses a weighted sum of the previous
6
+ * and current window to approximate a true sliding window.
7
+ *
8
+ * Algorithm:
9
+ * weight = (windowMs - elapsed) / windowMs
10
+ * count = (prevWindow * weight) + currentWindow
11
+ * allow = count < limit
12
+ *
13
+ * @example
14
+ * app.use(createSlidingWindowLimiter({ max: 100, window: '15m' }));
15
+ */
16
+ import type { Request, RequestHandler } from 'express';
17
+ export interface SlidingWindowOptions {
18
+ /** Maximum requests per window. Default: 100 */
19
+ max?: number;
20
+ /** Window size in ms or duration string. Default: '1m' */
21
+ window?: string | number;
22
+ /** Error message when limit exceeded */
23
+ message?: string;
24
+ /** HTTP status code for rate limited responses. Default: 429 */
25
+ statusCode?: number;
26
+ /** Function to generate rate limit key from request */
27
+ keyGenerator?: (req: Request) => string;
28
+ /** Function to skip rate limiting for certain requests */
29
+ skip?: (req: Request) => boolean;
30
+ }
31
+ export interface SlidingWindowMiddleware extends RequestHandler {
32
+ close: () => void;
33
+ }
34
+ /**
35
+ * Create sliding window rate limiter middleware.
36
+ *
37
+ * @example
38
+ * // 100 requests per 15 minutes
39
+ * app.use(createSlidingWindowLimiter({ max: 100, window: '15m' }));
40
+ *
41
+ * @example
42
+ * // Strict API limit
43
+ * app.use('/api', createSlidingWindowLimiter({ max: 30, window: '1m' }));
44
+ */
45
+ export declare function createSlidingWindowLimiter(options?: SlidingWindowOptions): SlidingWindowMiddleware;
46
+ //# sourceMappingURL=rate-limit-sliding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit-sliding.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit-sliding.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAA0B,cAAc,EAAE,MAAM,SAAS,CAAC;AAI/E,MAAM,WAAW,oBAAoB;IACnC,gDAAgD;IAChD,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,0DAA0D;IAC1D,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IACxC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;CAClC;AAOD,MAAM,WAAW,uBAAwB,SAAQ,cAAc;IAC7D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,CAAC,OAAO,GAAE,oBAAyB,GAAG,uBAAuB,CAiGtG"}
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @module @arcis/node/middleware/rate-limit-token
3
+ * Token bucket rate limiting middleware.
4
+ *
5
+ * Allows burst traffic while enforcing an average rate.
6
+ * Tokens refill at a steady rate. Each request costs 1 token.
7
+ *
8
+ * Algorithm:
9
+ * tokens = min(capacity, tokens + elapsed * refillRate)
10
+ * if tokens >= cost: allow, subtract cost
11
+ * else: deny
12
+ *
13
+ * @example
14
+ * app.use(createTokenBucketLimiter({ capacity: 50, refillRate: 10 }));
15
+ */
16
+ import type { Request, RequestHandler } from 'express';
17
+ export interface TokenBucketOptions {
18
+ /** Maximum tokens (burst size). Default: 100 */
19
+ capacity?: number;
20
+ /** Tokens added per second. Default: 10 */
21
+ refillRate?: number;
22
+ /** Tokens consumed per request. Default: 1 */
23
+ cost?: number;
24
+ /** Error message when limit exceeded */
25
+ message?: string;
26
+ /** HTTP status code for rate limited responses. Default: 429 */
27
+ statusCode?: number;
28
+ /** Function to generate rate limit key from request */
29
+ keyGenerator?: (req: Request) => string;
30
+ /** Function to skip rate limiting for certain requests */
31
+ skip?: (req: Request) => boolean;
32
+ }
33
+ export interface TokenBucketMiddleware extends RequestHandler {
34
+ close: () => void;
35
+ }
36
+ /**
37
+ * Create token bucket rate limiter middleware.
38
+ *
39
+ * @example
40
+ * // Allow bursts of 50, sustained rate of 10/sec
41
+ * app.use(createTokenBucketLimiter({ capacity: 50, refillRate: 10 }));
42
+ *
43
+ * @example
44
+ * // Strict API: 5 requests burst, 1/sec sustained
45
+ * app.use('/api/expensive', createTokenBucketLimiter({
46
+ * capacity: 5,
47
+ * refillRate: 1,
48
+ * }));
49
+ */
50
+ export declare function createTokenBucketLimiter(options?: TokenBucketOptions): TokenBucketMiddleware;
51
+ //# sourceMappingURL=rate-limit-token.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit-token.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit-token.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,OAAO,EAA0B,cAAc,EAAE,MAAM,SAAS,CAAC;AAG/E,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8CAA8C;IAC9C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gEAAgE;IAChE,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAAC;IACxC,0DAA0D;IAC1D,IAAI,CAAC,EAAE,CAAC,GAAG,EAAE,OAAO,KAAK,OAAO,CAAC;CAClC;AAOD,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,GAAE,kBAAuB,GAAG,qBAAqB,CA2FhG"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * @module @arcis/node/middleware/rate-limit
3
+ * Rate limiting middleware
4
+ */
5
+ import type { RateLimitOptions, RateLimiterMiddleware } from '../core/types';
6
+ /**
7
+ * Create Express middleware for rate limiting.
8
+ *
9
+ * @param options - Rate limit configuration
10
+ * @returns Express middleware with cleanup method
11
+ *
12
+ * @example
13
+ * app.use(createRateLimiter({ max: 100, windowMs: 60000 }));
14
+ *
15
+ * @example
16
+ * // Skip rate limiting for certain routes
17
+ * app.use(createRateLimiter({
18
+ * max: 50,
19
+ * skip: (req) => req.path === '/health'
20
+ * }));
21
+ *
22
+ * @example
23
+ * // Cleanup on shutdown
24
+ * const limiter = createRateLimiter();
25
+ * app.use(limiter);
26
+ * process.on('SIGTERM', () => limiter.close());
27
+ */
28
+ export declare function createRateLimiter(options?: RateLimitOptions): RateLimiterMiddleware;
29
+ /**
30
+ * Alias for createRateLimiter
31
+ * @see createRateLimiter
32
+ */
33
+ export declare const rateLimit: typeof createRateLimiter;
34
+ //# sourceMappingURL=rate-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rate-limit.d.ts","sourceRoot":"","sources":["../../src/middleware/rate-limit.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAkB,MAAM,eAAe,CAAC;AAO7F;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,GAAE,gBAAqB,GAAG,qBAAqB,CAoIvF;AAED;;;GAGG;AACH,eAAO,MAAM,SAAS,0BAAoB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/command
3
+ * Command injection prevention
4
+ */
5
+ import type { SanitizeResult } from '../core/types';
6
+ /**
7
+ * Sanitizes a string to prevent command injection attacks.
8
+ * Replaces shell metacharacters and dangerous commands with [BLOCKED].
9
+ *
10
+ * @param input - The string to sanitize
11
+ * @param collectThreats - Whether to collect threat information (default: false for performance)
12
+ * @returns Sanitized string or SanitizeResult if collectThreats is true
13
+ *
14
+ * @example
15
+ * sanitizeCommand("file.txt; rm -rf /")
16
+ * // Returns: "file.txt rm -rf /"
17
+ */
18
+ export declare function sanitizeCommand(input: string, collectThreats?: false): string;
19
+ export declare function sanitizeCommand(input: string, collectThreats: true): SanitizeResult;
20
+ /**
21
+ * Checks if a string contains command injection patterns.
22
+ * Does not sanitize — use sanitizeCommand() for that.
23
+ *
24
+ * @param input - The string to check
25
+ * @returns True if command injection patterns detected
26
+ */
27
+ export declare function detectCommandInjection(input: string): boolean;
28
+ //# sourceMappingURL=command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../src/sanitizers/command.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAEhE;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AAC/E,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,GAAG,cAAc,CAAC;AA4CrF;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAW7D"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/encode
3
+ * Context-aware output encoding for XSS prevention.
4
+ *
5
+ * Wrong-context encoding is the #1 cause of XSS bypasses in "protected" apps.
6
+ * A single sanitize() is not enough when output goes to JS, CSS, or attribute contexts.
7
+ */
8
+ /**
9
+ * Encodes for HTML body context. Entity-encodes & < > " '
10
+ *
11
+ * Use when outputting to HTML element content:
12
+ * `<p>${encodeForHtml(userInput)}</p>`
13
+ */
14
+ export declare function encodeForHtml(value: string): string;
15
+ /**
16
+ * Encodes for HTML attribute context.
17
+ * All non-alphanumeric characters are encoded as `&#xHH;` hex entities.
18
+ *
19
+ * Use when outputting to HTML attributes:
20
+ * `<div title="${encodeForAttribute(userInput)}">`
21
+ */
22
+ export declare function encodeForAttribute(value: string): string;
23
+ /**
24
+ * Encodes for JavaScript string context.
25
+ * Non-alphanumeric characters are escaped as `\xHH` (ASCII) or `\uHHHH` (Unicode).
26
+ *
27
+ * Use when embedding in JS string literals:
28
+ * `var x = '${encodeForJs(userInput)}';`
29
+ */
30
+ export declare function encodeForJs(value: string): string;
31
+ /**
32
+ * Encodes for URL parameter context. Percent-encodes all non-unreserved chars.
33
+ *
34
+ * Use when building query strings:
35
+ * `?q=${encodeForUrl(userInput)}`
36
+ */
37
+ export declare function encodeForUrl(value: string): string;
38
+ /**
39
+ * Encodes for CSS value context.
40
+ * Non-alphanumeric characters are hex-escaped as `\HH ` (trailing space per CSS spec).
41
+ *
42
+ * Use when embedding in CSS values:
43
+ * `content: '${encodeForCss(userInput)}';`
44
+ */
45
+ export declare function encodeForCss(value: string): string;
46
+ //# sourceMappingURL=encode.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../src/sanitizers/encode.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAaH;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAGnD;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBxD;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAwBjD;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAOlD;AAED;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAkBlD"}
@@ -0,0 +1,46 @@
1
+ /**
2
+ * @module @arcis/node/sanitizers/headers
3
+ * HTTP Header Injection & CRLF Injection prevention
4
+ *
5
+ * Prevents attackers from injecting newline characters (\r\n) into HTTP header
6
+ * values, which can lead to response splitting, session fixation, XSS via
7
+ * injected headers, and cache poisoning.
8
+ */
9
+ import type { SanitizeResult } from '../core/types';
10
+ /**
11
+ * Sanitizes a header value by stripping CRLF sequences, bare CR/LF, and null bytes.
12
+ *
13
+ * @param input - The header value to sanitize
14
+ * @param collectThreats - Whether to collect threat information (default: false)
15
+ * @returns Sanitized string or SanitizeResult if collectThreats is true
16
+ *
17
+ * @example
18
+ * sanitizeHeaderValue("safe-value")
19
+ * // Returns: "safe-value"
20
+ *
21
+ * sanitizeHeaderValue("value\r\nX-Injected: evil")
22
+ * // Returns: "valueX-Injected: evil"
23
+ */
24
+ export declare function sanitizeHeaderValue(input: string, collectThreats?: false): string;
25
+ export declare function sanitizeHeaderValue(input: string, collectThreats: true): SanitizeResult;
26
+ /**
27
+ * Sanitizes an object of header key-value pairs.
28
+ * Strips CRLF/null bytes from both keys and values.
29
+ *
30
+ * @param headers - Object with header names as keys and header values as values
31
+ * @returns New object with sanitized header names and values
32
+ *
33
+ * @example
34
+ * sanitizeHeaders({ "X-Custom": "safe", "X-Bad\r\n": "value\r\ninjected" })
35
+ * // Returns: { "X-Custom": "safe", "X-Bad": "valueinjected" }
36
+ */
37
+ export declare function sanitizeHeaders(headers: Record<string, string>): Record<string, string>;
38
+ /**
39
+ * Checks if a string contains HTTP header injection patterns (CRLF, null bytes).
40
+ * Does not sanitize — use sanitizeHeaderValue() for that.
41
+ *
42
+ * @param input - The string to check
43
+ * @returns True if header injection patterns detected
44
+ */
45
+ export declare function detectHeaderInjection(input: string): boolean;
46
+ //# sourceMappingURL=headers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.d.ts","sourceRoot":"","sources":["../../src/sanitizers/headers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAc,MAAM,eAAe,CAAC;AAUhE;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;AACnF,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,GAAG,cAAc,CAAC;AAuCzF;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAcvF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAK5D"}
@@ -1,24 +1,20 @@
1
- export { c as createSanitizer, d as detectCommandInjection, a as detectHeaderInjection, b as detectJsonpInjection, e as detectNoSqlInjection, f as detectPathTraversal, g as detectPii, h as detectPrototypePollution, i as detectSql, j as detectSsti, k as detectXss, l as detectXxe, m as encodeForAttribute, n as encodeForCss, o as encodeForHtml, p as encodeForJs, q as encodeForUrl, r as getDangerousOperators, s as getDangerousProtoKeys, t as isDangerousNoSqlKey, u as isDangerousProtoKey, v as redactObjectPii, w as redactPii, x as sanitizeCommand, y as sanitizeHeaderValue, z as sanitizeHeaders, A as sanitizeJsonpCallback, B as sanitizeObject, C as sanitizePath, D as sanitizeSql, E as sanitizeSsti, F as sanitizeString, G as sanitizeXss, H as sanitizeXxe, I as scanObjectPii, J as scanPii } from '../encode-jl9sOwmA.js';
2
- import 'express';
3
- import '../types-BOkx5YJc.js';
4
-
5
1
  /**
6
- * @module @arcis/node/sanitizers/utils
7
- * Shared utilities for sanitizers
2
+ * @module @arcis/node/sanitizers
3
+ * All sanitization functions for Arcis
8
4
  */
9
- /**
10
- * Encodes HTML entities to prevent interpretation as markup.
11
- *
12
- * @param str - The string to encode
13
- * @returns The encoded string
14
- */
15
- declare function encodeHtmlEntities(str: string): string;
16
- /**
17
- * Checks if a value is a plain object (not null, array, Date, etc.)
18
- *
19
- * @param value - Value to check
20
- * @returns True if plain object
21
- */
22
- declare function isPlainObject(value: unknown): value is Record<string, unknown>;
23
-
24
- export { encodeHtmlEntities, isPlainObject };
5
+ export { sanitizeString, sanitizeObject, createSanitizer } from './sanitize';
6
+ export { sanitizeXss, detectXss } from './xss';
7
+ export { sanitizeSql, detectSql } from './sql';
8
+ export { sanitizePath, detectPathTraversal } from './path';
9
+ export { sanitizeCommand, detectCommandInjection } from './command';
10
+ export { isDangerousNoSqlKey, detectNoSqlInjection, getDangerousOperators } from './nosql';
11
+ export { isDangerousProtoKey, detectPrototypePollution, getDangerousProtoKeys } from './prototype';
12
+ export { sanitizeSsti, detectSsti } from './ssti';
13
+ export { sanitizeXxe, detectXxe } from './xxe';
14
+ export { sanitizeJsonpCallback, detectJsonpInjection } from './jsonp';
15
+ export { sanitizeHeaderValue, sanitizeHeaders, detectHeaderInjection } from './headers';
16
+ export { scanPii, detectPii, redactPii, scanObjectPii, redactObjectPii } from './pii';
17
+ export { encodeForHtml, encodeForAttribute, encodeForJs, encodeForUrl, encodeForCss } from './encode';
18
+ export { sanitizeLdapFilter, sanitizeLdapDn, detectLdapInjection } from './ldap';
19
+ export { encodeHtmlEntities, isPlainObject } from './utils';
20
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/sanitizers/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAG7E,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAGpE,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAG3F,OAAO,EAAE,mBAAmB,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAGnG,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAGlD,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAG/C,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAGtE,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,WAAW,CAAC;AAGxF,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAGtF,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAGtG,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,QAAQ,CAAC;AAGjF,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC"}
@@ -27,7 +27,15 @@ var XSS_PATTERNS = [
27
27
  /** URL-encoded script tags */
28
28
  /%3Cscript/gi,
29
29
  /** SVG with onload */
30
- /<svg[^>]*onload/gi
30
+ /<svg[^>]*onload/gi,
31
+ /** form tags — phishing/credential harvesting via action= redirection */
32
+ /<form[\s>]/gi,
33
+ /** meta tags — http-equiv refresh redirects or CSP bypass */
34
+ /<meta[\s>]/gi,
35
+ /** base href hijacking — redirects all relative URLs to attacker domain */
36
+ /<base[\s>]/gi,
37
+ /** link tag injection — stylesheet or preload CSRF attacks */
38
+ /<link[\s>]/gi
31
39
  ];
32
40
  var XSS_REMOVE_PATTERNS = [
33
41
  /** Full script blocks (content + tags) */
@@ -54,7 +62,15 @@ var XSS_REMOVE_PATTERNS = [
54
62
  /javascript\s*:/gi,
55
63
  /vbscript\s*:/gi,
56
64
  /** data: URIs with HTML/script content */
57
- /data\s*:\s*text\/html[^>\s]*/gi
65
+ /data\s*:\s*text\/html[^>\s]*/gi,
66
+ /** form tag injection — phishing via action= redirection */
67
+ /<form[\s>][^>]*/gi,
68
+ /** meta tag injection — http-equiv refresh or CSP bypass */
69
+ /<meta[\s>][^>]*/gi,
70
+ /** base href hijacking */
71
+ /<base[\s>][^>]*/gi,
72
+ /** link tag injection — stylesheet or preload attacks */
73
+ /<link[\s>][^>]*/gi
58
74
  ];
59
75
  var SQL_PATTERNS = [
60
76
  /** SQL keywords */
@@ -118,8 +134,8 @@ var COMMAND_PATTERNS = [
118
134
  /[;&|`]/g,
119
135
  /** Command substitution: $( ... ) — matched as a pair to reduce false positives */
120
136
  /\$\(/g,
121
- /** URL-encoded newline/carriage-return injection (%0a, %0d) */
122
- /%0[ad]/gi
137
+ /** URL-encoded control characters (%00-%0F): null, tab, vtab, formfeed, LF, CR */
138
+ /%0[0-9a-f]/gi
123
139
  ];
124
140
  var DANGEROUS_PROTO_KEYS = /* @__PURE__ */ new Set([
125
141
  "__proto__",
@@ -323,26 +339,31 @@ function sanitizePath(input, collectThreats = false) {
323
339
  const threats = [];
324
340
  let value = input;
325
341
  let wasSanitized = false;
326
- for (const pattern of PATH_PATTERNS) {
327
- pattern.lastIndex = 0;
328
- if (pattern.test(value)) {
342
+ value = value.normalize("NFKC");
343
+ let prev;
344
+ do {
345
+ prev = value;
346
+ for (const pattern of PATH_PATTERNS) {
329
347
  pattern.lastIndex = 0;
330
- if (collectThreats) {
331
- const matches = value.match(pattern);
332
- if (matches) {
333
- for (const match of matches) {
334
- threats.push({
335
- type: "path_traversal",
336
- pattern: pattern.source,
337
- original: match
338
- });
348
+ if (pattern.test(value)) {
349
+ pattern.lastIndex = 0;
350
+ if (collectThreats) {
351
+ const matches = value.match(pattern);
352
+ if (matches) {
353
+ for (const match of matches) {
354
+ threats.push({
355
+ type: "path_traversal",
356
+ pattern: pattern.source,
357
+ original: match
358
+ });
359
+ }
339
360
  }
340
361
  }
362
+ value = value.replace(pattern, "");
363
+ wasSanitized = true;
341
364
  }
342
- value = value.replace(pattern, "");
343
- wasSanitized = true;
344
365
  }
345
- }
366
+ } while (value !== prev);
346
367
  if (collectThreats) {
347
368
  return { value, wasSanitized, threats };
348
369
  }
@@ -350,9 +371,10 @@ function sanitizePath(input, collectThreats = false) {
350
371
  }
351
372
  function detectPathTraversal(input) {
352
373
  if (typeof input !== "string") return false;
374
+ const normalized = input.normalize("NFKC");
353
375
  for (const pattern of PATH_PATTERNS) {
354
376
  pattern.lastIndex = 0;
355
- if (pattern.test(input)) {
377
+ if (pattern.test(normalized)) {
356
378
  return true;
357
379
  }
358
380
  }
@@ -410,7 +432,7 @@ function sanitizeString(value, options = {}) {
410
432
  if (value.length > maxSize) {
411
433
  throw new InputTooLargeError(maxSize, value.length);
412
434
  }
413
- const reject = options.mode !== "sanitize";
435
+ const reject = options.mode === "reject";
414
436
  let result = value;
415
437
  if (options.sql !== false) {
416
438
  if (reject) {
@@ -565,10 +587,22 @@ var SSTI_DETECT_PATTERNS = [
565
587
  /\{\{\s*(?:self|request|lipsum|cycler|joiner|namespace|range)\b/gi
566
588
  ];
567
589
  var SSTI_REMOVE_PATTERNS = [
590
+ /** Jinja2 / Twig: {{ ... }} — always strip (not valid in any JS context) */
568
591
  /\{\{.*?\}\}/g,
569
- /\$\{.*?\}/g,
592
+ /**
593
+ * Freemarker / Spring EL: ${...} — only strip when the expression contains
594
+ * operators (?!*+-/), method calls (), or known-dangerous prefixes.
595
+ * Bare ${name} and ${user.name} are left intact (JS template literal syntax).
596
+ */
597
+ /\$\{[^}]*[?!()*+\-/][^}]*\}/g,
598
+ /** ERB / EJS: <%= ... %> */
570
599
  /<%[=\-]?.*?%>/gs,
571
- /#\{.*?\}/g,
600
+ /**
601
+ * Pug / Jade: #{...} — same narrowing as ${ above.
602
+ * #{name} output expressions are left intact.
603
+ */
604
+ /#\{[^}]*[?!()*+\-/][^}]*\}/g,
605
+ /** Python dunder sandbox escape — always strip */
572
606
  /__(?:class|mro|subclasses|globals|builtins|import)__/gi
573
607
  ];
574
608
  function sanitizeSsti(input, collectThreats = false) {
@@ -932,16 +966,18 @@ function encodeForAttribute(value) {
932
966
  function encodeForJs(value) {
933
967
  if (!value) return "";
934
968
  let result = "";
935
- for (let i = 0; i < value.length; i++) {
936
- const ch = value.charCodeAt(i);
937
- if (ch >= 48 && ch <= 57 || // 0-9
938
- ch >= 65 && ch <= 90 || // A-Z
939
- ch >= 97 && ch <= 122) {
940
- result += value[i];
941
- } else if (ch < 256) {
942
- result += `\\x${ch.toString(16).toUpperCase().padStart(2, "0")}`;
969
+ for (const char of value) {
970
+ const cp = char.codePointAt(0);
971
+ if (cp >= 48 && cp <= 57 || // 0-9
972
+ cp >= 65 && cp <= 90 || // A-Z
973
+ cp >= 97 && cp <= 122) {
974
+ result += char;
975
+ } else if (cp < 256) {
976
+ result += `\\x${cp.toString(16).toUpperCase().padStart(2, "0")}`;
977
+ } else if (cp <= 65535) {
978
+ result += `\\u${cp.toString(16).toUpperCase().padStart(4, "0")}`;
943
979
  } else {
944
- result += `\\u${ch.toString(16).toUpperCase().padStart(4, "0")}`;
980
+ result += `\\u{${cp.toString(16).toUpperCase()}}`;
945
981
  }
946
982
  }
947
983
  return result;
@@ -968,10 +1004,30 @@ function encodeForCss(value) {
968
1004
  return result;
969
1005
  }
970
1006
 
1007
+ // src/sanitizers/ldap.ts
1008
+ var LDAP_FILTER_CHARS = /[*()\\\x00]/g;
1009
+ var LDAP_DN_CHARS = /[,+<>;"=\/\\\x00*()\x00]/g;
1010
+ var LDAP_DETECT_PATTERN = /[*()\\\x00]/;
1011
+ var LDAP_INJECTION_PATTERN = /\)\s*\(|\*\s*\)\s*\(/;
1012
+ var escapeChar = (char) => "\\" + char.charCodeAt(0).toString(16).padStart(2, "0");
1013
+ function sanitizeLdapFilter(input) {
1014
+ if (typeof input !== "string") return String(input);
1015
+ return input.replace(LDAP_FILTER_CHARS, escapeChar);
1016
+ }
1017
+ function sanitizeLdapDn(input) {
1018
+ if (typeof input !== "string") return String(input);
1019
+ return input.replace(LDAP_DN_CHARS, escapeChar);
1020
+ }
1021
+ function detectLdapInjection(input) {
1022
+ if (typeof input !== "string") return false;
1023
+ return LDAP_DETECT_PATTERN.test(input) || LDAP_INJECTION_PATTERN.test(input);
1024
+ }
1025
+
971
1026
  exports.createSanitizer = createSanitizer;
972
1027
  exports.detectCommandInjection = detectCommandInjection;
973
1028
  exports.detectHeaderInjection = detectHeaderInjection;
974
1029
  exports.detectJsonpInjection = detectJsonpInjection;
1030
+ exports.detectLdapInjection = detectLdapInjection;
975
1031
  exports.detectNoSqlInjection = detectNoSqlInjection;
976
1032
  exports.detectPathTraversal = detectPathTraversal;
977
1033
  exports.detectPii = detectPii;
@@ -997,6 +1053,8 @@ exports.sanitizeCommand = sanitizeCommand;
997
1053
  exports.sanitizeHeaderValue = sanitizeHeaderValue;
998
1054
  exports.sanitizeHeaders = sanitizeHeaders;
999
1055
  exports.sanitizeJsonpCallback = sanitizeJsonpCallback;
1056
+ exports.sanitizeLdapDn = sanitizeLdapDn;
1057
+ exports.sanitizeLdapFilter = sanitizeLdapFilter;
1000
1058
  exports.sanitizeObject = sanitizeObject;
1001
1059
  exports.sanitizePath = sanitizePath;
1002
1060
  exports.sanitizeSql = sanitizeSql;