@neutron-build/security 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/dist/index.d.ts +50 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +250 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tyler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @neutron-build/security
|
|
2
|
+
|
|
3
|
+
Security middleware for Neutron.
|
|
4
|
+
|
|
5
|
+
CSRF protection, rate limiting, input validation, and tenant isolation.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @neutron-build/security
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { csrfMiddleware, rateLimitMiddleware } from "@neutron-build/security";
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Documentation
|
|
20
|
+
|
|
21
|
+
[neutron.build](https://neutron.build)
|
|
22
|
+
|
|
23
|
+
## License
|
|
24
|
+
|
|
25
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { type AppContext, type CookieSerializeOptions, type MiddlewareFn } from "@neutron-build/core";
|
|
2
|
+
export interface CspNonceMiddlewareOptions {
|
|
3
|
+
contextKey?: string;
|
|
4
|
+
headerName?: string;
|
|
5
|
+
policy?: string | ((args: {
|
|
6
|
+
nonce: string;
|
|
7
|
+
request: Request;
|
|
8
|
+
context: AppContext;
|
|
9
|
+
}) => string);
|
|
10
|
+
}
|
|
11
|
+
export interface CsrfMiddlewareOptions {
|
|
12
|
+
cookieName?: string;
|
|
13
|
+
headerName?: string;
|
|
14
|
+
formFieldName?: string;
|
|
15
|
+
safeMethods?: string[];
|
|
16
|
+
cookie?: CookieSerializeOptions;
|
|
17
|
+
contextKey?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface TrustedProxyOptions {
|
|
20
|
+
trustProxy?: boolean;
|
|
21
|
+
forwardedHeader?: string;
|
|
22
|
+
maxForwardedIps?: number;
|
|
23
|
+
/**
|
|
24
|
+
* Number of trusted proxies between this server and the client. The client
|
|
25
|
+
* IP is read this many hops from the right of the forwarded chain, since the
|
|
26
|
+
* left-most entries are attacker-controlled. Default 1.
|
|
27
|
+
*/
|
|
28
|
+
trustedHops?: number;
|
|
29
|
+
}
|
|
30
|
+
export interface RateLimitMiddlewareOptions {
|
|
31
|
+
capacity: number;
|
|
32
|
+
refillPerSecond?: number;
|
|
33
|
+
tokensPerRequest?: number;
|
|
34
|
+
key?: (request: Request, context: AppContext) => string | Promise<string>;
|
|
35
|
+
denyStatus?: number;
|
|
36
|
+
maxBuckets?: number;
|
|
37
|
+
bucketTtlMs?: number;
|
|
38
|
+
cleanupEvery?: number;
|
|
39
|
+
}
|
|
40
|
+
export interface SecureCookieDefaultsOptions extends CookieSerializeOptions {
|
|
41
|
+
nodeEnv?: string;
|
|
42
|
+
}
|
|
43
|
+
export declare function createCspNonceMiddleware(options?: CspNonceMiddlewareOptions): MiddlewareFn;
|
|
44
|
+
export declare function getCspNonceFromContext(context: AppContext, contextKey?: string): string | null;
|
|
45
|
+
export declare function createCsrfMiddleware(options?: CsrfMiddlewareOptions): MiddlewareFn;
|
|
46
|
+
export declare function getCsrfTokenFromContext(context: AppContext, contextKey?: string): string | null;
|
|
47
|
+
export declare function resolveClientIp(request: Request, options?: TrustedProxyOptions): string | null;
|
|
48
|
+
export declare function createRateLimitMiddleware(options: RateLimitMiddlewareOptions): MiddlewareFn;
|
|
49
|
+
export declare function resolveSecureCookieOptions(options?: SecureCookieDefaultsOptions): CookieSerializeOptions;
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,sBAAsB,EAC3B,KAAK,YAAY,EAClB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,yBAAyB;IACxC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EACH,MAAM,GACN,CAAC,CAAC,IAAI,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,OAAO,CAAC;QAAC,OAAO,EAA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gB,uBAAuB,CACrC,OAAO,EAAE,UAAU,EACnB,UAAU,GAAE,MAAiC,GAC5C,MAAM,GAAG,IAAI,CAGf;AAED,wBAAgB,eAAe,CAC7B,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,mBAAwB,GAChC,MAAM,GAAG,IAAI,CAwCf;AAED,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,0BAA0B,GAClC,YAAY,CAgDd;AA+BD,wBAAgB,0BAA0B,CACxC,OAAO,GAAE,2BAAgC,GACxC,sBAAsB,CAYxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { getCookie, serializeCookie, } from "@neutron-build/core";
|
|
3
|
+
const DEFAULT_CSP_CONTEXT_KEY = "cspNonce";
|
|
4
|
+
const DEFAULT_CSRF_CONTEXT_KEY = "csrfToken";
|
|
5
|
+
export function createCspNonceMiddleware(options = {}) {
|
|
6
|
+
const contextKey = options.contextKey || DEFAULT_CSP_CONTEXT_KEY;
|
|
7
|
+
const headerName = options.headerName || "Content-Security-Policy";
|
|
8
|
+
return async (request, context, next) => {
|
|
9
|
+
const nonce = createNonce();
|
|
10
|
+
context[contextKey] = nonce;
|
|
11
|
+
const response = await next();
|
|
12
|
+
if (!response.headers.has(headerName)) {
|
|
13
|
+
response.headers.set(headerName, resolvePolicy(options.policy, { nonce, request, context }));
|
|
14
|
+
}
|
|
15
|
+
return response;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function getCspNonceFromContext(context, contextKey = DEFAULT_CSP_CONTEXT_KEY) {
|
|
19
|
+
const value = context[contextKey];
|
|
20
|
+
return typeof value === "string" ? value : null;
|
|
21
|
+
}
|
|
22
|
+
export function createCsrfMiddleware(options = {}) {
|
|
23
|
+
const cookieName = options.cookieName || "__neutron_csrf";
|
|
24
|
+
const headerName = (options.headerName || "x-csrf-token").toLowerCase();
|
|
25
|
+
const formFieldName = options.formFieldName || "_csrf";
|
|
26
|
+
const safeMethods = new Set((options.safeMethods || ["GET", "HEAD", "OPTIONS"]).map((method) => method.toUpperCase()));
|
|
27
|
+
const contextKey = options.contextKey || DEFAULT_CSRF_CONTEXT_KEY;
|
|
28
|
+
// Secure-by-default double-submit: the token is exposed to the page through
|
|
29
|
+
// context (rendered into forms / a meta tag), so the cookie itself stays
|
|
30
|
+
// HttpOnly and SameSite=Strict. This blocks JS/subdomain cookie reads while
|
|
31
|
+
// the page still has the value it needs to echo back in the header/field.
|
|
32
|
+
const cookieOptions = resolveSecureCookieOptions({
|
|
33
|
+
path: "/",
|
|
34
|
+
sameSite: "Strict",
|
|
35
|
+
httpOnly: true,
|
|
36
|
+
...options.cookie,
|
|
37
|
+
});
|
|
38
|
+
return async (request, context, next) => {
|
|
39
|
+
const method = request.method.toUpperCase();
|
|
40
|
+
const existingToken = getCookie(request, cookieName) || "";
|
|
41
|
+
const csrfToken = existingToken || createNonce();
|
|
42
|
+
context[contextKey] = csrfToken;
|
|
43
|
+
if (!safeMethods.has(method)) {
|
|
44
|
+
if (!isSameOrigin(request)) {
|
|
45
|
+
return new Response("Invalid CSRF origin", { status: 403 });
|
|
46
|
+
}
|
|
47
|
+
// Prefer the header token; only fall back to parsing the (potentially
|
|
48
|
+
// large) form body when no header was supplied.
|
|
49
|
+
const headerToken = request.headers.get(headerName) || "";
|
|
50
|
+
const submittedToken = headerToken || (await readFormToken(request, formFieldName));
|
|
51
|
+
if (!existingToken ||
|
|
52
|
+
!submittedToken ||
|
|
53
|
+
!timingSafeEqualStr(submittedToken, existingToken)) {
|
|
54
|
+
return new Response("Invalid CSRF token", { status: 403 });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
const response = await next();
|
|
58
|
+
if (!existingToken) {
|
|
59
|
+
response.headers.append("Set-Cookie", serializeCookie(cookieName, csrfToken, cookieOptions));
|
|
60
|
+
}
|
|
61
|
+
return response;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export function getCsrfTokenFromContext(context, contextKey = DEFAULT_CSRF_CONTEXT_KEY) {
|
|
65
|
+
const value = context[contextKey];
|
|
66
|
+
return typeof value === "string" ? value : null;
|
|
67
|
+
}
|
|
68
|
+
export function resolveClientIp(request, options = {}) {
|
|
69
|
+
const trustProxy = options.trustProxy ?? false;
|
|
70
|
+
if (!trustProxy) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const maxForwardedIps = Math.max(1, options.maxForwardedIps ?? 5);
|
|
74
|
+
const forwardedHeader = (options.forwardedHeader || "x-forwarded-for").toLowerCase();
|
|
75
|
+
const cfConnectingIp = request.headers.get("cf-connecting-ip");
|
|
76
|
+
if (cfConnectingIp) {
|
|
77
|
+
return cfConnectingIp.trim();
|
|
78
|
+
}
|
|
79
|
+
const xRealIp = request.headers.get("x-real-ip");
|
|
80
|
+
if (xRealIp) {
|
|
81
|
+
return xRealIp.trim();
|
|
82
|
+
}
|
|
83
|
+
const xForwardedFor = request.headers.get(forwardedHeader);
|
|
84
|
+
if (!xForwardedFor || !trustProxy) {
|
|
85
|
+
return null;
|
|
86
|
+
}
|
|
87
|
+
const ips = xForwardedFor
|
|
88
|
+
.split(",")
|
|
89
|
+
.map((value) => value.trim())
|
|
90
|
+
.filter(Boolean)
|
|
91
|
+
.slice(-maxForwardedIps);
|
|
92
|
+
if (ips.length === 0) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
// The left-most entries are supplied by the client and cannot be trusted.
|
|
96
|
+
// Read the entry `trustedHops` from the right — the address observed by the
|
|
97
|
+
// outermost proxy we actually trust.
|
|
98
|
+
const trustedHops = Math.max(1, options.trustedHops ?? 1);
|
|
99
|
+
const index = ips.length - trustedHops;
|
|
100
|
+
return ips[Math.max(0, index)] ?? null;
|
|
101
|
+
}
|
|
102
|
+
export function createRateLimitMiddleware(options) {
|
|
103
|
+
const capacity = Math.max(1, Math.floor(options.capacity));
|
|
104
|
+
const refillPerSecond = Math.max(0.001, options.refillPerSecond ?? capacity);
|
|
105
|
+
const tokensPerRequest = Math.max(1, options.tokensPerRequest ?? 1);
|
|
106
|
+
const denyStatus = options.denyStatus ?? 429;
|
|
107
|
+
const maxBuckets = Math.max(1_000, Math.floor(options.maxBuckets ?? 50_000));
|
|
108
|
+
const bucketTtlMs = Math.max(1_000, Math.floor(options.bucketTtlMs ?? (capacity / refillPerSecond) * 4_000));
|
|
109
|
+
const cleanupEvery = Math.max(1, Math.floor(options.cleanupEvery ?? 128));
|
|
110
|
+
const buckets = new Map();
|
|
111
|
+
let handledRequests = 0;
|
|
112
|
+
return async (request, context, next) => {
|
|
113
|
+
const key = options.key
|
|
114
|
+
? await options.key(request, context)
|
|
115
|
+
: resolveClientIp(request) || "anonymous";
|
|
116
|
+
const now = Date.now();
|
|
117
|
+
handledRequests += 1;
|
|
118
|
+
if (handledRequests % cleanupEvery === 0 || buckets.size > maxBuckets) {
|
|
119
|
+
pruneBuckets(buckets, now, maxBuckets, bucketTtlMs);
|
|
120
|
+
}
|
|
121
|
+
const state = buckets.get(key) || { tokens: capacity, lastRefillMs: now };
|
|
122
|
+
const elapsedSeconds = Math.max(0, (now - state.lastRefillMs) / 1000);
|
|
123
|
+
const replenished = Math.min(capacity, state.tokens + elapsedSeconds * refillPerSecond);
|
|
124
|
+
const remainingAfter = replenished - tokensPerRequest;
|
|
125
|
+
if (remainingAfter < 0) {
|
|
126
|
+
const retryAfterSec = Math.ceil((tokensPerRequest - replenished) / refillPerSecond);
|
|
127
|
+
const denied = new Response("Too Many Requests", { status: denyStatus });
|
|
128
|
+
denied.headers.set("Retry-After", String(Math.max(1, retryAfterSec)));
|
|
129
|
+
denied.headers.set("RateLimit-Limit", String(capacity));
|
|
130
|
+
denied.headers.set("RateLimit-Remaining", "0");
|
|
131
|
+
denied.headers.set("RateLimit-Reset", String(Math.max(1, retryAfterSec)));
|
|
132
|
+
buckets.set(key, { tokens: replenished, lastRefillMs: now });
|
|
133
|
+
return denied;
|
|
134
|
+
}
|
|
135
|
+
buckets.set(key, { tokens: remainingAfter, lastRefillMs: now });
|
|
136
|
+
const response = await next();
|
|
137
|
+
const resetSec = Math.ceil((capacity - remainingAfter) / refillPerSecond);
|
|
138
|
+
response.headers.set("RateLimit-Limit", String(capacity));
|
|
139
|
+
response.headers.set("RateLimit-Remaining", String(Math.floor(remainingAfter)));
|
|
140
|
+
response.headers.set("RateLimit-Reset", String(Math.max(1, resetSec)));
|
|
141
|
+
return response;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function pruneBuckets(buckets, now, maxBuckets, bucketTtlMs) {
|
|
145
|
+
if (buckets.size === 0) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
for (const [key, state] of buckets) {
|
|
149
|
+
if (now - state.lastRefillMs > bucketTtlMs) {
|
|
150
|
+
buckets.delete(key);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (buckets.size <= maxBuckets) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
const overflow = buckets.size - maxBuckets;
|
|
157
|
+
const oldest = Array.from(buckets.entries())
|
|
158
|
+
.sort((left, right) => left[1].lastRefillMs - right[1].lastRefillMs)
|
|
159
|
+
.slice(0, overflow);
|
|
160
|
+
for (const [key] of oldest) {
|
|
161
|
+
buckets.delete(key);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
export function resolveSecureCookieOptions(options = {}) {
|
|
165
|
+
const nodeEnv = options.nodeEnv || process.env.NODE_ENV || "development";
|
|
166
|
+
const isProduction = nodeEnv === "production";
|
|
167
|
+
return {
|
|
168
|
+
path: options.path ?? "/",
|
|
169
|
+
domain: options.domain,
|
|
170
|
+
httpOnly: options.httpOnly ?? true,
|
|
171
|
+
sameSite: options.sameSite ?? "Lax",
|
|
172
|
+
secure: options.secure ?? isProduction,
|
|
173
|
+
expires: options.expires,
|
|
174
|
+
maxAge: options.maxAge,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
function resolvePolicy(policy, args) {
|
|
178
|
+
if (typeof policy === "function") {
|
|
179
|
+
return policy(args);
|
|
180
|
+
}
|
|
181
|
+
if (typeof policy === "string" && policy.trim().length > 0) {
|
|
182
|
+
return policy.replace(/\{\{\s*nonce\s*\}\}/g, args.nonce);
|
|
183
|
+
}
|
|
184
|
+
return [
|
|
185
|
+
"default-src 'self'",
|
|
186
|
+
`script-src 'self' 'nonce-${args.nonce}'`,
|
|
187
|
+
"style-src 'self' 'unsafe-inline'",
|
|
188
|
+
"object-src 'none'",
|
|
189
|
+
"base-uri 'self'",
|
|
190
|
+
"frame-ancestors 'none'",
|
|
191
|
+
].join("; ");
|
|
192
|
+
}
|
|
193
|
+
function timingSafeEqualStr(a, b) {
|
|
194
|
+
const aBuf = Buffer.from(a, "utf8");
|
|
195
|
+
const bBuf = Buffer.from(b, "utf8");
|
|
196
|
+
if (aBuf.length !== bBuf.length) {
|
|
197
|
+
return false;
|
|
198
|
+
}
|
|
199
|
+
return timingSafeEqual(aBuf, bBuf);
|
|
200
|
+
}
|
|
201
|
+
function isSameOrigin(request) {
|
|
202
|
+
const source = request.headers.get("Origin") || request.headers.get("Referer");
|
|
203
|
+
if (!source) {
|
|
204
|
+
return true;
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
return new URL(source).host === new URL(request.url).host;
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
return false;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
async function readFormToken(request, fieldName) {
|
|
214
|
+
const contentType = request.headers.get("content-type") || "";
|
|
215
|
+
if (!contentType.includes("application/x-www-form-urlencoded") &&
|
|
216
|
+
!contentType.includes("multipart/form-data")) {
|
|
217
|
+
return "";
|
|
218
|
+
}
|
|
219
|
+
try {
|
|
220
|
+
const formData = await request.clone().formData();
|
|
221
|
+
const value = formData.get(fieldName);
|
|
222
|
+
return typeof value === "string" ? value : "";
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return "";
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function createNonce() {
|
|
229
|
+
const bytes = new Uint8Array(16);
|
|
230
|
+
crypto.getRandomValues(bytes);
|
|
231
|
+
return toBase64Url(bytes);
|
|
232
|
+
}
|
|
233
|
+
function toBase64Url(bytes) {
|
|
234
|
+
if (typeof Buffer !== "undefined") {
|
|
235
|
+
return Buffer.from(bytes)
|
|
236
|
+
.toString("base64")
|
|
237
|
+
.replace(/\+/g, "-")
|
|
238
|
+
.replace(/\//g, "_")
|
|
239
|
+
.replace(/=+$/g, "");
|
|
240
|
+
}
|
|
241
|
+
let binary = "";
|
|
242
|
+
for (const byte of bytes) {
|
|
243
|
+
binary += String.fromCharCode(byte);
|
|
244
|
+
}
|
|
245
|
+
return btoa(binary)
|
|
246
|
+
.replace(/\+/g, "-")
|
|
247
|
+
.replace(/\//g, "_")
|
|
248
|
+
.replace(/=+$/g, "");
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,EACL,SAAS,EACT,eAAe,GAIhB,MAAM,qBAAqB,CAAC;AA8C7B,MAAM,uBAAuB,GAAG,UAAU,CAAC;AAC3C,MAAM,wBAAwB,GAAG,WAAW,CAAC;AAE7C,MAAM,UAAU,wBAAwB,CACtC,UAAqC,EAAE;IAEvC,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,uBAAuB,CAAC;IACjE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,yBAAyB,CAAC;IAEnE,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE;QACtC,MAAM,KAAK,GAAG,WAAW,EAAE,CAAC;QAC5B,OAAO,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;QAC5B,MAAM,QAAQ,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AU,CAAC,EAAE,CAAC,CAAC;IACjC,MAAM,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;IAC9B,OAAO,WAAW,CAAC,KAAK,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,WAAW,CAAC,KAAiB;IACpC,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC;aACtB,QAAQ,CAAC,QAAQ,CAAC;aAClB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;aACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;aACnB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IACzB,CAAC;IAED,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;IACD,OAAO,IAAI,CAAC,MAAM,CAAC;SAChB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;SACnB,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;AACzB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@neutron-build/security",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Security middleware for Neutron. CSP, CSRF protection, rate limiting, and secure cookie defaults.",
|
|
5
|
+
"author": "Tyler",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://neutron.build",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/neutron-build/neutron",
|
|
11
|
+
"directory": "typescript/packages/neutron-security"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"neutron",
|
|
15
|
+
"security",
|
|
16
|
+
"csp",
|
|
17
|
+
"csrf",
|
|
18
|
+
"rate-limiting",
|
|
19
|
+
"middleware"
|
|
20
|
+
],
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"dist",
|
|
30
|
+
"!dist/**/*.test.*"
|
|
31
|
+
],
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@neutron-build/core": "0.1.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/node": "^22.10.7",
|
|
37
|
+
"typescript": "^5.7.2"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"peerDependencies": {},
|
|
43
|
+
"engines": {
|
|
44
|
+
"node": ">=20"
|
|
45
|
+
},
|
|
46
|
+
"sideEffects": false,
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc",
|
|
49
|
+
"dev": "tsc --watch",
|
|
50
|
+
"lint": "tsc --noEmit --pretty false",
|
|
51
|
+
"test": "pnpm run build && node --test --experimental-test-isolation=none dist/index.test.js"
|
|
52
|
+
}
|
|
53
|
+
}
|