-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Not possible to verify unsigned token (signed with alg none) #185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The verify method options support algorithms which is an array of supported algs |
Thanks for the suggestion. Unfortunately, using // Third attempt, also causes 'secret or public key must be provided'
jwt.verify(signedToken, null, { algorithms: ['none'] }, ...); |
I had a look at the jwt.verify() implementation and it does not seem to handle unsigned JWTs correctly. This is the snippet of code where the problem occurs: if (parts[2].trim() === '' && secretOrPublicKey){
return done(new JsonWebTokenError('jwt signature is required'));
}
if (!secretOrPublicKey) {
return done(new JsonWebTokenError('secret or public key must be provided'));
} If the token does not have a signature, the method will always return with an error. One way to fix this would be to add an additional condition to the second if statement: if (parts[2].trim() !== '' && !secretOrPublicKey) {
return done(new JsonWebTokenError('secret or public key must be provided'));
} This change allows |
Yes! Sounds like a good plan
|
OK, great. I updated the title to reflect that this is more of a defect than a question. |
Is it possible to verify (as in
jwt.verify()
) a token that was signed with algorithmnone
?I expected the first version to do what I want, which is to realize that the token does not have a signature and therefore doesn't require a signature validation and hence not a key either.
The text was updated successfully, but these errors were encountered: