Reject JWT tokens with alg:none to prevent signature bypass#3
Open
emrazik wants to merge 1 commit into
Open
Conversation
The expressJwt middleware and jwt.verify() accepted tokens whose header declared alg:none, which skips signature verification entirely and lets an attacker forge arbitrary claims without knowing the private key. - isAuthorized(): wraps expressJwt in a guard that decodes the token header first and returns 401 if the algorithm is absent or 'none' - updateAuthenticatedUsers(): skips jwt.verify() for alg:none tokens so they are never cached as authenticated sessions Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Finding
NetSPI Finding #1048219779 — JWT Weak Signature Validation | High
The JWT library accepted tokens whose header declared
"alg": "none". When a token has no algorithm, the signature field is ignored and the library treats the payload as trusted without any cryptographic check. An unauthenticated attacker can craft a token with any email address, setalgtonone(or case variants likeNone,nOnE), omit the signature, and be accepted as that user by every protected endpoint.What changed
lib/insecurity.ts—isAuthorized()The function previously returned
expressJwt(...)directly. It now wraps that middleware: before delegating toexpressJwt, it decodes the token header withjws.decode()and returns401immediately if thealgfield is missing or equalsnone(case-insensitive).expressJwtonly receives tokens with a real algorithm.lib/insecurity.ts—updateAuthenticatedUsers()Before calling
jwt.verify()to cache the decoded user, the middleware now checks the token header viajws.decode()and skips verification entirely foralg:nonetokens, so they are never stored as authenticated sessions.Test plan
alg:nonetoken (e.g.header.payload.) toGET /rest/basket/1— expect401alg:nonetokens with a forged admin email are rejected🤖 Generated with Claude Code