fix(backend): Require configured JWT header type#8471
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
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 (3)
📝 WalkthroughWalkthroughThe JWT header type validation logic has been modified in the 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. Review rate limit: 4/5 reviews remaining, refill in 12 minutes. Comment |
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