diff --git a/plugins/passkeys/server/auth/passkeys.test.ts b/plugins/passkeys/server/auth/passkeys.test.ts index 0c9326bcb7..37b1ea80c4 100644 --- a/plugins/passkeys/server/auth/passkeys.test.ts +++ b/plugins/passkeys/server/auth/passkeys.test.ts @@ -358,4 +358,29 @@ describe("#passkeys.verifyAuthentication", () => { "No authentication challenge found or challenge expired" ); }); + + it("should accept boolean extension results sent as form strings", async () => { + const options = await server.post( + "/auth/passkeys.generateAuthenticationOptions", + { body: {} } + ); + const { data } = await options.json(); + const res = await server.post("/auth/passkeys.verifyAuthentication", { + body: { + challengeId: data.challengeId, + id: "unknown", + rawId: "unknown", + response: { + authenticatorData: "", + clientDataJSON: "", + signature: "", + }, + type: "public-key", + clientExtensionResults: { appid: "false", hmacCreateSecret: "true" }, + }, + }); + const body = await res.json(); + expect(res.status).toEqual(400); + expect(body.message).toContain("Passkey not found"); + }); }); diff --git a/plugins/passkeys/server/auth/schema.ts b/plugins/passkeys/server/auth/schema.ts index fe6c103b60..df2c5ed27d 100644 --- a/plugins/passkeys/server/auth/schema.ts +++ b/plugins/passkeys/server/auth/schema.ts @@ -2,6 +2,12 @@ import { z } from "zod"; import { Client } from "@shared/types"; import { BaseSchema } from "@server/routes/api/schema"; +// Form posts send booleans as "true" or "false". +const formBoolean = z.union([ + z.boolean(), + z.stringbool({ truthy: ["true"], falsy: ["false"], case: "sensitive" }), +]); + export const PasskeysGenerateAuthenticationOptionsSchema = BaseSchema.extend({ body: z.object({}), query: z.object({ @@ -29,8 +35,8 @@ export const PasskeysVerifyAuthenticationSchema = BaseSchema.extend({ authenticatorAttachment: z.enum(["cross-platform", "platform"]).optional(), clientExtensionResults: z .object({ - appid: z.boolean().optional(), - hmacCreateSecret: z.boolean().optional(), + appid: formBoolean.optional(), + hmacCreateSecret: formBoolean.optional(), }) .prefault({}), }),