From 5e2bb072826d8b5ee77c771990a806f1284067bb Mon Sep 17 00:00:00 2001 From: Kyosuke Konishi Date: Thu, 19 Nov 2026 23:42:34 +0900 Subject: [PATCH 1/2] fix(web-bot-auth): accept the Ed25519 JWK alg --- packages/web-bot-auth/src/crypto.ts | 4 ++-- packages/web-bot-auth/test/index.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/packages/web-bot-auth/src/crypto.ts b/packages/web-bot-auth/src/crypto.ts index b973ede..a62cc7f 100644 --- a/packages/web-bot-auth/src/crypto.ts +++ b/packages/web-bot-auth/src/crypto.ts @@ -19,8 +19,8 @@ async function keyid(jwk: JsonWebKey): Promise { function jwkAlgorithm(jwk: JsonWebKey): WebBotAlgorithm { if (jwk.kty === "OKP" && jwk.crv === "Ed25519") { - if (jwk.alg !== undefined && jwk.alg !== "EdDSA") { - throw new Error("Ed25519 JWK alg must be EdDSA when present"); + if (jwk.alg !== undefined && jwk.alg !== "Ed25519" && jwk.alg !== "EdDSA") { + throw new Error("Ed25519 JWK alg must be Ed25519 or EdDSA when present"); } return "ed25519"; } diff --git a/packages/web-bot-auth/test/index.test.ts b/packages/web-bot-auth/test/index.test.ts index ec458bf..89255f7 100644 --- a/packages/web-bot-auth/test/index.test.ts +++ b/packages/web-bot-auth/test/index.test.ts @@ -476,6 +476,20 @@ describe("verification policy", () => { }); describe("JWK binding", () => { + it.each(["Ed25519", "EdDSA"])("accepts Ed25519 JWK alg %s", async (alg) => { + const jwk = { ...ed25519Jwk, alg }; + const signer = await signerFromJWK(jwk); + const verifier = await verifierFromJWK(jwk); + expect(signer.keyid).toBe((await signerFromJWK(ed25519Jwk)).keyid); + const request = await signedRequest( + new Request("https://example.com"), + signer + ); + await expect( + verify(request, { resolver: () => verifier, now }) + ).resolves.toBeDefined(); + }); + it("rejects conflicting JWK alg", async () => { await expect( signerFromJWK({ ...ed25519Jwk, alg: "PS512" }) From 825ab51e9305fd8385d28d3933d96e7444cbe83f Mon Sep 17 00:00:00 2001 From: Thibault Meunier Date: Wed, 25 Nov 2026 09:42:02 +0100 Subject: [PATCH 2/2] fix(web-bot-auth): normalize Ed25519 JWKs for signer import Validate the original JWK before omitting the explicit Ed25519 label for runtimes that reject it. Exercise signing and verification in workerd. --- examples/verification-workers/test/index.spec.ts | 10 +++++++++- packages/web-bot-auth/src/crypto.ts | 4 +++- packages/web-bot-auth/test/index.test.ts | 14 -------------- 3 files changed, 12 insertions(+), 16 deletions(-) diff --git a/examples/verification-workers/test/index.spec.ts b/examples/verification-workers/test/index.spec.ts index 4186574..8b7c658 100644 --- a/examples/verification-workers/test/index.spec.ts +++ b/examples/verification-workers/test/index.spec.ts @@ -21,7 +21,7 @@ import { } from "cloudflare:test"; import { afterEach, describe, it, expect, vi } from "vitest"; import { sign } from "web-bot-auth"; -import { signerFromJWK } from "web-bot-auth/crypto"; +import { signerFromJWK, verifierFromJWK } from "web-bot-auth/crypto"; import worker from "../src/index"; import jwk from "../../rfc9421-keys/ed25519.json" with { type: "json" }; @@ -75,6 +75,14 @@ afterEach(() => { vi.restoreAllMocks(); }); +it("signs and verifies with Ed25519 JWKs labeled Ed25519", async () => { + const { kty, crv, x } = jwk; + const signer = await signerFromJWK({ ...jwk, alg: "Ed25519" }); + const verifier = await verifierFromJWK({ kty, crv, x, alg: "Ed25519" }); + const data = new TextEncoder().encode("test message"); + expect(await verifier.verify(data, await signer.sign(data))).toBe(true); +}); + describe("/ endpoint", () => { it("responds with HTTP 200", async () => { const request = new IncomingRequest(sampleURL); diff --git a/packages/web-bot-auth/src/crypto.ts b/packages/web-bot-auth/src/crypto.ts index a62cc7f..14d7edb 100644 --- a/packages/web-bot-auth/src/crypto.ts +++ b/packages/web-bot-auth/src/crypto.ts @@ -47,9 +47,11 @@ function publicJwk(jwk: JsonWebKey, algorithm: WebBotAlgorithm): JsonWebKey { export async function signerFromJWK(jwk: JsonWebKey): Promise { const algorithm = jwkAlgorithm(jwk); + // Some Web Crypto runtimes only accept the legacy EdDSA label. + const importJwk = jwk.alg === "Ed25519" ? { ...jwk, alg: undefined } : jwk; const key = await crypto.subtle.importKey( "jwk", - jwk, + importJwk, importAlgorithm(algorithm), false, ["sign"] diff --git a/packages/web-bot-auth/test/index.test.ts b/packages/web-bot-auth/test/index.test.ts index 89255f7..ec458bf 100644 --- a/packages/web-bot-auth/test/index.test.ts +++ b/packages/web-bot-auth/test/index.test.ts @@ -476,20 +476,6 @@ describe("verification policy", () => { }); describe("JWK binding", () => { - it.each(["Ed25519", "EdDSA"])("accepts Ed25519 JWK alg %s", async (alg) => { - const jwk = { ...ed25519Jwk, alg }; - const signer = await signerFromJWK(jwk); - const verifier = await verifierFromJWK(jwk); - expect(signer.keyid).toBe((await signerFromJWK(ed25519Jwk)).keyid); - const request = await signedRequest( - new Request("https://example.com"), - signer - ); - await expect( - verify(request, { resolver: () => verifier, now }) - ).resolves.toBeDefined(); - }); - it("rejects conflicting JWK alg", async () => { await expect( signerFromJWK({ ...ed25519Jwk, alg: "PS512" })