fix(backend): Require configured JWT header type#8471
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 85bfdad The changes in this PR will be included in the next version bump. This PR includes changesets to release 10 packages
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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository YAML (base), Organization UI (inherited) Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughassertHeaderType's signature was changed to make allowedTypes optional and its early-return now occurs only when both typ and allowedTypes are undefined. When allowedTypes is provided, the function computes expectedTypes as allowedTypes ?? 'JWT', normalizes to an array, and validates typ against it, throwing TokenVerificationError for missing or unexpected typ. Tests were updated: assertions.test now checks both the no-throw case when allowedTypes is not configured and the throw case when it is; verifyJwt.test adds a case asserting verification fails with configured headerType. A changeset documents the behavior change. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/dev-cli
@clerk/expo
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
Summary
This changes
verifyJwt/verifyTokenheader type validation so a missing JWTtypheader is only accepted when callers have not configuredheaderType.When callers explicitly pass
headerType, the token must now include atypheader that matches one of the configured values. For example,headerType: 'at+jwt'now rejects a token whose JOSE header omitstyp.Root Cause
assertHeaderTypereturned early whenevertypwasundefined, before it checked the configured allowlist. That meant an explicitheaderTypeoption could be silently skipped for typ-less tokens.The default verifier behavior is preserved for compatibility: if
headerTypeis omitted, a missingtypstill passes.Tests
typwith and without configured allowed types.typwhenheaderType: 'at+jwt'is configured.Validation
NODE_OPTIONS=--no-experimental-webstorage pnpm --filter @clerk/backend buildpnpm --filter @clerk/backend build:runtimeNODE_OPTIONS=--no-experimental-webstorage pnpm exec vitest run src/jwt/__tests__/assertions.test.ts src/jwt/__tests__/verifyJwt.test.ts --environment node --typecheck.enabled=falsepnpm --filter @clerk/backend format:checkgit diff --check