@zudojs/security 0.0.1

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 (95) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +37 -0
  3. package/dist/body/body.core.d.ts +51 -0
  4. package/dist/body/body.core.d.ts.map +1 -0
  5. package/dist/body/body.core.js +120 -0
  6. package/dist/body/body.core.js.map +1 -0
  7. package/dist/body/index.d.ts +5 -0
  8. package/dist/body/index.d.ts.map +1 -0
  9. package/dist/body/index.js +5 -0
  10. package/dist/body/index.js.map +1 -0
  11. package/dist/cookie/cookie.core.d.ts +58 -0
  12. package/dist/cookie/cookie.core.d.ts.map +1 -0
  13. package/dist/cookie/cookie.core.js +163 -0
  14. package/dist/cookie/cookie.core.js.map +1 -0
  15. package/dist/cookie/index.d.ts +5 -0
  16. package/dist/cookie/index.d.ts.map +1 -0
  17. package/dist/cookie/index.js +5 -0
  18. package/dist/cookie/index.js.map +1 -0
  19. package/dist/cors/cors.core.d.ts +58 -0
  20. package/dist/cors/cors.core.d.ts.map +1 -0
  21. package/dist/cors/cors.core.js +131 -0
  22. package/dist/cors/cors.core.js.map +1 -0
  23. package/dist/cors/cors.namespace.d.ts +15 -0
  24. package/dist/cors/cors.namespace.d.ts.map +1 -0
  25. package/dist/cors/cors.namespace.js +14 -0
  26. package/dist/cors/cors.namespace.js.map +1 -0
  27. package/dist/cors/index.d.ts +6 -0
  28. package/dist/cors/index.d.ts.map +1 -0
  29. package/dist/cors/index.js +5 -0
  30. package/dist/cors/index.js.map +1 -0
  31. package/dist/csrf/csrf.core.d.ts +56 -0
  32. package/dist/csrf/csrf.core.d.ts.map +1 -0
  33. package/dist/csrf/csrf.core.js +149 -0
  34. package/dist/csrf/csrf.core.js.map +1 -0
  35. package/dist/csrf/index.d.ts +5 -0
  36. package/dist/csrf/index.d.ts.map +1 -0
  37. package/dist/csrf/index.js +5 -0
  38. package/dist/csrf/index.js.map +1 -0
  39. package/dist/header/header.core.d.ts +47 -0
  40. package/dist/header/header.core.d.ts.map +1 -0
  41. package/dist/header/header.core.js +158 -0
  42. package/dist/header/header.core.js.map +1 -0
  43. package/dist/header/index.d.ts +5 -0
  44. package/dist/header/index.d.ts.map +1 -0
  45. package/dist/header/index.js +5 -0
  46. package/dist/header/index.js.map +1 -0
  47. package/dist/headers/headers.core.d.ts +48 -0
  48. package/dist/headers/headers.core.d.ts.map +1 -0
  49. package/dist/headers/headers.core.js +124 -0
  50. package/dist/headers/headers.core.js.map +1 -0
  51. package/dist/headers/index.d.ts +6 -0
  52. package/dist/headers/index.d.ts.map +1 -0
  53. package/dist/headers/index.js +6 -0
  54. package/dist/headers/index.js.map +1 -0
  55. package/dist/index.d.ts +44 -0
  56. package/dist/index.d.ts.map +1 -0
  57. package/dist/index.js +50 -0
  58. package/dist/index.js.map +1 -0
  59. package/dist/input/index.d.ts +5 -0
  60. package/dist/input/index.d.ts.map +1 -0
  61. package/dist/input/index.js +5 -0
  62. package/dist/input/index.js.map +1 -0
  63. package/dist/input/input.core.d.ts +73 -0
  64. package/dist/input/input.core.d.ts.map +1 -0
  65. package/dist/input/input.core.js +182 -0
  66. package/dist/input/input.core.js.map +1 -0
  67. package/dist/rateLimit/index.d.ts +5 -0
  68. package/dist/rateLimit/index.d.ts.map +1 -0
  69. package/dist/rateLimit/index.js +5 -0
  70. package/dist/rateLimit/index.js.map +1 -0
  71. package/dist/rateLimit/rateLimit.core.d.ts +51 -0
  72. package/dist/rateLimit/rateLimit.core.d.ts.map +1 -0
  73. package/dist/rateLimit/rateLimit.core.js +175 -0
  74. package/dist/rateLimit/rateLimit.core.js.map +1 -0
  75. package/dist/rateLimit/rateLimit.namespace.d.ts +13 -0
  76. package/dist/rateLimit/rateLimit.namespace.d.ts.map +1 -0
  77. package/dist/rateLimit/rateLimit.namespace.js +13 -0
  78. package/dist/rateLimit/rateLimit.namespace.js.map +1 -0
  79. package/dist/types/index.d.ts +8 -0
  80. package/dist/types/index.d.ts.map +1 -0
  81. package/dist/types/index.js +7 -0
  82. package/dist/types/index.js.map +1 -0
  83. package/dist/types/security.type.d.ts +203 -0
  84. package/dist/types/security.type.d.ts.map +1 -0
  85. package/dist/types/security.type.js +31 -0
  86. package/dist/types/security.type.js.map +1 -0
  87. package/dist/url/index.d.ts +5 -0
  88. package/dist/url/index.d.ts.map +1 -0
  89. package/dist/url/index.js +5 -0
  90. package/dist/url/index.js.map +1 -0
  91. package/dist/url/url.core.d.ts +38 -0
  92. package/dist/url/url.core.d.ts.map +1 -0
  93. package/dist/url/url.core.js +187 -0
  94. package/dist/url/url.core.js.map +1 -0
  95. package/package.json +53 -0
@@ -0,0 +1,51 @@
1
+ /**
2
+ * @zudojs/security — Rate Limiting
3
+ *
4
+ * Implements sliding window rate limiting to prevent abuse.
5
+ */
6
+ import type { RateLimitConfig, RateLimitRequest, RateLimitResult } from "../types/security.type.js";
7
+ /**
8
+ * Default key generator using IP address.
9
+ *
10
+ * @param request - The rate limit request.
11
+ * @returns The rate limit key.
12
+ */
13
+ export declare function defaultKeyGenerator(request: RateLimitRequest): string;
14
+ /**
15
+ * Default handler when rate limit is exceeded.
16
+ *
17
+ * @param _request - The rate limit request.
18
+ * @param response - The rate limit response to modify.
19
+ */
20
+ export declare function defaultHandler(_request: RateLimitRequest, response: {
21
+ statusCode: number;
22
+ headers: Record<string, string>;
23
+ body?: string;
24
+ }): void;
25
+ /**
26
+ * Creates an in-memory rate limiter.
27
+ *
28
+ * @param config - Rate limit configuration.
29
+ * @returns A function that checks rate limits.
30
+ */
31
+ export declare function createRateLimiter(config: RateLimitConfig): {
32
+ check: (request: RateLimitRequest) => RateLimitResult;
33
+ middleware: (request: RateLimitRequest, response?: {
34
+ statusCode: number;
35
+ headers: Record<string, string>;
36
+ body?: string;
37
+ }) => RateLimitResult;
38
+ reset: (key: string) => void;
39
+ clear: () => void;
40
+ getCount: (key: string) => number;
41
+ destroy: () => void;
42
+ };
43
+ /**
44
+ * Extracts the client IP from request headers.
45
+ * Used as a default key generator.
46
+ *
47
+ * @param headers - Request headers.
48
+ * @returns The client IP address.
49
+ */
50
+ export declare function extractClientIp(headers: Record<string, string | string[] | undefined>): string;
51
+ //# sourceMappingURL=rateLimit.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.core.d.ts","sourceRoot":"","sources":["../../src/rateLimit/rateLimit.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,eAAe,EAChB,MAAM,2BAA2B,CAAC;AAoBnC;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,QAAQ,EAAE,gBAAgB,EAC1B,QAAQ,EAAE;IACR,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GACA,IAAI,CAUN;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,eAAe;qBAwB/B,gBAAgB,KAAG,eAAe;0BA4C/C,gBAAgB,aACd;QACT,UAAU,EAAE,MAAM,CAAC;QACnB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,KACA,eAAe;iBAaE,MAAM,KAAG,IAAI;iBAOf,IAAI;oBAOC,MAAM,KAAG,MAAM;mBAYlB,IAAI;EAazB;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,GACrD,MAAM,CAiBR"}
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @zudojs/security — Rate Limiting
3
+ *
4
+ * Implements sliding window rate limiting to prevent abuse.
5
+ */
6
+ /** Default rate limit: 100 requests per minute. */
7
+ const DEFAULT_MAX = 100;
8
+ /** Default window: 1 minute. */
9
+ const DEFAULT_WINDOW_MS = 60_000;
10
+ /** Default rate limit message. */
11
+ const DEFAULT_MESSAGE = "Too many requests";
12
+ /**
13
+ * Default key generator using IP address.
14
+ *
15
+ * @param request - The rate limit request.
16
+ * @returns The rate limit key.
17
+ */
18
+ export function defaultKeyGenerator(request) {
19
+ return request.ip ?? "unknown";
20
+ }
21
+ /**
22
+ * Default handler when rate limit is exceeded.
23
+ *
24
+ * @param _request - The rate limit request.
25
+ * @param response - The rate limit response to modify.
26
+ */
27
+ export function defaultHandler(_request, response) {
28
+ response.statusCode = 429;
29
+ response.headers["Retry-After"] = "60";
30
+ response.headers["X-RateLimit-Remaining"] = "0";
31
+ response.body = JSON.stringify({
32
+ error: {
33
+ code: "RATE_LIMIT_EXCEEDED",
34
+ message: DEFAULT_MESSAGE,
35
+ },
36
+ });
37
+ }
38
+ /**
39
+ * Creates an in-memory rate limiter.
40
+ *
41
+ * @param config - Rate limit configuration.
42
+ * @returns A function that checks rate limits.
43
+ */
44
+ export function createRateLimiter(config) {
45
+ const store = new Map();
46
+ const keyGenerator = config.keyGenerator ?? defaultKeyGenerator;
47
+ const handler = config.handler;
48
+ const skip = config.skip;
49
+ // Cleanup old entries periodically
50
+ const cleanupInterval = setInterval(() => {
51
+ const now = Date.now();
52
+ for (const [key, entry] of store) {
53
+ if (now - entry.windowStart > config.windowMs * 2) {
54
+ store.delete(key);
55
+ }
56
+ }
57
+ }, config.windowMs);
58
+ // Allow cleanup to not keep process alive
59
+ if (cleanupInterval.unref) {
60
+ cleanupInterval.unref();
61
+ }
62
+ /**
63
+ * Checks if a request is allowed and updates the counter.
64
+ */
65
+ function check(request) {
66
+ // Skip if configured
67
+ if (skip && skip(request)) {
68
+ return {
69
+ allowed: true,
70
+ remaining: config.max,
71
+ resetAt: new Date(Date.now() + config.windowMs),
72
+ total: config.max,
73
+ };
74
+ }
75
+ const key = keyGenerator(request);
76
+ const now = Date.now();
77
+ const windowStart = now - config.windowMs;
78
+ let entry = store.get(key);
79
+ if (!entry || now - entry.windowStart >= config.windowMs) {
80
+ // New window
81
+ entry = { timestamps: [now], windowStart: now };
82
+ store.set(key, entry);
83
+ }
84
+ else {
85
+ // Existing window — remove expired timestamps
86
+ const validTimestamps = entry.timestamps.filter((t) => t > windowStart);
87
+ validTimestamps.push(now);
88
+ entry = { timestamps: validTimestamps, windowStart: entry.windowStart };
89
+ store.set(key, entry);
90
+ }
91
+ const remaining = Math.max(0, config.max - entry.timestamps.length);
92
+ const allowed = entry.timestamps.length <= config.max;
93
+ return {
94
+ allowed,
95
+ remaining,
96
+ resetAt: new Date(entry.windowStart + config.windowMs),
97
+ total: config.max,
98
+ };
99
+ }
100
+ /**
101
+ * Middleware-like function that checks and optionally handles rate limiting.
102
+ */
103
+ function middleware(request, response) {
104
+ const result = check(request);
105
+ if (!result.allowed && response && handler) {
106
+ handler(request, response);
107
+ }
108
+ return result;
109
+ }
110
+ /**
111
+ * Resets the rate limit for a specific key.
112
+ */
113
+ function reset(key) {
114
+ store.delete(key);
115
+ }
116
+ /**
117
+ * Clears all rate limit data.
118
+ */
119
+ function clear() {
120
+ store.clear();
121
+ }
122
+ /**
123
+ * Gets the current count for a key.
124
+ */
125
+ function getCount(key) {
126
+ const entry = store.get(key);
127
+ if (!entry)
128
+ return 0;
129
+ const now = Date.now();
130
+ const windowStart = now - config.windowMs;
131
+ return entry.timestamps.filter((t) => t > windowStart).length;
132
+ }
133
+ /**
134
+ * Destroys the rate limiter and cleans up resources.
135
+ */
136
+ function destroy() {
137
+ clearInterval(cleanupInterval);
138
+ store.clear();
139
+ }
140
+ return {
141
+ check,
142
+ middleware,
143
+ reset,
144
+ clear,
145
+ getCount,
146
+ destroy,
147
+ };
148
+ }
149
+ /**
150
+ * Extracts the client IP from request headers.
151
+ * Used as a default key generator.
152
+ *
153
+ * @param headers - Request headers.
154
+ * @returns The client IP address.
155
+ */
156
+ export function extractClientIp(headers) {
157
+ // X-Forwarded-For (first entry)
158
+ const forwarded = headers["x-forwarded-for"];
159
+ if (typeof forwarded === "string") {
160
+ const first = forwarded.split(",")[0]?.trim();
161
+ if (first)
162
+ return first;
163
+ }
164
+ if (Array.isArray(forwarded) && forwarded.length > 0) {
165
+ const first = forwarded[0]?.split(",")[0]?.trim();
166
+ if (first)
167
+ return first;
168
+ }
169
+ // X-Real-IP
170
+ const realIp = headers["x-real-ip"];
171
+ if (typeof realIp === "string")
172
+ return realIp;
173
+ return "unknown";
174
+ }
175
+ //# sourceMappingURL=rateLimit.core.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.core.js","sourceRoot":"","sources":["../../src/rateLimit/rateLimit.core.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,mDAAmD;AACnD,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,gCAAgC;AAChC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC,kCAAkC;AAClC,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAW5C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,OAAO,OAAO,CAAC,EAAE,IAAI,SAAS,CAAC;AACjC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAC5B,QAA0B,EAC1B,QAIC;IAED,QAAQ,CAAC,UAAU,GAAG,GAAG,CAAC;IAC1B,QAAQ,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,IAAI,CAAC;IACvC,QAAQ,CAAC,OAAO,CAAC,uBAAuB,CAAC,GAAG,GAAG,CAAC;IAChD,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC;QAC7B,KAAK,EAAE;YACL,IAAI,EAAE,qBAAqB;YAC3B,OAAO,EAAE,eAAe;SACzB;KACF,CAAC,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,iBAAiB,CAAC,MAAu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AAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACrD,MAAM,KAAK,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC;QAClD,IAAI,KAAK;YAAE,OAAO,KAAK,CAAC;IAC1B,CAAC;IAED,YAAY;IACZ,MAAM,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC;IACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAE9C,OAAO,SAAS,CAAC;AACnB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @zudojs/security — Rate Limit Namespace
3
+ *
4
+ * Convenience namespace for rate limiting utilities.
5
+ */
6
+ import { defaultKeyGenerator, defaultHandler, createRateLimiter, extractClientIp } from "./rateLimit.core.js";
7
+ export declare const rateLimit: {
8
+ defaultKeyGenerator: typeof defaultKeyGenerator;
9
+ defaultHandler: typeof defaultHandler;
10
+ createRateLimiter: typeof createRateLimiter;
11
+ extractClientIp: typeof extractClientIp;
12
+ };
13
+ //# sourceMappingURL=rateLimit.namespace.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.namespace.d.ts","sourceRoot":"","sources":["../../src/rateLimit/rateLimit.namespace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,eAAe,EAChB,MAAM,qBAAqB,CAAC;AAE7B,eAAO,MAAM,SAAS;;;;;CAKrB,CAAC"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @zudojs/security — Rate Limit Namespace
3
+ *
4
+ * Convenience namespace for rate limiting utilities.
5
+ */
6
+ import { defaultKeyGenerator, defaultHandler, createRateLimiter, extractClientIp, } from "./rateLimit.core.js";
7
+ export const rateLimit = {
8
+ defaultKeyGenerator,
9
+ defaultHandler,
10
+ createRateLimiter,
11
+ extractClientIp,
12
+ };
13
+ //# sourceMappingURL=rateLimit.namespace.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rateLimit.namespace.js","sourceRoot":"","sources":["../../src/rateLimit/rateLimit.namespace.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,mBAAmB;IACnB,cAAc;IACd,iBAAiB;IACjB,eAAe;CAChB,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * @zudojs/security — Types Barrel
3
+ *
4
+ * Re-exports all security configuration and result types.
5
+ */
6
+ export type { HeaderSecurityConfig, HeaderValidationResult, BodyLimitConfig, BodyLimitPresets, UrlValidationConfig, UrlValidationResult, CookieSecurityConfig, ParsedCookie, CorsConfig, CsrfConfig, RateLimitConfig, RateLimitRequest, RateLimitResponse, RateLimitResult, SecurityHeadersConfig, RequestValidationConfig, InputSanitizationConfig, } from "./security.type.js";
7
+ export { PROTOTYPE_POLLUTION_KEYS, SQL_INJECTION_PATTERNS, XSS_PATTERNS, } from "./security.type.js";
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EACV,oBAAoB,EACpB,sBAAsB,EACtB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,UAAU,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,GACxB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,GACb,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @zudojs/security — Types Barrel
3
+ *
4
+ * Re-exports all security configuration and result types.
5
+ */
6
+ export { PROTOTYPE_POLLUTION_KEYS, SQL_INJECTION_PATTERNS, XSS_PATTERNS, } from "./security.type.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAsBH,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,YAAY,GACb,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,203 @@
1
+ /**
2
+ * @zudojs/security — Core Types
3
+ *
4
+ * Security configuration interfaces and type definitions.
5
+ */
6
+ /** Configuration for header security validation. */
7
+ export interface HeaderSecurityConfig {
8
+ /** Maximum size of a single header value in bytes. */
9
+ readonly maxValueSize?: number;
10
+ /** Maximum number of headers allowed. */
11
+ readonly maxHeaders?: number;
12
+ /** Maximum total size of all headers in bytes. */
13
+ readonly maxTotalSize?: number;
14
+ /** Headers that should be rejected entirely. */
15
+ readonly blockedHeaders?: readonly string[];
16
+ }
17
+ /** Result of header validation. */
18
+ export interface HeaderValidationResult {
19
+ readonly valid: boolean;
20
+ readonly errors: readonly string[];
21
+ }
22
+ /** Configuration for body size limits. */
23
+ export interface BodyLimitConfig {
24
+ /** Maximum body size in bytes. */
25
+ readonly maxSize: number;
26
+ /** Content types that use this limit (if empty, applies to all). */
27
+ readonly contentTypes?: readonly string[];
28
+ }
29
+ /** Preset body limits for common use cases. */
30
+ export interface BodyLimitPresets {
31
+ /** JSON API body limit (default: 1MB). */
32
+ readonly json: number;
33
+ /** Authentication endpoint limit (default: 256KB). */
34
+ readonly auth: number;
35
+ /** File upload limit (default: 100MB). */
36
+ readonly upload: number;
37
+ /** Webhook payload limit (default: 2MB). */
38
+ readonly webhook: number;
39
+ }
40
+ /** Configuration for URL validation. */
41
+ export interface UrlValidationConfig {
42
+ /** Allowed protocols (default: ["http", "https"]). */
43
+ readonly allowedProtocols?: readonly string[];
44
+ /** Maximum URL length in characters. */
45
+ readonly maxLength?: number;
46
+ /** Whether to normalize paths (resolve . and ..). */
47
+ readonly normalizePaths?: boolean;
48
+ /** Whether to block path traversal attempts. */
49
+ readonly blockTraversal?: boolean;
50
+ }
51
+ /** Result of URL validation. */
52
+ export interface UrlValidationResult {
53
+ readonly valid: boolean;
54
+ readonly normalized?: string;
55
+ readonly errors: readonly string[];
56
+ }
57
+ /** Configuration for cookie security. */
58
+ export interface CookieSecurityConfig {
59
+ /** Whether to set Secure flag by default. */
60
+ readonly secure?: boolean;
61
+ /** Whether to set HttpOnly flag by default. */
62
+ readonly httpOnly?: boolean;
63
+ /** Default SameSite policy. */
64
+ readonly sameSite?: "strict" | "lax" | "none";
65
+ /** Maximum cookie size in bytes. */
66
+ readonly maxSize?: number;
67
+ /** Maximum number of cookies. */
68
+ readonly maxCount?: number;
69
+ }
70
+ /** A parsed cookie with security metadata. */
71
+ export interface ParsedCookie {
72
+ readonly name: string;
73
+ readonly value: string;
74
+ readonly secure?: boolean;
75
+ readonly httpOnly?: boolean;
76
+ readonly sameSite?: "strict" | "lax" | "none";
77
+ readonly path?: string;
78
+ readonly domain?: string;
79
+ readonly maxAge?: number;
80
+ readonly expires?: Date;
81
+ readonly partitioned?: boolean;
82
+ }
83
+ /** Configuration for CORS. */
84
+ export interface CorsConfig {
85
+ /** Allowed origins (strings or regex patterns). */
86
+ readonly origin?: string | readonly string[] | RegExp | ((origin: string) => boolean);
87
+ /** Allowed HTTP methods. */
88
+ readonly methods?: readonly string[];
89
+ /** Allowed request headers. */
90
+ readonly allowedHeaders?: readonly string[];
91
+ /** Headers exposed to the browser. */
92
+ readonly exposedHeaders?: readonly string[];
93
+ /** Whether to include credentials. */
94
+ readonly credentials?: boolean;
95
+ /** Max age for preflight cache in seconds. */
96
+ readonly maxAge?: number;
97
+ }
98
+ /** Configuration for CSRF protection. */
99
+ export interface CsrfConfig {
100
+ /** Secret key for token generation. */
101
+ readonly secret: string;
102
+ /** Token expiration in seconds. */
103
+ readonly expiration?: number;
104
+ /** Cookie name for the CSRF token. */
105
+ readonly cookieName?: string;
106
+ /** Header name for the CSRF token. */
107
+ readonly headerName?: string;
108
+ /** Methods that require CSRF protection. */
109
+ readonly methods?: readonly string[];
110
+ }
111
+ /** Configuration for rate limiting. */
112
+ export interface RateLimitConfig {
113
+ /** Maximum requests per window. */
114
+ readonly max: number;
115
+ /** Window duration in milliseconds. */
116
+ readonly windowMs: number;
117
+ /** Key generator function (defaults to IP). */
118
+ readonly keyGenerator?: (request: RateLimitRequest) => string;
119
+ /** Custom handler when rate limit is exceeded. */
120
+ readonly handler?: (request: RateLimitRequest, response: RateLimitResponse) => void;
121
+ /** Skip certain requests. */
122
+ readonly skip?: (request: RateLimitRequest) => boolean;
123
+ /** Message returned when rate limited. */
124
+ readonly message?: string;
125
+ }
126
+ /** Request info for rate limiting. */
127
+ export interface RateLimitRequest {
128
+ readonly ip?: string;
129
+ readonly method?: string;
130
+ readonly path?: string;
131
+ readonly headers?: Record<string, string | string[] | undefined>;
132
+ }
133
+ /** Response info for rate limiting. */
134
+ export interface RateLimitResponse {
135
+ statusCode: number;
136
+ headers: Record<string, string>;
137
+ body?: string;
138
+ }
139
+ /** Result of rate limit check. */
140
+ export interface RateLimitResult {
141
+ readonly allowed: boolean;
142
+ readonly remaining: number;
143
+ readonly resetAt: Date;
144
+ readonly total: number;
145
+ }
146
+ /** Configuration for security headers. */
147
+ export interface SecurityHeadersConfig {
148
+ /** Content-Security-Policy directive. */
149
+ readonly contentSecurityPolicy?: string;
150
+ /** X-Content-Type-Options value (default: "nosniff"). */
151
+ readonly contentTypeOptions?: string;
152
+ /** X-Frame-Options value (default: "DENY"). */
153
+ readonly frameOptions?: string;
154
+ /** X-XSS-Protection value (default: "1; mode=block"). */
155
+ readonly xssProtection?: string;
156
+ /** Strict-Transport-Security value. */
157
+ readonly hsts?: string;
158
+ /** Referrer-Policy value (default: "strict-origin-when-cross-origin"). */
159
+ readonly referrerPolicy?: string;
160
+ /** Permissions-Policy value. */
161
+ readonly permissionsPolicy?: string;
162
+ /** X-DNS-Prefetch-Control value. */
163
+ readonly dnsPrefetchControl?: string;
164
+ /** Cross-Origin-Opener-Policy value. */
165
+ readonly openerPolicy?: string;
166
+ /** Cross-Origin-Resource-Policy value. */
167
+ readonly resourcePolicy?: string;
168
+ }
169
+ /** Configuration for request validation. */
170
+ export interface RequestValidationConfig {
171
+ /** Allowed HTTP methods. */
172
+ readonly allowedMethods?: readonly string[];
173
+ /** Maximum request line size in bytes. */
174
+ readonly maxRequestLineSize?: number;
175
+ /** Allowed hosts (empty = allow all). */
176
+ readonly allowedHosts?: readonly string[];
177
+ /** Whether to validate the Host header. */
178
+ readonly validateHost?: boolean;
179
+ /** Whether to validate Content-Length. */
180
+ readonly validateContentLength?: boolean;
181
+ /** Maximum Content-Length value. */
182
+ readonly maxContentLength?: number;
183
+ }
184
+ /** Configuration for input sanitization. */
185
+ export interface InputSanitizationConfig {
186
+ /** Whether to strip null bytes. */
187
+ readonly stripNullBytes?: boolean;
188
+ /** Whether to normalize Unicode. */
189
+ readonly normalizeUnicode?: boolean;
190
+ /** Maximum string length. */
191
+ readonly maxStringLength?: number;
192
+ /** Whether to prevent prototype pollution. */
193
+ readonly preventPrototypePollution?: boolean;
194
+ /** Custom sanitizer function. */
195
+ readonly customSanitizer?: (value: string) => string;
196
+ }
197
+ /** Keys that indicate prototype pollution attempts. */
198
+ export declare const PROTOTYPE_POLLUTION_KEYS: readonly ["__proto__", "constructor", "prototype"];
199
+ /** Common SQL injection patterns. */
200
+ export declare const SQL_INJECTION_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp];
201
+ /** Common XSS patterns. */
202
+ export declare const XSS_PATTERNS: readonly [RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp, RegExp];
203
+ //# sourceMappingURL=security.type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.type.d.ts","sourceRoot":"","sources":["../../src/types/security.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,oDAAoD;AACpD,MAAM,WAAW,oBAAoB;IACnC,sDAAsD;IACtD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,yCAAyC;IACzC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B,kDAAkD;IAClD,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,gDAAgD;IAChD,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,mCAAmC;AACnC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AAID,0CAA0C;AAC1C,MAAM,WAAW,eAAe;IAC9B,kCAAkC;IAClC,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,oEAAoE;IACpE,QAAQ,CAAC,YAAY,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC3C;AAED,+CAA+C;AAC/C,MAAM,WAAW,gBAAgB;IAC/B,0CAA0C;IAC1C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sDAAsD;IACtD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,0CAA0C;IAC1C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B;AAID,wCAAwC;AACxC,MAAM,WAAW,mBAAmB;IAClC,sDAAsD;IACtD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC9C,wCAAwC;IACxC,QAAQ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9C,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAC7C,iCAAiC;IACjC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;CACtD;AAED,uDAAuD;AACvD,eAAO,MAAM,wBAAwB,YACnC,WAAW,EACX,aAAa,EACb,WAAW,CACH,CAAC;AAEX,qCAAqC;AACrC,eAAO,MAAM,sBAAsB,2CAKzB,CAAC;AAEX,2BAA2B;AAC3B,eAAO,MAAM,YAAY,mFAUf,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @zudojs/security — Core Types
3
+ *
4
+ * Security configuration interfaces and type definitions.
5
+ */
6
+ /** Keys that indicate prototype pollution attempts. */
7
+ export const PROTOTYPE_POLLUTION_KEYS = [
8
+ "__proto__",
9
+ "constructor",
10
+ "prototype",
11
+ ];
12
+ /** Common SQL injection patterns. */
13
+ export const SQL_INJECTION_PATTERNS = [
14
+ /(\b(SELECT|INSERT|UPDATE|DELETE|DROP|CREATE|ALTER|EXEC|EXECUTE|UNION|FETCH|DECLARE|TRUNCATE|COMMENT|ALTER)\b)/i,
15
+ /(--|#|\/\*|\*\/)/,
16
+ /('\s*(OR|AND)\s*')/i,
17
+ /(;\s*(DROP|DELETE|INSERT|UPDATE))/i,
18
+ ];
19
+ /** Common XSS patterns. */
20
+ export const XSS_PATTERNS = [
21
+ /<script\b[^>]*>[\s\S]*?<\/script[^>]*>/gi,
22
+ /<script\b[^>]*>/gi,
23
+ /<\/script[^>]*>/gi,
24
+ /javascript:/gi,
25
+ /on\w+\s*=/gi,
26
+ /data:text\/html/gi,
27
+ /<iframe\b[^>]*>/gi,
28
+ /<object\b[^>]*>/gi,
29
+ /<embed\b[^>]*>/gi,
30
+ ];
31
+ //# sourceMappingURL=security.type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.type.js","sourceRoot":"","sources":["../../src/types/security.type.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0OH,uDAAuD;AACvD,MAAM,CAAC,MAAM,wBAAwB,GAAG;IACtC,WAAW;IACX,aAAa;IACb,WAAW;CACH,CAAC;AAEX,qCAAqC;AACrC,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,gHAAgH;IAChH,kBAAkB;IAClB,qBAAqB;IACrB,oCAAoC;CAC5B,CAAC;AAEX,2BAA2B;AAC3B,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,0CAA0C;IAC1C,mBAAmB;IACnB,mBAAmB;IACnB,eAAe;IACf,aAAa;IACb,mBAAmB;IACnB,mBAAmB;IACnB,mBAAmB;IACnB,kBAAkB;CACV,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @zudojs/security — URL Validation Barrel
3
+ */
4
+ export { validateUrl, normalizePath, validateRequestTarget, isSafeUrl, } from "./url.core.js";
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,SAAS,GACV,MAAM,eAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @zudojs/security — URL Validation Barrel
3
+ */
4
+ export { validateUrl, normalizePath, validateRequestTarget, isSafeUrl, } from "./url.core.js";
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/url/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,WAAW,EACX,aAAa,EACb,qBAAqB,EACrB,SAAS,GACV,MAAM,eAAe,CAAC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * @zudojs/security — URL Validation
3
+ *
4
+ * Validates and normalizes URLs, prevents path traversal attacks,
5
+ * and ensures request targets are safe.
6
+ */
7
+ import type { UrlValidationConfig, UrlValidationResult } from "../types/security.type.js";
8
+ /**
9
+ * Validates a URL against security configuration.
10
+ *
11
+ * @param url - The URL string to validate.
12
+ * @param config - Optional validation configuration.
13
+ * @returns Validation result.
14
+ */
15
+ export declare function validateUrl(url: string, config?: UrlValidationConfig): UrlValidationResult;
16
+ /**
17
+ * Normalizes a URL path by resolving . and .. segments.
18
+ *
19
+ * @param pathname - The path to normalize.
20
+ * @returns The normalized path.
21
+ */
22
+ export declare function normalizePath(pathname: string): string;
23
+ /**
24
+ * Validates a request target (URI path + query).
25
+ *
26
+ * @param target - The request target (e.g., "/users?page=1").
27
+ * @param config - Optional validation configuration.
28
+ * @returns Validation result.
29
+ */
30
+ export declare function validateRequestTarget(target: string, config?: UrlValidationConfig): UrlValidationResult;
31
+ /**
32
+ * Checks if a URL is safe to follow (not pointing to internal resources).
33
+ *
34
+ * @param url - The URL to check.
35
+ * @returns True if the URL appears safe.
36
+ */
37
+ export declare function isSafeUrl(url: string): boolean;
38
+ //# sourceMappingURL=url.core.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url.core.d.ts","sourceRoot":"","sources":["../../src/url/url.core.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,mBAAmB,EACnB,mBAAmB,EACpB,MAAM,2BAA2B,CAAC;AAiCnC;;;;;;GAMG;AACH,wBAAgB,WAAW,CACzB,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE,mBAAmB,GAC3B,mBAAmB,CAwDrB;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,CAmBtD;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,mBAAmB,GAC3B,mBAAmB,CA0CrB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CA0B9C"}