@zeruxjs/security 0.0.0-stage → 0.0.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.
- package/LICENSE-APACHE +201 -0
- package/LICENSE-MIT +9 -0
- package/README.md +18 -2
- package/dist/cookies.d.ts +9 -0
- package/dist/cookies.js +37 -0
- package/dist/cookies.js.map +1 -0
- package/dist/core.d.ts +9 -0
- package/dist/core.js +60 -0
- package/dist/core.js.map +1 -0
- package/dist/cors.d.ts +18 -0
- package/dist/cors.js +46 -0
- package/dist/cors.js.map +1 -0
- package/dist/csrf.d.ts +13 -0
- package/dist/csrf.js +55 -0
- package/dist/csrf.js.map +1 -0
- package/dist/headers.d.ts +12 -0
- package/dist/headers.js +23 -0
- package/dist/headers.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/rate-limit.d.ts +18 -0
- package/dist/rate-limit.js +44 -0
- package/dist/rate-limit.js.map +1 -0
- package/package.json +43 -4
package/LICENSE-APACHE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/LICENSE-MIT
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ZeruxJS.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zeruxjs/security
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Framework-independent server security primitives. Use `createSecurityHeaders()` per response; never assume these helpers alone prevent XSS or CSRF. Cookie-authenticated unsafe methods should verify both the origin (when supplied) and a session-bound CSRF token.
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import { createCsrfProtection, evaluateCors, createSecurityHeaders, createRateLimiter, serializeCookie } from '@zeruxjs/security';
|
|
7
|
+
const csrf = createCsrfProtection({ secret: process.env.CSRF_KEY! }); // >=32 bytes
|
|
8
|
+
const token = csrf.issue(sessionId);
|
|
9
|
+
csrf.verify(token, sessionId);
|
|
10
|
+
const cors = evaluateCors(request.headers.origin, { origins: ['https://app.example'], credentials: true });
|
|
11
|
+
const headers = createSecurityHeaders({ hsts: true }, true);
|
|
12
|
+
const limiter = createRateLimiter({ max: 100, windowMs: 60_000 });
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
CORS is not authentication. The limiter is in-memory and not distributed. `ensurePathInsideRoot` is a lexical containment check, not a symlink-safe filesystem authorization check. Configure CSP and origin policy for your application. Secrets must come from a secret manager or protected environment variables.
|
|
16
|
+
|
|
17
|
+
## Release 0.0.2
|
|
18
|
+
|
|
19
|
+
Prepared to validate npm trusted publishing through GitHub Actions.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CookieOptions {
|
|
2
|
+
maxAgeSeconds?: number;
|
|
3
|
+
path?: string;
|
|
4
|
+
domain?: string;
|
|
5
|
+
httpOnly?: boolean;
|
|
6
|
+
secure?: boolean;
|
|
7
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
8
|
+
}
|
|
9
|
+
export declare function serializeCookie(name: string, value: string, options?: CookieOptions): string;
|
package/dist/cookies.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export function serializeCookie(name, value, options = {}) {
|
|
2
|
+
if (!/^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/.test(name))
|
|
3
|
+
throw new Error("Invalid cookie name");
|
|
4
|
+
// eslint-disable-next-line no-control-regex -- Intentionally matches control characters for validation or output sanitization.
|
|
5
|
+
if (/[\u0000-\u001f\u007f;]/.test(value))
|
|
6
|
+
throw new Error("Invalid cookie value");
|
|
7
|
+
if (name.startsWith("__Host-") && (options.secure !== true || options.path !== "/" || options.domain))
|
|
8
|
+
throw new Error("__Host- cookies require Secure, Path=/ and no Domain");
|
|
9
|
+
if (name.startsWith("__Secure-") && !options.secure)
|
|
10
|
+
throw new Error("__Secure- cookies require Secure");
|
|
11
|
+
const sameSite = options.sameSite ?? "Lax";
|
|
12
|
+
if (sameSite === "None" && !options.secure)
|
|
13
|
+
throw new Error("SameSite=None requires Secure");
|
|
14
|
+
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
15
|
+
const path = options.path ?? "/";
|
|
16
|
+
// eslint-disable-next-line no-control-regex -- Intentionally matches control characters for validation or output sanitization.
|
|
17
|
+
if (!path.startsWith("/") || /[\u0000-\u001f\u007f;]/.test(path))
|
|
18
|
+
throw new Error("Invalid cookie path");
|
|
19
|
+
parts.push(`Path=${path}`);
|
|
20
|
+
if (options.domain) {
|
|
21
|
+
if (!/^(?!-)[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/.test(options.domain))
|
|
22
|
+
throw new Error("Invalid cookie domain");
|
|
23
|
+
parts.push(`Domain=${options.domain}`);
|
|
24
|
+
}
|
|
25
|
+
if (options.maxAgeSeconds !== undefined) {
|
|
26
|
+
if (!Number.isSafeInteger(options.maxAgeSeconds) || options.maxAgeSeconds < 0)
|
|
27
|
+
throw new RangeError("Invalid cookie Max-Age");
|
|
28
|
+
parts.push(`Max-Age=${options.maxAgeSeconds}`);
|
|
29
|
+
}
|
|
30
|
+
if (options.secure)
|
|
31
|
+
parts.push("Secure");
|
|
32
|
+
if (options.httpOnly ?? true)
|
|
33
|
+
parts.push("HttpOnly");
|
|
34
|
+
parts.push(`SameSite=${sameSite}`);
|
|
35
|
+
return parts.join("; ");
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookies.js","sourceRoot":"","sources":["../src/cookies.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,KAAa,EAAE,UAAyB,EAAE;IACpF,IAAI,CAAC,+BAA+B,CAAC,IAAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACxF,+HAA+H;IAC/H,IAAI,wBAAwB,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAClF,IAAI,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,KAAK,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,GAAG,IAAI,OAAO,CAAC,MAAM,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC/K,IAAI,IAAI,CAAC,UAAU,CAAC,WAA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IAAI,CAAC,QAAQ,CAAC,CAAC;IACzC,IAAI,OAAO,CAAC,QAAQ,IAAI,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACrD,KAAK,CAAC,IAAI,CAAC,YAAY,QAAQ,EAAE,CAAC,CAAC;IACnC,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC"}
|
package/dist/core.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export declare const createNonce: (size?: number) => string;
|
|
2
|
+
export declare const escapeHtml: (value: unknown) => string;
|
|
3
|
+
export declare const serializeJsonForScript: (value: unknown) => string;
|
|
4
|
+
export declare const sanitizeIdentifier: (value: unknown, fallback?: string) => string;
|
|
5
|
+
export declare const sanitizeRelativeAssetPath: (value: unknown) => string | null;
|
|
6
|
+
export declare const ensurePathInsideRoot: (rootDir: string, targetPath: string) => boolean;
|
|
7
|
+
export declare const buildContentSecurityPolicy: (nonce: string, options?: {
|
|
8
|
+
frameAncestors?: string[];
|
|
9
|
+
}) => string;
|
package/dist/core.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
const unsafePathPattern = /(^|[\\/])\.\.(?:[\\/]|$)/;
|
|
4
|
+
export const createNonce = (size = 16) => {
|
|
5
|
+
if (!Number.isSafeInteger(size) || size < 16 || size > 64)
|
|
6
|
+
throw new RangeError("CSP nonce size must be 16–64 bytes");
|
|
7
|
+
return crypto.randomBytes(size).toString("base64");
|
|
8
|
+
};
|
|
9
|
+
export const escapeHtml = (value) => String(value ?? "")
|
|
10
|
+
.replace(/&/g, "&")
|
|
11
|
+
.replace(/</g, "<")
|
|
12
|
+
.replace(/>/g, ">")
|
|
13
|
+
.replace(/"/g, """)
|
|
14
|
+
.replace(/'/g, "'");
|
|
15
|
+
export const serializeJsonForScript = (value) => JSON.stringify(value ?? {})
|
|
16
|
+
.replace(/</g, "\\u003c")
|
|
17
|
+
.replace(/>/g, "\\u003e")
|
|
18
|
+
.replace(/&/g, "\\u0026")
|
|
19
|
+
.replace(/\u2028/g, "\\u2028")
|
|
20
|
+
.replace(/\u2029/g, "\\u2029");
|
|
21
|
+
export const sanitizeIdentifier = (value, fallback = "item") => {
|
|
22
|
+
const normalized = String(value ?? "")
|
|
23
|
+
.trim()
|
|
24
|
+
.replace(/[^a-zA-Z0-9_-]+/g, "-")
|
|
25
|
+
.replace(/-{2,}/g, "-")
|
|
26
|
+
.replace(/^-+|-+$/g, "");
|
|
27
|
+
return normalized || fallback;
|
|
28
|
+
};
|
|
29
|
+
export const sanitizeRelativeAssetPath = (value) => {
|
|
30
|
+
const target = String(value ?? "").trim();
|
|
31
|
+
if (!target || path.isAbsolute(target) || /^[A-Za-z]:/.test(target) || target.startsWith("\\\\") || target.startsWith("//") || target.includes("\0") || /[?#:]|%(?:2e|2f|5c)/i.test(target) || unsafePathPattern.test(target)) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
return target.replace(/\\/g, "/");
|
|
35
|
+
};
|
|
36
|
+
export const ensurePathInsideRoot = (rootDir, targetPath) => {
|
|
37
|
+
const relative = path.relative(rootDir, targetPath);
|
|
38
|
+
return relative === "" || (relative !== ".." && !relative.startsWith(`..${path.sep}`) && !path.isAbsolute(relative));
|
|
39
|
+
};
|
|
40
|
+
export const buildContentSecurityPolicy = (nonce, options) => {
|
|
41
|
+
if (!/^[A-Za-z0-9+/_=-]{16,256}$/.test(nonce))
|
|
42
|
+
throw new Error("Invalid CSP nonce");
|
|
43
|
+
const frameAncestors = options?.frameAncestors?.length
|
|
44
|
+
? options.frameAncestors.join(" ")
|
|
45
|
+
: "'self'";
|
|
46
|
+
if (options?.frameAncestors?.some(item => !/^(?:'self'|'none'|https:\/\/[A-Za-z0-9.-]+(?::[0-9]{1,5})?)$/.test(item)))
|
|
47
|
+
throw new Error("Invalid frame-ancestors source");
|
|
48
|
+
return [
|
|
49
|
+
"default-src 'self'",
|
|
50
|
+
`script-src 'self' 'nonce-${nonce}'`,
|
|
51
|
+
"style-src 'self' 'unsafe-inline'",
|
|
52
|
+
"img-src 'self' data: https:",
|
|
53
|
+
"font-src 'self' data:",
|
|
54
|
+
"connect-src 'self' ws: wss: http: https:",
|
|
55
|
+
`frame-ancestors ${frameAncestors}`,
|
|
56
|
+
"base-uri 'self'",
|
|
57
|
+
"object-src 'none'"
|
|
58
|
+
].join("; ");
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../src/core.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,iBAAiB,GAAG,0BAA0B,CAAC;AAErD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAI,GAAG,EAAE,EAAE,EAAE;IACrC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE;QAAE,MAAM,IAAI,UAAU,CAAC,oCAAoC,CAAC,CAAC;IACtH,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;AACvD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAc,EAAE,EAAE,CACzC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;KACd,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC;KACtB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;KACrB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;KACrB,OAAO,CAAC,IAAI,EAAE,QAAQ,CAAC;KACvB,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAEhC,MAAM,CAA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
|
2
|
+
origins: readonly string[] | ((origin: string) => boolean);
|
|
3
|
+
methods?: readonly string[];
|
|
4
|
+
headers?: readonly string[];
|
|
5
|
+
exposeHeaders?: readonly string[];
|
|
6
|
+
credentials?: boolean;
|
|
7
|
+
maxAgeSeconds?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CorsResult {
|
|
10
|
+
allowed: boolean;
|
|
11
|
+
status: 200 | 204 | 403;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/** Origin is never reflected without a matching allowlist or explicit predicate. */
|
|
15
|
+
export declare function evaluateCors(origin: string | undefined, options: CorsOptions, preflight?: {
|
|
16
|
+
method: string;
|
|
17
|
+
headers?: string;
|
|
18
|
+
}): CorsResult;
|
package/dist/cors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const httpToken = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
|
|
2
|
+
const list = (values) => {
|
|
3
|
+
if (values.some(v => !httpToken.test(v)))
|
|
4
|
+
throw new Error("Invalid CORS token");
|
|
5
|
+
return values.join(", ");
|
|
6
|
+
};
|
|
7
|
+
/** Origin is never reflected without a matching allowlist or explicit predicate. */
|
|
8
|
+
export function evaluateCors(origin, options, preflight) {
|
|
9
|
+
const headers = { vary: "Origin" };
|
|
10
|
+
if (!origin || origin === "null")
|
|
11
|
+
return { allowed: false, status: 403, headers };
|
|
12
|
+
const allowed = typeof options.origins === "function" ? options.origins(origin) : options.origins.some(item => item === origin);
|
|
13
|
+
if (!allowed)
|
|
14
|
+
return { allowed: false, status: 403, headers };
|
|
15
|
+
try {
|
|
16
|
+
if (new URL(origin).origin !== origin)
|
|
17
|
+
return { allowed: false, status: 403, headers };
|
|
18
|
+
}
|
|
19
|
+
catch {
|
|
20
|
+
return { allowed: false, status: 403, headers };
|
|
21
|
+
}
|
|
22
|
+
const methods = options.methods ?? ["GET", "HEAD", "POST", "PUT", "PATCH", "DELETE"];
|
|
23
|
+
const allowedHeaders = options.headers ?? ["Content-Type", "Authorization", "X-CSRF-Token"];
|
|
24
|
+
if (preflight) {
|
|
25
|
+
if (!httpToken.test(preflight.method) || !methods.includes(preflight.method.toUpperCase()))
|
|
26
|
+
return { allowed: false, status: 403, headers };
|
|
27
|
+
const requested = (preflight.headers ?? "").split(",").map(v => v.trim()).filter(Boolean);
|
|
28
|
+
if (requested.some(v => !httpToken.test(v) || !allowedHeaders.some(h => h.toLowerCase() === v.toLowerCase())))
|
|
29
|
+
return { allowed: false, status: 403, headers };
|
|
30
|
+
headers.vary += ", Access-Control-Request-Method, Access-Control-Request-Headers";
|
|
31
|
+
headers["access-control-allow-methods"] = list(methods);
|
|
32
|
+
headers["access-control-allow-headers"] = list(allowedHeaders);
|
|
33
|
+
if (options.maxAgeSeconds !== undefined) {
|
|
34
|
+
if (!Number.isSafeInteger(options.maxAgeSeconds) || options.maxAgeSeconds < 0 || options.maxAgeSeconds > 86400)
|
|
35
|
+
throw new RangeError("Invalid CORS max age");
|
|
36
|
+
headers["access-control-max-age"] = String(options.maxAgeSeconds);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
headers["access-control-allow-origin"] = origin;
|
|
40
|
+
if (options.credentials)
|
|
41
|
+
headers["access-control-allow-credentials"] = "true";
|
|
42
|
+
if (options.exposeHeaders?.length)
|
|
43
|
+
headers["access-control-expose-headers"] = list(options.exposeHeaders);
|
|
44
|
+
return { allowed: true, status: preflight ? 204 : 200, headers };
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=cors.js.map
|
package/dist/cors.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cors.js","sourceRoot":"","sources":["../src/cors.ts"],"names":[],"mappings":"AASA,MAAM,SAAS,GAAG,+BAA+B,CAAC;AAClD,MAAM,IAAI,GAAG,CAAC,MAAyB,EAAE,EAAE;IACvC,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,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UAAU,CAAC,sBAAsB,CAAC,CAAC;YAC7J,OAAO,CAAC,wBAAwB,CAAC,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;IACD,OAAO,CAAC,6BAA6B,CAAC,GAAG,MAAM,CAAC;IAChD,IAAI,OAAO,CAAC,WAAW;QAAE,OAAO,CAAC,kCAAkC,CAAC,GAAG,MAAM,CAAC;IAC9E,IAAI,OAAO,CAAC,aAAa,EAAE,MAAM;QAAE,OAAO,CAAC,+BAA+B,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;IAC1G,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,CAAC;AACrE,CAAC"}
|
package/dist/csrf.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Double-submit friendly, session-bound signed token. The caller must store the session identifier securely. */
|
|
2
|
+
export interface CsrfOptions {
|
|
3
|
+
secret: string | Buffer;
|
|
4
|
+
ttlSeconds?: number;
|
|
5
|
+
now?: () => number;
|
|
6
|
+
}
|
|
7
|
+
export interface CsrfTokenManager {
|
|
8
|
+
issue(sessionId: string): string;
|
|
9
|
+
verify(token: string | undefined, sessionId: string): boolean;
|
|
10
|
+
}
|
|
11
|
+
export declare function createCsrfProtection(options: CsrfOptions): CsrfTokenManager;
|
|
12
|
+
/** Enforce same-origin checks for unsafe cookie-authenticated requests. */
|
|
13
|
+
export declare function isSameOriginRequest(origin: string | undefined, expectedOrigin: string): boolean;
|
package/dist/csrf.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createHmac, randomBytes, timingSafeEqual } from "node:crypto";
|
|
2
|
+
const encode = (value) => Buffer.from(value).toString("base64url");
|
|
3
|
+
const validSecret = (value) => {
|
|
4
|
+
const buffer = Buffer.isBuffer(value) ? value : Buffer.from(value, "utf8");
|
|
5
|
+
if (buffer.length < 32)
|
|
6
|
+
throw new Error("CSRF secret must contain at least 32 bytes");
|
|
7
|
+
return buffer;
|
|
8
|
+
};
|
|
9
|
+
export function createCsrfProtection(options) {
|
|
10
|
+
const secret = validSecret(options.secret);
|
|
11
|
+
const ttl = options.ttlSeconds ?? 3600;
|
|
12
|
+
if (!Number.isSafeInteger(ttl) || ttl < 1 || ttl > 86400 * 7)
|
|
13
|
+
throw new RangeError("Invalid CSRF lifetime");
|
|
14
|
+
const now = options.now ?? Date.now;
|
|
15
|
+
function signature(payload, sessionId) {
|
|
16
|
+
return createHmac("sha256", secret).update(sessionId).update("\0").update(payload).digest();
|
|
17
|
+
}
|
|
18
|
+
return {
|
|
19
|
+
issue(sessionId) {
|
|
20
|
+
if (!sessionId)
|
|
21
|
+
throw new Error("Session identifier is required");
|
|
22
|
+
const payload = `${Math.floor(now() / 1000)}.${randomBytes(24).toString("base64url")}`;
|
|
23
|
+
return `${encode(payload)}.${signature(payload, sessionId).toString("base64url")}`;
|
|
24
|
+
},
|
|
25
|
+
verify(token, sessionId) {
|
|
26
|
+
if (!sessionId || !token || token.length > 512)
|
|
27
|
+
return false;
|
|
28
|
+
const parts = token.split(".");
|
|
29
|
+
if (parts.length !== 2 || !/^[A-Za-z0-9_-]+$/.test(parts[0]) || !/^[A-Za-z0-9_-]+$/.test(parts[1]))
|
|
30
|
+
return false;
|
|
31
|
+
const payload = Buffer.from(parts[0], "base64url").toString("utf8");
|
|
32
|
+
const [time, nonce, ...extra] = payload.split(".");
|
|
33
|
+
if (extra.length || !/^(0|[1-9][0-9]*)$/.test(time) || !/^[A-Za-z0-9_-]{32}$/.test(nonce))
|
|
34
|
+
return false;
|
|
35
|
+
const issued = Number(time), current = Math.floor(now() / 1000);
|
|
36
|
+
if (!Number.isSafeInteger(issued) || issued > current + 60 || issued + ttl < current)
|
|
37
|
+
return false;
|
|
38
|
+
const actual = Buffer.from(parts[1], "base64url"), expected = signature(payload, sessionId);
|
|
39
|
+
return actual.length === expected.length && timingSafeEqual(actual, expected);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Enforce same-origin checks for unsafe cookie-authenticated requests. */
|
|
44
|
+
export function isSameOriginRequest(origin, expectedOrigin) {
|
|
45
|
+
try {
|
|
46
|
+
if (!origin || origin === "null")
|
|
47
|
+
return false;
|
|
48
|
+
const source = new URL(origin), expected = new URL(expectedOrigin);
|
|
49
|
+
return source.origin === expected.origin && source.username === "" && source.password === "";
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=csrf.js.map
|
package/dist/csrf.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"csrf.js","sourceRoot":"","sources":["../src/csrf.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAQvE,MAAM,MAAM,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC3E,MAAM,WAAW,GAAG,CAAC,KAAsB,EAAU,EAAE;IACnD,MAAM,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3E,IAAI,MAAM,CAAC,MAAM,GAAG,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;IACtF,OAAO,MAAM,CAAC;AAClB,CAAC,CAAC;AACF,MAAM,UAAU,oBAAoB,CAAC,OAAoB;IACrD,MAAM,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,GAAG,GA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GAAG,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;QACnE,OAAO,MAAM,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,IAAI,MAAM,CAAC,QAAQ,KAAK,EAAE,IAAI,MAAM,CAAC,QAAQ,KAAK,EAAE,CAAC;IACjG,CAAC;IAAC,MAAM,CAAC;QAAC,OAAO,KAAK,CAAC;IAAC,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface SecureHeadersOptions {
|
|
2
|
+
hsts?: boolean | {
|
|
3
|
+
maxAgeSeconds: number;
|
|
4
|
+
includeSubDomains?: boolean;
|
|
5
|
+
preload?: boolean;
|
|
6
|
+
};
|
|
7
|
+
csp?: string;
|
|
8
|
+
referrerPolicy?: "no-referrer" | "strict-origin-when-cross-origin" | "same-origin";
|
|
9
|
+
frameOptions?: "DENY" | "SAMEORIGIN";
|
|
10
|
+
}
|
|
11
|
+
/** HTTPS-only HSTS and defense-in-depth browser headers. CSP must be reviewed per application. */
|
|
12
|
+
export declare function createSecurityHeaders(options?: SecureHeadersOptions, https?: boolean): Record<string, string>;
|
package/dist/headers.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** HTTPS-only HSTS and defense-in-depth browser headers. CSP must be reviewed per application. */
|
|
2
|
+
export function createSecurityHeaders(options = {}, https = false) {
|
|
3
|
+
const headers = {
|
|
4
|
+
"x-content-type-options": "nosniff",
|
|
5
|
+
"referrer-policy": options.referrerPolicy ?? "strict-origin-when-cross-origin",
|
|
6
|
+
"x-frame-options": options.frameOptions ?? "DENY",
|
|
7
|
+
"cross-origin-opener-policy": "same-origin",
|
|
8
|
+
"permissions-policy": "camera=(), microphone=(), geolocation=()"
|
|
9
|
+
};
|
|
10
|
+
if (options.csp) {
|
|
11
|
+
if (/[\r\n]/.test(options.csp))
|
|
12
|
+
throw new Error("Invalid CSP");
|
|
13
|
+
headers["content-security-policy"] = options.csp;
|
|
14
|
+
}
|
|
15
|
+
if (https && options.hsts) {
|
|
16
|
+
const config = options.hsts === true ? { maxAgeSeconds: 31536000 } : options.hsts;
|
|
17
|
+
if (!Number.isSafeInteger(config.maxAgeSeconds) || config.maxAgeSeconds < 0 || config.maxAgeSeconds > 63072000)
|
|
18
|
+
throw new RangeError("Invalid HSTS max age");
|
|
19
|
+
headers["strict-transport-security"] = `max-age=${config.maxAgeSeconds}` + ("includeSubDomains" in config && config.includeSubDomains ? "; includeSubDomains" : "") + ("preload" in config && config.preload ? "; preload" : "");
|
|
20
|
+
}
|
|
21
|
+
return headers;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=headers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headers.js","sourceRoot":"","sources":["../src/headers.ts"],"names":[],"mappings":"AAMA,kGAAkG;AAClG,MAAM,UAAU,qBAAqB,CAAC,UAAgC,EAAE,EAAE,KAAK,GAAG,KAAK;IACnF,MAAM,OAAO,GAA2B;QACpC,wBAAwB,EAAE,SAAS;QACnC,iBAAiB,EAAE,OAAO,CAAC,cAAc,IAAI,iCAAiC;QAC9E,iBAAiB,EAAE,OAAO,CAAC,YAAY,IAAI,MAAM;QACjD,4BAA4B,EAAE,aAAa;QAC3C,oBAAoB,EAAE,0CAA0C;KACnE,CAAC;IACF,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QACd,IAAI,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC;YAAE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAC;QAC/D,OAAO,CAAC,yBAAyB,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IACrD,CAAC;IACD,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;QACxB,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;QAClF,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,MAAM,CAAC,aAAa,GAAG,CAAC,IAAI,MAAM,CAAC,aAAa,GAAG,QAAQ;YAAE,MAAM,IAAI,UAAU,CAAC,sBAAsB,CAAC,CAAC;QAC7J,OAAO,CAAC,2BAA2B,CAAC,GAAG,WAAW,MAAM,CAAC,aAAa,EAAE,GAAG,CAAC,mBAAmB,IAAI,MAAM,IAAI,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrO,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/** Public, framework-neutral security helpers. */
|
|
2
|
+
export * from "./core.js";
|
|
3
|
+
export * from "./csrf.js";
|
|
4
|
+
export * from "./cors.js";
|
|
5
|
+
export * from "./headers.js";
|
|
6
|
+
export * from "./rate-limit.js";
|
|
7
|
+
export * from "./cookies.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface RateLimitOptions {
|
|
2
|
+
windowMs: number;
|
|
3
|
+
max: number;
|
|
4
|
+
maxKeys?: number;
|
|
5
|
+
now?: () => number;
|
|
6
|
+
}
|
|
7
|
+
export interface RateLimitResult {
|
|
8
|
+
allowed: boolean;
|
|
9
|
+
remaining: number;
|
|
10
|
+
resetAt: number;
|
|
11
|
+
retryAfterSeconds: number;
|
|
12
|
+
}
|
|
13
|
+
/** Bounded in-process rate limiter. Use a shared store for multiple instances. */
|
|
14
|
+
export declare function createRateLimiter(options: RateLimitOptions): {
|
|
15
|
+
check(key: string, weight?: number): RateLimitResult;
|
|
16
|
+
reset(key?: string): void;
|
|
17
|
+
readonly size: number;
|
|
18
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/** Bounded in-process rate limiter. Use a shared store for multiple instances. */
|
|
2
|
+
export function createRateLimiter(options) {
|
|
3
|
+
if (![options.windowMs, options.max].every(n => Number.isSafeInteger(n) && n > 0))
|
|
4
|
+
throw new RangeError("Invalid limiter settings");
|
|
5
|
+
const cap = options.maxKeys ?? 10000;
|
|
6
|
+
if (!Number.isSafeInteger(cap) || cap < 1)
|
|
7
|
+
throw new RangeError("Invalid maxKeys");
|
|
8
|
+
const now = options.now ?? Date.now;
|
|
9
|
+
const buckets = new Map();
|
|
10
|
+
return {
|
|
11
|
+
check(key, weight = 1) {
|
|
12
|
+
if (!key || key.length > 512 || !Number.isSafeInteger(weight) || weight < 1)
|
|
13
|
+
throw new Error("Invalid rate-limit key or weight");
|
|
14
|
+
const stamp = now();
|
|
15
|
+
let state = buckets.get(key);
|
|
16
|
+
if (state && state.reset <= stamp) {
|
|
17
|
+
buckets.delete(key);
|
|
18
|
+
state = undefined;
|
|
19
|
+
}
|
|
20
|
+
if (!state) {
|
|
21
|
+
if (buckets.size >= cap) {
|
|
22
|
+
for (const [name, item] of buckets) {
|
|
23
|
+
if (item.reset <= stamp)
|
|
24
|
+
buckets.delete(name);
|
|
25
|
+
}
|
|
26
|
+
if (buckets.size >= cap)
|
|
27
|
+
return { allowed: false, remaining: 0, resetAt: stamp + options.windowMs, retryAfterSeconds: Math.ceil(options.windowMs / 1000) };
|
|
28
|
+
}
|
|
29
|
+
state = { count: 0, reset: stamp + options.windowMs };
|
|
30
|
+
buckets.set(key, state);
|
|
31
|
+
}
|
|
32
|
+
const allowed = state.count + weight <= options.max;
|
|
33
|
+
if (allowed)
|
|
34
|
+
state.count += weight;
|
|
35
|
+
return { allowed, remaining: Math.max(0, options.max - state.count), resetAt: state.reset, retryAfterSeconds: allowed ? 0 : Math.ceil((state.reset - stamp) / 1000) };
|
|
36
|
+
},
|
|
37
|
+
reset(key) { if (key)
|
|
38
|
+
buckets.delete(key);
|
|
39
|
+
else
|
|
40
|
+
buckets.clear(); },
|
|
41
|
+
get size() { return buckets.size; }
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.js","sourceRoot":"","sources":["../src/rate-limit.ts"],"names":[],"mappings":"AAEA,kFAAkF;AAClF,MAAM,UAAU,iBAAiB,CAAC,OAAyB;IACvD,IAAI,CAAC,CAAC,OAAO,CAAC,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,0BAA0B,CAAC,CAAC;IACpI,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,IAAI,KAAK,CAAC;IACrC,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC;QAAE,MAAM,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC;IACnF,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC;IACpC,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4C,CAAC;IACpE,OAAO;QACH,KAAK,CAAC,GAAW,EA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MAAM,IAAI,OAAO,CAAC,GAAG,CAAC;YACpD,IAAI,OAAO;gBAAE,KAAK,CAAC,KAAK,IAAI,MAAM,CAAC;YACnC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,KAAK,EAAE,iBAAiB,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,CAAC,EAAE,CAAC;QAC1K,CAAC;QACD,KAAK,CAAC,GAAY,IAAI,IAAI,GAAG;YAAE,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;;YAAM,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC;QAC3E,IAAI,IAAI,KAAK,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC;KACtC,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeruxjs/security",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "A security Plugin to secure application by auto CFSR, XSS and many other attacks, validate schema, escaping, sanitization, CROS, and much more",
|
|
5
|
+
"homepage": "https://github.com/zeruxjs/zeruxjs#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/zeruxjs/zeruxjs/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/zeruxjs/zeruxjs.git"
|
|
12
|
+
},
|
|
13
|
+
"license": "(MIT OR Apache-2.0)",
|
|
14
|
+
"type": "module",
|
|
15
|
+
"main": "./dist/index.js",
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"test": "npm run build && node --test test/*.test.cjs",
|
|
21
|
+
"prepack": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
".": {
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"import": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"A security Plugin to secure application by auto CFSR, XSS and many other attacks, validate schema, escaping, sanitization, CROS, and much more"
|
|
31
|
+
],
|
|
32
|
+
"files": [
|
|
33
|
+
"dist/",
|
|
34
|
+
"README.md",
|
|
35
|
+
"LICENSE-MIT",
|
|
36
|
+
"LICENSE-APACHE"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"typescript": "^5.9.3",
|
|
43
|
+
"@types/node": "^25.4.0"
|
|
44
|
+
}
|
|
45
|
+
}
|