Skip to content

fix(backend): Accept RSA jwtKey of any size (Core 2) - #11108

Merged
nikosdouvlis merged 5 commits into
release/core-2from
nikos/backend-jwt-key-any-size-core-2
Dec 3, 2026
Merged

nikosdouvlis merged 5 commits into
release/core-2from
nikos/backend-jwt-key-any-size-core-2

Conversation

@nikosdouvlis

@nikosdouvlis nikosdouvlis commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Summary

jwtKey / CLERK_JWT_KEY accepts an RSA public key of any size, such as 3072-bit. ES256 support and the JWKS fallback from #11037 are unchanged.

 loadClerkJwkFromPem
   P-256 PEM → EC JWK
-  RSA PEM   → strip a fixed 2048-bit SPKI prefix/suffix to get n, build an RS256 JWK
+  RSA PEM   → PEM string, imported by WebCrypto as SPKI

The prefix strip was a 2021 workaround for Next.js dev mode not parsing PEM keys. importKey has imported PEM strings directly since signJwt landed, so jwtKey now goes through that path too.

Evidence

  • Before: a 3072-bit jwtKey derives the wrong modulus, so every token fails with token-invalid-signature.
    After: verify.test.ts "verifies a 3072-bit RS256 token with a 3072-bit PEM" passes.
  • Two PEMs under the same kid each verify only their own token: "verifies only the token signed by the key of the provided PEM when the kid is the same" passes.
  • A one-line PEM with literal \n or \r\n escapes, a PEM wrapped in double or single quotes, a bare base64 body and a base64url body all verify.
  • A garbage jwtKey still fails with token-invalid-signature, so the dev-mode handshake hint is unchanged.
  • The existing ES256 and JWKS fallback tests pass unedited, with the same error reasons.

Merge Danger

Door: two-way

Blast Radius: verification

  • An RSA jwtKey also verifies RS384 and RS512 tokens signed by the same key, without fetching the JWKS.
  • verifyJwt from @clerk/backend/jwt reports a PEM key that cannot be imported as token-invalid-signature, which is what a jwtKey already gave. Before, a bad PEM string passed to verifyJwt gave token-verification-failed. hasValidSignature now returns false for it instead of throwing.

@vercel

vercel Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
mosaic-docs Error Error Dec 3, 2026 3:22pm UTC
swingset Error Error Dec 3, 2026 3:22pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
clerk-js-sandbox Skipped Skipped Dec 3, 2026 3:22pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 1e54b6a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@clerk/backend Patch
@clerk/agent-toolkit Patch
@clerk/astro Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/remix Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@blacksmith-sh

blacksmith-sh Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Matches 3072- and 4096-bit RSA jwtKey verifies tokens

3072- and 4096-bit RSA jwtKeys failed with token-invalid-signature before and verify on the head. 2048-bit verifies on both.

Merge-base

verifyToken probe

This PR 359f547f

verifyToken probe

Also checked · 3 match

Matches PEM formatting variants of a large RSA key verify
Matches Two PEMs under one kid each verify only their own token
Matches Garbage key, ES256 and RS384 behave as described

Proof on 359f547f · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@pkg-pr-new

pkg-pr-new Bot commented Dec 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/agent-toolkit

npm i https://pkg.pr.new/@clerk/agent-toolkit@11108

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@11108

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@11108

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@11108

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@11108

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@11108

@clerk/elements

npm i https://pkg.pr.new/@clerk/elements@11108

@clerk/clerk-expo

npm i https://pkg.pr.new/@clerk/clerk-expo@11108

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@11108

@clerk/express

npm i https://pkg.pr.new/@clerk/express@11108

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@11108

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@11108

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@11108

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@11108

@clerk/clerk-react

npm i https://pkg.pr.new/@clerk/clerk-react@11108

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@11108

@clerk/remix

npm i https://pkg.pr.new/@clerk/remix@11108

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@11108

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@11108

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@11108

@clerk/themes

npm i https://pkg.pr.new/@clerk/themes@11108

@clerk/types

npm i https://pkg.pr.new/@clerk/types@11108

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@11108

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@11108

commit: 1e54b6a

@nikosdouvlis
nikosdouvlis merged commit d77afaf into release/core-2 Dec 3, 2026
74 of 79 checks passed
@nikosdouvlis
nikosdouvlis deleted the nikos/backend-jwt-key-any-size-core-2 branch December 3, 2026 15:37

This branch had an error being deployed

1 failed and 1 inactive deployments
Preview – swingset — 1e54b6a1 Deployed Dec 3, 2026 by vercel[bot]
Preview – clerk-js-sandbox — 1e54b6a1 Deployed Dec 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant