You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This changes verifyJwt / verifyToken header type validation so a missing JWT typ header is only accepted when callers have not configured headerType.
When callers explicitly pass headerType, the token must now include a typ header that matches one of the configured values. For example, headerType: 'at+jwt' now rejects a token whose JOSE header omits typ.
Root Cause
assertHeaderType returned early whenever typ was undefined, before it checked the configured allowlist. That meant an explicit headerType option could be silently skipped for typ-less tokens.
The default verifier behavior is preserved for compatibility: if headerType is omitted, a missing typ still passes.
Tests
Added direct assertion coverage for missing typ with and without configured allowed types.
Added verifier coverage for a token without typ when headerType: 'at+jwt' is configured.
Reviewing files that changed from the base of the PR and between ddc3c8d and ab16250.
📒 Files selected for processing (1)
.changeset/tidy-chicken-bathe.md
✅ Files skipped from review due to trivial changes (1)
.changeset/tidy-chicken-bathe.md
📝 Walkthrough
Walkthrough
assertHeaderType'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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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