@appwarden/middleware 3.10.0 → 3.10.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.
package/README.md CHANGED
@@ -112,7 +112,7 @@ import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare"
112
112
 
113
113
  const appwardenHandler = createAppwardenMiddleware((cloudflare) => ({
114
114
  debug: cloudflare.env.DEBUG,
115
- lockPageSlug: cloudflare.env.LOCK_PAGE_SLUG,
115
+ lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
116
116
  appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
117
117
  contentSecurityPolicy: {
118
118
  mode: cloudflare.env.CSP_MODE,
@@ -143,7 +143,7 @@ import { sequence } from "astro:middleware"
143
143
  import { createAppwardenMiddleware } from "@appwarden/middleware/cloudflare/astro"
144
144
 
145
145
  const appwarden = createAppwardenMiddleware((cloudflare) => ({
146
- lockPageSlug: cloudflare.env.LOCK_PAGE_SLUG,
146
+ lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
147
147
  appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
148
148
  debug: cloudflare.env.DEBUG,
149
149
  contentSecurityPolicy: {
@@ -230,7 +230,7 @@ export const config = {
230
230
  }
231
231
 
232
232
  export default createAppwardenMiddleware((cloudflare) => ({
233
- lockPageSlug: cloudflare.env.LOCK_PAGE_SLUG,
233
+ lockPageSlug: cloudflare.env.APPWARDEN_LOCK_PAGE_SLUG,
234
234
  appwardenApiToken: cloudflare.env.APPWARDEN_API_TOKEN,
235
235
  debug: cloudflare.env.DEBUG,
236
236
  // Headers-only CSP (no HTML rewriting, no nonce support; do not use `{{nonce}}` here)
@@ -45,7 +45,31 @@ function isHTMLResponse(response) {
45
45
  return response.headers.get("Content-Type")?.includes("text/html") ?? false;
46
46
  }
47
47
  function isHTMLRequest(request) {
48
- return request.headers.get("accept")?.includes("text/html") ?? false;
48
+ const accept = request.headers.get("accept");
49
+ if (!accept) {
50
+ return false;
51
+ }
52
+ const normalizedAccept = accept.toLowerCase();
53
+ const isWildcardOnlyAccept = (value) => {
54
+ const mediaRanges = value.split(",");
55
+ let hasNonEmptyRange = false;
56
+ for (const range of mediaRanges) {
57
+ const [typeSubtype] = range.split(";");
58
+ const trimmed = typeSubtype.trim();
59
+ if (!trimmed) {
60
+ continue;
61
+ }
62
+ hasNonEmptyRange = true;
63
+ if (trimmed !== "*/*" && trimmed !== "*") {
64
+ return false;
65
+ }
66
+ }
67
+ return hasNonEmptyRange;
68
+ };
69
+ if (isWildcardOnlyAccept(normalizedAccept)) {
70
+ return false;
71
+ }
72
+ return normalizedAccept.includes("text/html");
49
73
  }
50
74
 
51
75
  // src/schemas/use-content-security-policy.ts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  LOCKDOWN_TEST_EXPIRY_MS
3
- } from "./chunk-UIIYORBW.js";
3
+ } from "./chunk-6O25N45F.js";
4
4
  import {
5
5
  printMessage
6
6
  } from "./chunk-QGXPAVOA.js";
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  MemoryCache,
3
3
  debug
4
- } from "./chunk-Z7FIMIZS.js";
4
+ } from "./chunk-HIGZSGKS.js";
5
5
  import {
6
6
  APPWARDEN_CACHE_KEY,
7
7
  APPWARDEN_TEST_ROUTE
8
- } from "./chunk-UIIYORBW.js";
8
+ } from "./chunk-6O25N45F.js";
9
9
  import {
10
10
  deleteEdgeValue,
11
11
  getLockValue,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  UseCSPInputSchema,
3
3
  isHTMLResponse
4
- } from "./chunk-UIIYORBW.js";
4
+ } from "./chunk-6O25N45F.js";
5
5
  import {
6
6
  makeCSPHeader
7
7
  } from "./chunk-QGXPAVOA.js";
@@ -386,7 +386,7 @@ type AstroConfigFn = (runtime: AstroCloudflareRuntime) => AstroCloudflareConfigI
386
386
  * import { createAppwardenMiddleware } from "@appwarden/middleware/astro"
387
387
  *
388
388
  * const appwarden = createAppwardenMiddleware(({ env }) => ({
389
- * lockPageSlug: env.LOCK_PAGE_SLUG,
389
+ * lockPageSlug: env.APPWARDEN_LOCK_PAGE_SLUG,
390
390
  * appwardenApiToken: env.APPWARDEN_API_TOKEN,
391
391
  * }))
392
392
  *
@@ -3,24 +3,24 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  TEMPORARY_REDIRECT_STATUS,
15
15
  buildLockPageUrl,
16
16
  createRedirect,
17
17
  debug,
18
18
  isOnLockPage
19
- } from "../chunk-Z7FIMIZS.js";
19
+ } from "../chunk-HIGZSGKS.js";
20
20
  import {
21
21
  UseCSPInputSchema,
22
22
  isHTMLRequest
23
- } from "../chunk-UIIYORBW.js";
23
+ } from "../chunk-6O25N45F.js";
24
24
  import {
25
25
  AppwardenApiTokenSchema,
26
26
  BooleanSchema,
@@ -454,7 +454,7 @@ type NextJsMiddlewareFunction = (request: NextRequest, event?: NextFetchEvent) =
454
454
  * }
455
455
  *
456
456
  * export default createAppwardenMiddleware(({ env }) => ({
457
- * lockPageSlug: env.LOCK_PAGE_SLUG,
457
+ * lockPageSlug: env.APPWARDEN_LOCK_PAGE_SLUG,
458
458
  * appwardenApiToken: env.APPWARDEN_API_TOKEN,
459
459
  * }))
460
460
  * ```
@@ -3,17 +3,17 @@ import {
3
3
  } from "../chunk-X7WZVYQS.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "../chunk-MYIKUPTR.js";
6
+ } from "../chunk-TASPCREA.js";
7
7
  import {
8
8
  TEMPORARY_REDIRECT_STATUS,
9
9
  buildLockPageUrl,
10
10
  debug,
11
11
  isOnLockPage
12
- } from "../chunk-Z7FIMIZS.js";
12
+ } from "../chunk-HIGZSGKS.js";
13
13
  import {
14
14
  UseCSPInputSchema,
15
15
  isHTMLRequest
16
- } from "../chunk-UIIYORBW.js";
16
+ } from "../chunk-6O25N45F.js";
17
17
  import {
18
18
  AppwardenApiTokenSchema,
19
19
  BooleanSchema,
@@ -381,7 +381,7 @@ type ReactRouterMiddlewareFunction = (args: ReactRouterMiddlewareArgs, next: ()
381
381
  *
382
382
  * export const unstable_middleware = [
383
383
  * createAppwardenMiddleware(() => ({
384
- * lockPageSlug: env.LOCK_PAGE_SLUG,
384
+ * lockPageSlug: env.APPWARDEN_LOCK_PAGE_SLUG,
385
385
  * appwardenApiToken: env.APPWARDEN_API_TOKEN,
386
386
  * })),
387
387
  * ]
@@ -3,23 +3,23 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
17
  isOnLockPage
18
- } from "../chunk-Z7FIMIZS.js";
18
+ } from "../chunk-HIGZSGKS.js";
19
19
  import {
20
20
  UseCSPInputSchema,
21
21
  isHTMLRequest
22
- } from "../chunk-UIIYORBW.js";
22
+ } from "../chunk-6O25N45F.js";
23
23
  import {
24
24
  AppwardenApiTokenSchema,
25
25
  BooleanSchema,
@@ -3,23 +3,23 @@ import {
3
3
  } from "../chunk-XFG6SUSV.js";
4
4
  import {
5
5
  useContentSecurityPolicy
6
- } from "../chunk-VSCXTBP6.js";
6
+ } from "../chunk-ZQNXNGLV.js";
7
7
  import {
8
8
  getNowMs
9
9
  } from "../chunk-X7WZVYQS.js";
10
10
  import {
11
11
  checkLockStatus
12
- } from "../chunk-MYIKUPTR.js";
12
+ } from "../chunk-TASPCREA.js";
13
13
  import {
14
14
  buildLockPageUrl,
15
15
  createRedirect,
16
16
  debug,
17
17
  isOnLockPage
18
- } from "../chunk-Z7FIMIZS.js";
18
+ } from "../chunk-HIGZSGKS.js";
19
19
  import {
20
20
  UseCSPInputSchema,
21
21
  isHTMLRequest
22
- } from "../chunk-UIIYORBW.js";
22
+ } from "../chunk-6O25N45F.js";
23
23
  import {
24
24
  AppwardenApiTokenSchema,
25
25
  BooleanSchema,
package/cloudflare.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { B as Bindings } from './use-content-security-policy-UMl4Biie.js';
2
- export { u as useContentSecurityPolicy } from './use-content-security-policy-UMl4Biie.js';
1
+ import { B as Bindings } from './use-content-security-policy-DpmIa2tk.js';
2
+ export { u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  declare const UseAppwardenInputSchema: z.ZodObject<{
package/cloudflare.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
2
  useContentSecurityPolicy
3
- } from "./chunk-VSCXTBP6.js";
3
+ } from "./chunk-ZQNXNGLV.js";
4
4
  import {
5
5
  checkLockStatus
6
- } from "./chunk-MYIKUPTR.js";
6
+ } from "./chunk-TASPCREA.js";
7
7
  import {
8
8
  buildLockPageUrl,
9
9
  createRedirect,
10
10
  debug,
11
11
  isOnLockPage
12
- } from "./chunk-Z7FIMIZS.js";
12
+ } from "./chunk-HIGZSGKS.js";
13
13
  import {
14
14
  UseCSPInputSchema,
15
15
  isHTMLRequest
16
- } from "./chunk-UIIYORBW.js";
16
+ } from "./chunk-6O25N45F.js";
17
17
  import {
18
18
  AppwardenApiTokenSchema,
19
19
  BooleanSchema,
@@ -123,8 +123,7 @@ var useAppwarden = (input) => async (context, next) => {
123
123
  var useFetchOrigin = () => async (context, next) => {
124
124
  context.response = await fetch(
125
125
  new Request(context.request, {
126
- ...context.request,
127
- redirect: "follow"
126
+ redirect: "manual"
128
127
  })
129
128
  );
130
129
  await next();
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-UMl4Biie.js';
1
+ export { B as Bindings, C as CSPDirectivesSchema, a as CSPModeSchema, M as Middleware, u as useContentSecurityPolicy } from './use-content-security-policy-DpmIa2tk.js';
2
2
  import { z } from 'zod';
3
3
 
4
4
  declare const LOCKDOWN_TEST_EXPIRY_MS: number;
package/index.js CHANGED
@@ -5,13 +5,13 @@ import {
5
5
  } from "./chunk-QEFORWCW.js";
6
6
  import {
7
7
  useContentSecurityPolicy
8
- } from "./chunk-VSCXTBP6.js";
8
+ } from "./chunk-ZQNXNGLV.js";
9
9
  import {
10
10
  APPWARDEN_CACHE_KEY,
11
11
  CSPDirectivesSchema,
12
12
  CSPModeSchema,
13
13
  LOCKDOWN_TEST_EXPIRY_MS
14
- } from "./chunk-UIIYORBW.js";
14
+ } from "./chunk-6O25N45F.js";
15
15
  import "./chunk-QGXPAVOA.js";
16
16
  export {
17
17
  APPWARDEN_CACHE_KEY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appwarden/middleware",
3
- "version": "3.10.0",
3
+ "version": "3.10.1",
4
4
  "description": "Instantly disable all user interaction with your app deployed on Cloudflare or Vercel",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -96,7 +96,7 @@ type ContentSecurityPolicyType = z.infer<typeof ContentSecurityPolicySchema>;
96
96
  */
97
97
  type Bindings = {
98
98
  DEBUG?: string | boolean;
99
- LOCK_PAGE_SLUG?: string;
99
+ APPWARDEN_LOCK_PAGE_SLUG?: string;
100
100
  CSP_MODE?: "disabled" | "report-only" | "enforced";
101
101
  CSP_DIRECTIVES?: string | ContentSecurityPolicyType;
102
102
  APPWARDEN_API_TOKEN?: string;
package/vercel.js CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  buildLockPageUrl,
9
9
  debug,
10
10
  isOnLockPage
11
- } from "./chunk-Z7FIMIZS.js";
11
+ } from "./chunk-HIGZSGKS.js";
12
12
  import {
13
13
  APPWARDEN_CACHE_KEY,
14
14
  CSPDirectivesSchema,
@@ -16,7 +16,7 @@ import {
16
16
  errors,
17
17
  globalErrors,
18
18
  isHTMLRequest
19
- } from "./chunk-UIIYORBW.js";
19
+ } from "./chunk-6O25N45F.js";
20
20
  import {
21
21
  LockValue,
22
22
  getErrors,