Bug: Can't use multiple secrets with different algorithms
See original GitHub issueDescription
Using a function with the secret
option to express-jwt, I can provide different secrets for different requests.
These secrets might require different algorithms to verify, e.g. HS256 and RS256.
This doesn’t work as expected: After one token has been verified by a middleware, only tokens with the same algorithm can be verified by that middleware. Verification of tokens with different algorithms fails with UnauthorizedError: invalid algorithm
. See https://gist.github.com/bspot/319dd8c5458d24955842b400bd90b634 for a test case.
Reason
- The
options
argument to express-jwt is passed tojwt.verify
on every request. (https://github.com/auth0/express-jwt/blob/master/lib/index.js#L99) - As long as
options.algorithms
is empty, jsonwebtoken fills it with the list of applicable algorithms. (https://github.com/auth0/node-jsonwebtoken/blob/v6.2.0/index.js#L89) - On subsequent requests,
options.algorithms
is filled and jsonwebtoken refuses to use any other algorithm.
Workaround
Keep a reference to the options
passed to express-jwt and
delete options.algorithms;
before each request. This can be done in the function passed as the secret
.
Potential fix
- Either
delete options.algorithms;
in the express-jwt middleware on every request, or - pass
Object.assign({}, options)
tojwt.verify
.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (4 by maintainers)
Top Results From Across the Web
The problems with secret algorithms in vulnerability ...
Many vulnerability prioritisation platforms use secret algorithms but a lack of transparency in ranking is risky. Here's why.
Read more >Bug Attacks | SpringerLink
Section 4 presents attacks on several cryptosystems when exponentiations are computed using the LTOR algorithm, and Sect.
Read more >Never Assuming That Your Secrets Are Safe - US-CERT - CISA
Top-secret algorithms need to be protected from competitors. These kinds of requirements are almost always high on the list, but turn out to ......
Read more >Critical vulnerabilities in JSON Web Token libraries - Auth0
Anyone using a JWT implementation should make sure that tokens with a different signature type are guaranteed to be rejected. Some libraries ...
Read more >Resolve Secrets Manager secret access errors after updating ...
"You can't access a secret from a different AWS account if you encrypt ... or "An unknown error occurred"; "Access to KMS is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Updated jsonwebtoken in
v5.3.0
A workaround that worked for us is to create a new options object to pass to the JWT middleware on each request