@appwarden/middleware 1.4.2 → 1.5.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/README.md +1 -1
- package/{chunk-JWUAFJ2E.js → chunk-FDIKUQ3E.js} +1 -1
- package/{chunk-47MLTBFC.js → chunk-L6RSRHOF.js} +1 -1
- package/{chunk-NZNMFDZ7.js → chunk-TP5CHUTK.js} +6 -2
- package/cloudflare.d.ts +20 -7
- package/cloudflare.js +27 -8
- package/index.d.ts +1 -1
- package/index.js +2 -2
- package/package.json +1 -1
- package/{use-content-security-policy-C89AROtC.d.ts → use-content-security-policy-Cgy0nz3J.d.ts} +5 -0
- package/vercel.js +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @appwarden/middleware
|
|
2
2
|
|
|
3
|
-

|
|
4
4
|
[](https://www.npmjs.com/package/@appwarden/middleware)
|
|
5
5
|
[](https://docs.npmjs.com/generating-provenance-statements)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
@@ -14,7 +14,7 @@ var debug = (...msg) => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
// src/utils/print-message.ts
|
|
17
|
-
var addSlashes = (str) => str.replace(/
|
|
17
|
+
var addSlashes = (str) => str.replace(/\\/g, "\\\\").replace(/`/g, "\\`").replace(/\$/g, "\\$").replace(/"/g, '\\"').replace(/'/g, "\\'").replace(/\u0000/g, "\\0").replace(/<\/script>/gi, "<\\/script>");
|
|
18
18
|
var printMessage = (message) => `[@appwarden/middleware] ${addSlashes(message)}`;
|
|
19
19
|
|
|
20
20
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
debug,
|
|
3
3
|
printMessage
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-FDIKUQ3E.js";
|
|
5
5
|
|
|
6
6
|
// src/schemas/use-content-security-policy.ts
|
|
7
7
|
import { z as z2 } from "zod";
|
|
@@ -49,6 +49,7 @@ var CSPModeSchema = z2.union([
|
|
|
49
49
|
z2.literal("enforced")
|
|
50
50
|
]).optional().default("disabled");
|
|
51
51
|
var UseCSPInputSchema = z2.object({
|
|
52
|
+
hostname: z2.string().optional(),
|
|
52
53
|
mode: CSPModeSchema,
|
|
53
54
|
directives: CSPDirectivesSchema.optional().refine(
|
|
54
55
|
(val) => {
|
|
@@ -114,6 +115,9 @@ var useContentSecurityPolicy = (input) => {
|
|
|
114
115
|
const config = parsedInput.data;
|
|
115
116
|
return async (context, next) => {
|
|
116
117
|
await next();
|
|
118
|
+
if (config.hostname && context.hostname !== config.hostname) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
117
121
|
const { response } = context;
|
|
118
122
|
if (
|
|
119
123
|
// if the csp is disabled
|
|
@@ -125,7 +129,7 @@ var useContentSecurityPolicy = (input) => {
|
|
|
125
129
|
if (response.headers.has("Content-Type") && !response.headers.get("Content-Type")?.includes("text/html")) {
|
|
126
130
|
return;
|
|
127
131
|
}
|
|
128
|
-
const cspNonce =
|
|
132
|
+
const cspNonce = crypto.randomUUID();
|
|
129
133
|
const [cspHeaderName, cspHeaderValue] = makeCSPHeader(
|
|
130
134
|
cspNonce,
|
|
131
135
|
config.directives,
|
package/cloudflare.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B as Bindings } from './cloudflare-2PkEr25r.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import { M as Middleware } from './use-content-security-policy-
|
|
4
|
-
export { u as useContentSecurityPolicy } from './use-content-security-policy-
|
|
3
|
+
import { M as Middleware } from './use-content-security-policy-Cgy0nz3J.js';
|
|
4
|
+
export { u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
|
|
5
5
|
|
|
6
6
|
declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
|
|
7
7
|
env: CloudflareEnv;
|
|
@@ -11,9 +11,16 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
|
|
|
11
11
|
env: CloudflareEnv;
|
|
12
12
|
cf: Record<string, unknown>;
|
|
13
13
|
ctx: unknown;
|
|
14
|
-
}>], z.ZodUnknown>, z.ZodObject<{
|
|
14
|
+
}>], z.ZodUnknown>, z.ZodEffects<z.ZodObject<{
|
|
15
15
|
debug: z.ZodDefault<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodBoolean]>>, boolean, string | boolean | undefined>>;
|
|
16
|
-
lockPageSlug: z.ZodString
|
|
16
|
+
lockPageSlug: z.ZodOptional<z.ZodString>;
|
|
17
|
+
multidomainConfig: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
18
|
+
lockPageSlug: z.ZodString;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
lockPageSlug: string;
|
|
21
|
+
}, {
|
|
22
|
+
lockPageSlug: string;
|
|
23
|
+
}>>>;
|
|
17
24
|
appwardenApiToken: z.ZodEffects<z.ZodString, string, string>;
|
|
18
25
|
} & {
|
|
19
26
|
middleware: z.ZodDefault<z.ZodObject<{
|
|
@@ -25,19 +32,25 @@ declare const ConfigFnInputSchema: z.ZodFunction<z.ZodTuple<[z.ZodType<{
|
|
|
25
32
|
}>>;
|
|
26
33
|
}, "strip", z.ZodTypeAny, {
|
|
27
34
|
debug: boolean;
|
|
28
|
-
lockPageSlug: string;
|
|
29
35
|
appwardenApiToken: string;
|
|
30
36
|
middleware: {
|
|
31
37
|
before: Middleware[];
|
|
32
38
|
};
|
|
39
|
+
lockPageSlug?: string | undefined;
|
|
40
|
+
multidomainConfig?: Record<string, {
|
|
41
|
+
lockPageSlug: string;
|
|
42
|
+
}> | undefined;
|
|
33
43
|
}, {
|
|
34
|
-
lockPageSlug: string;
|
|
35
44
|
appwardenApiToken: string;
|
|
45
|
+
lockPageSlug?: string | undefined;
|
|
36
46
|
debug?: string | boolean | undefined;
|
|
47
|
+
multidomainConfig?: Record<string, {
|
|
48
|
+
lockPageSlug: string;
|
|
49
|
+
}> | undefined;
|
|
37
50
|
middleware?: {
|
|
38
51
|
before?: Middleware[] | undefined;
|
|
39
52
|
} | undefined;
|
|
40
|
-
}>>;
|
|
53
|
+
}>, any, any>>;
|
|
41
54
|
type CloudflareConfigType = ReturnType<z.infer<typeof ConfigFnInputSchema>>;
|
|
42
55
|
|
|
43
56
|
declare const withAppwarden: (inputFn: CloudflareConfigType) => ExportedHandlerFetchHandler<Bindings>;
|
package/cloudflare.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useContentSecurityPolicy
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-TP5CHUTK.js";
|
|
4
4
|
import {
|
|
5
5
|
BooleanSchema,
|
|
6
6
|
LockValue,
|
|
7
7
|
MemoryCache,
|
|
8
8
|
getErrors
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-L6RSRHOF.js";
|
|
10
10
|
import {
|
|
11
11
|
APPWARDEN_CACHE_KEY,
|
|
12
12
|
APPWARDEN_TEST_ROUTE,
|
|
13
13
|
APPWARDEN_USER_AGENT,
|
|
14
14
|
debug,
|
|
15
15
|
printMessage
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-FDIKUQ3E.js";
|
|
17
17
|
|
|
18
18
|
// src/runners/appwarden-on-cloudflare.ts
|
|
19
19
|
import { ZodError } from "zod";
|
|
@@ -23,17 +23,32 @@ import { z as z2 } from "zod";
|
|
|
23
23
|
|
|
24
24
|
// src/schemas/use-appwarden.ts
|
|
25
25
|
import { z } from "zod";
|
|
26
|
+
var AppwardenMultidomainConfigSchema = z.record(
|
|
27
|
+
z.string(),
|
|
28
|
+
z.object({
|
|
29
|
+
lockPageSlug: z.string()
|
|
30
|
+
})
|
|
31
|
+
);
|
|
26
32
|
var UseAppwardenInputSchema = z.object({
|
|
27
33
|
debug: BooleanSchema.default(false),
|
|
28
|
-
lockPageSlug: z.string(),
|
|
34
|
+
lockPageSlug: z.string().optional(),
|
|
35
|
+
multidomainConfig: AppwardenMultidomainConfigSchema.optional(),
|
|
29
36
|
appwardenApiToken: z.string().refine((val) => !!val, { path: ["appwardenApiToken"] })
|
|
30
37
|
});
|
|
38
|
+
var lockPageSlugRefinement = (schema) => schema.refine(
|
|
39
|
+
(data) => data.lockPageSlug || data.multidomainConfig,
|
|
40
|
+
{
|
|
41
|
+
message: "Either lockPageSlug or multidomainConfig must be provided"
|
|
42
|
+
}
|
|
43
|
+
);
|
|
31
44
|
|
|
32
45
|
// src/schemas/cloudflare.ts
|
|
33
46
|
var ConfigFnInputSchema = z2.function().args(z2.custom()).returns(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
47
|
+
lockPageSlugRefinement(
|
|
48
|
+
UseAppwardenInputSchema.extend({
|
|
49
|
+
middleware: z2.object({ before: z2.custom().array().default([]) }).default({})
|
|
50
|
+
})
|
|
51
|
+
)
|
|
37
52
|
);
|
|
38
53
|
|
|
39
54
|
// src/utils/middleware.ts
|
|
@@ -312,6 +327,10 @@ var useAppwarden = (input) => async (context, next) => {
|
|
|
312
327
|
const isHTMLRequest = response.headers.get("Content-Type")?.includes("text/html");
|
|
313
328
|
const isMonitoringRequest = request.headers.get("User-Agent") === APPWARDEN_USER_AGENT;
|
|
314
329
|
if (isHTMLRequest && !isMonitoringRequest) {
|
|
330
|
+
const lockPageSlug = input.multidomainConfig?.[requestUrl.hostname]?.lockPageSlug ?? input.lockPageSlug;
|
|
331
|
+
if (!lockPageSlug) {
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
315
334
|
const innerContext = {
|
|
316
335
|
keyName,
|
|
317
336
|
request,
|
|
@@ -319,7 +338,7 @@ var useAppwarden = (input) => async (context, next) => {
|
|
|
319
338
|
requestUrl,
|
|
320
339
|
provider,
|
|
321
340
|
debug: input.debug,
|
|
322
|
-
lockPageSlug
|
|
341
|
+
lockPageSlug,
|
|
323
342
|
appwardenApiToken: input.appwardenApiToken,
|
|
324
343
|
waitUntil: (fn) => context.waitUntil(fn)
|
|
325
344
|
};
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { B as Bindings } from './cloudflare-2PkEr25r.js';
|
|
2
|
-
export { C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-
|
|
2
|
+
export { C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-Cgy0nz3J.js';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
declare const LOCKDOWN_TEST_EXPIRY_MS: number;
|
package/index.js
CHANGED
|
@@ -7,12 +7,12 @@ import {
|
|
|
7
7
|
CSPDirectivesSchema,
|
|
8
8
|
CSPModeSchema,
|
|
9
9
|
useContentSecurityPolicy
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-TP5CHUTK.js";
|
|
11
11
|
import {
|
|
12
12
|
APPWARDEN_CACHE_KEY,
|
|
13
13
|
APPWARDEN_USER_AGENT,
|
|
14
14
|
LOCKDOWN_TEST_EXPIRY_MS
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-FDIKUQ3E.js";
|
|
16
16
|
export {
|
|
17
17
|
APPWARDEN_CACHE_KEY,
|
|
18
18
|
APPWARDEN_USER_AGENT,
|
package/package.json
CHANGED
package/{use-content-security-policy-C89AROtC.d.ts → use-content-security-policy-Cgy0nz3J.d.ts}
RENAMED
|
@@ -95,6 +95,7 @@ declare const CSPDirectivesSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
|
95
95
|
}>]>;
|
|
96
96
|
declare const CSPModeSchema: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
|
|
97
97
|
declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
98
|
+
hostname: z.ZodOptional<z.ZodString>;
|
|
98
99
|
mode: z.ZodDefault<z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"disabled">, z.ZodLiteral<"report-only">, z.ZodLiteral<"enforced">]>>>;
|
|
99
100
|
directives: z.ZodEffects<z.ZodEffects<z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
100
101
|
"default-src": z.ZodOptional<z.ZodUnion<[z.ZodArray<z.ZodString, "many">, z.ZodString, z.ZodBoolean]>>;
|
|
@@ -316,6 +317,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
316
317
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
317
318
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
318
319
|
} | undefined;
|
|
320
|
+
hostname?: string | undefined;
|
|
319
321
|
}, {
|
|
320
322
|
mode?: "disabled" | "report-only" | "enforced" | undefined;
|
|
321
323
|
directives?: string | {
|
|
@@ -346,6 +348,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
346
348
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
347
349
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
348
350
|
} | undefined;
|
|
351
|
+
hostname?: string | undefined;
|
|
349
352
|
}>, {
|
|
350
353
|
mode: "disabled" | "report-only" | "enforced";
|
|
351
354
|
directives?: {
|
|
@@ -376,6 +379,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
376
379
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
377
380
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
378
381
|
} | undefined;
|
|
382
|
+
hostname?: string | undefined;
|
|
379
383
|
}, {
|
|
380
384
|
mode?: "disabled" | "report-only" | "enforced" | undefined;
|
|
381
385
|
directives?: string | {
|
|
@@ -406,6 +410,7 @@ declare const UseCSPInputSchema: z.ZodEffects<z.ZodObject<{
|
|
|
406
410
|
"trusted-types"?: string | boolean | string[] | undefined;
|
|
407
411
|
"require-trusted-types-for"?: string | boolean | string[] | undefined;
|
|
408
412
|
} | undefined;
|
|
413
|
+
hostname?: string | undefined;
|
|
409
414
|
}>;
|
|
410
415
|
type UseCSPInput = z.infer<typeof UseCSPInputSchema>;
|
|
411
416
|
|
package/vercel.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
LockValue,
|
|
8
8
|
MemoryCache,
|
|
9
9
|
getErrors
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-L6RSRHOF.js";
|
|
11
11
|
import {
|
|
12
12
|
APPWARDEN_CACHE_KEY,
|
|
13
13
|
APPWARDEN_TEST_ROUTE,
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
errors,
|
|
17
17
|
globalErrors,
|
|
18
18
|
printMessage
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-FDIKUQ3E.js";
|
|
20
20
|
|
|
21
21
|
// src/runners/appwarden-on-vercel.ts
|
|
22
22
|
import { NextResponse } from "next/server";
|