@onderwijsin/nuxt-turnstile 0.2.0 → 0.2.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
3
  "configKey": "turnstile",
4
- "version": "0.2.0",
4
+ "version": "0.2.1",
5
5
  "compatibility": {
6
6
  "nuxt": "^4.0.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -81,7 +81,7 @@ function validateModuleOptions(options, schema, log) {
81
81
  throw new Error("Invalid module options \u261D. Exiting.");
82
82
  }
83
83
 
84
- const version = "0.2.0";
84
+ const version = "0.2.1";
85
85
 
86
86
  const turnstileOptionsSchema = z.object({
87
87
  enabled,
@@ -3,7 +3,12 @@ import { useRuntimeConfig } from "#imports";
3
3
  import { verifyTurnstileToken } from "@nuxtjs/turnstile/runtime/server/utils/verify.js";
4
4
  import { isAdmin } from "module-utils/server";
5
5
  import { attempt } from "module-utils/shared";
6
+ import { z } from "zod";
6
7
  import { TURNSTILE_TOKEN_HEADER } from "../../constants.js";
8
+ const turnstileVerificationSchema = z.object({
9
+ success: z.boolean(),
10
+ action: z.string().optional()
11
+ });
7
12
  export async function assertTurnstileToken(event, expectedAction) {
8
13
  const config = useRuntimeConfig(event);
9
14
  const turnstileConfig = config.turnstile;
@@ -38,7 +43,15 @@ export async function assertTurnstileToken(event, expectedAction) {
38
43
  cause: result.error
39
44
  });
40
45
  }
41
- const verification = result.data;
46
+ const verificationResult = turnstileVerificationSchema.safeParse(result.data);
47
+ if (!verificationResult.success)
48
+ throw createError({
49
+ statusCode: 502,
50
+ statusMessage: "Turnstile validation returned an invalid response",
51
+ data: createTurnstileErrorData("TURNSTILE_VALIDATION_UNAVAILABLE", expectedAction),
52
+ cause: verificationResult.error
53
+ });
54
+ const verification = verificationResult.data;
42
55
  if (!verification.success)
43
56
  throw createTurnstileError(
44
57
  403,
@@ -46,7 +59,7 @@ export async function assertTurnstileToken(event, expectedAction) {
46
59
  "TURNSTILE_VALIDATION_FAILED",
47
60
  expectedAction
48
61
  );
49
- if (verification.action && verification.action !== expectedAction)
62
+ if (verification.action !== expectedAction)
50
63
  throw createTurnstileError(
51
64
  403,
52
65
  "Turnstile action does not match",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onderwijsin/nuxt-turnstile",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Nuxt Turnstile integration with client helpers and server-side validation.",
5
5
  "homepage": "https://github.com/onderwijsin/nuxt-modules#readme",
6
6
  "bugs": {
@@ -54,7 +54,7 @@
54
54
  "scripts": {
55
55
  "build": "nuxt-module-build build",
56
56
  "typecheck": "tsc --noEmit --project tsconfig.json",
57
- "dev": "npm run dev:prepare && nuxt dev playground",
57
+ "dev": "pnpm run dev:prepare && nuxt dev playground",
58
58
  "dev:build": "nuxt build playground",
59
59
  "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxt-module-build build && nuxt prepare playground"
60
60
  }