Skip to content

fix(isJWT): reject tokens with an empty header or payload segment - #2875

Open
spokodev wants to merge 1 commit into
validatorjs:masterfrom
spokodev:fix/isjwt-empty-segments
Open

fix(isJWT): reject tokens with an empty header or payload segment#2875
spokodev wants to merge 1 commit into
validatorjs:masterfrom
spokodev:fix/isjwt-empty-segments

Conversation

@spokodev

@spokodev spokodev commented Sep 3, 2026

Copy link
Copy Markdown

isJWT accepts tokens whose header or payload segment is empty, e.g. isJWT('..'), isJWT('.<payload>.<sig>') and isJWT('<header>..<sig>') all return true.

Per RFC 7519 / RFC 7515 the JOSE header (a JSON object that must contain alg) and the payload are base64url encodings of non-empty JSON, so neither can be empty; only the signature may be empty (unsecured JWS, alg: none). The empty segments slip through today because isBase64('') returns true.

This adds a guard requiring the header and payload segments to be non-empty, leaving the empty-signature (<header>.<payload>.) case untouched. Tests added to the existing invalid set.

@codecov

codecov Bot commented Sep 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a79ff98) to head (66622ba).

Additional details and impacted files
@@            Coverage Diff            @@
##            master     #2875   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          114       114           
  Lines         2599      2601    +2     
  Branches       658       659    +1     
=========================================
+ Hits          2599      2601    +2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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