fix(isJWT): reject tokens with non-JSON header or payload#2723
Closed
xxiaoxiong wants to merge 6 commits into
Closed
fix(isJWT): reject tokens with non-JSON header or payload#2723xxiaoxiong wants to merge 6 commits into
xxiaoxiong wants to merge 6 commits into
Conversation
The isJWT function currently only validates that the JWT has three dot-separated segments and that each segment is valid URL-safe base64. However, it does not verify that the decoded header and payload are valid JSON. This allows strings like `foo.bar.dGVzdA` to pass validation even though they are not valid JWTs. This fix decodes the base64-encoded header and payload and checks that they parse as valid JSON before returning true. Fixes #2511
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2723 +/- ##
===========================================
- Coverage 100.00% 99.80% -0.20%
===========================================
Files 114 114
Lines 2587 2605 +18
Branches 656 660 +4
===========================================
+ Hits 2587 2600 +13
- Misses 0 4 +4
- Partials 0 1 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Author
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Description
The
isJWTfunction currently only validates that a string has three dot-separated segments and that each segment is valid URL-safe base64. However, a JWT's header and payload must be valid JSON when decoded.For example:
The string "foo" is valid base64 but is not valid JSON, meaning this is not a real JWT.
Changes
Related Issue
Fixes #2511