Do not crash on a JWT with a non-base64url signature (fixes #6101) - #6102
Open
chan770 wants to merge 1 commit into
Open
Do not crash on a JWT with a non-base64url signature (fixes #6101)#6102chan770 wants to merge 1 commit into
chan770 wants to merge 1 commit into
Conversation
…ject#6101) JWT_REGEX accepts a signature segment of any length and parseJWT only validates the header/payload, so a value that matches the JWT pattern but carries a malformed/truncated signature (e.g. 41 base64url characters, which is length % 4 == 1 and thus impossible base64) reached crackHMAC. There decodeBase64(signature) let binascii.Error propagate, aborting the whole run with an unhandled exception during checkJWT(). Guard the signature decode: a signature that is not valid base64url cannot be an HMAC we could verify, so crackHMAC now treats it as not crackable (returns None) instead of raising. The other auditJWT findings are unaffected. Added a regression doctest.
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
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 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.
Summary
Fixes #6101 — an unhandled
binascii.Errorthat aborts the whole run when a request value matches the JWT pattern but carries a malformed/truncated signature.Root cause
JWT_REGEXaccepts a signature segment of any length ([A-Za-z0-9_-]*), andparseJWTonly validates that the header and payload decode — it never checks the signature. So a value such aseyJ….eyJ….<41 chars>(41 base64url chars =length % 4 == 1, which is impossible base64) passes as a JWT withalg=HS256and reachescrackHMAC, wheredecodeBase64(signature)letsbinascii.Errorpropagate out throughauditJWT/checkJWT, crashing the scan:Fix
A signature that is not valid base64url cannot be an HMAC we could verify, so
crackHMACnow treats it as not crackable (returnsNone) instead of raising. This is the only place the untrusted signature is decoded; the header/payload decodes already sit insideparseJWT'stry/except. All otherauditJWTfindings (alg-none,no-expiry, etc.) are unaffected.Verification
None.python -m doctest lib/utils/jwt.py→ 10 passed, 0 failed (includes a new regression doctest and the existing real HMAC-crack case).convert.pydoctests → 39 passed, 0 failed.