Expired or wrong signature?
See original GitHub issueI need to know exactly why a token failed verification.
Using the jwt.verify
function I don’t know the reason as it might be expired or wrongly signed.
So I have implemented the following workaround:
let validationMessage = "ok";
let isValid = false;
try {
isValid = await jwt.verify(token, SECRET);
if (!isValid) {
if (jwtClaims.exp < Math.floor(Date.now() / 1000)) {
throw new Error('token expired')
}
throw new Error('wrong signature')
}
} catch (error) {
validationMessage = `jwt verify failed: ${error.message}`;
}
I would like to suggest throwing such errors from jwt.verify
and only returning true
in case of success (never return false
).
I could prepare PR but it’s a breaking change, so I’m not sure if you accept it.
Maybe as a separate verify_unsafe
function or add a boolean thow=false
flag to the existing func?
What do you think?
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Digital signatures and certificate expiration dates
When a file is digitally signed and timestamped, the signature will not expire when the certificate expires. The public key accompanying the ...
Read more >What to do if document execution has gone wrong
"Oh no, the correct people have not executed". See 'Back to basics - signing your documents correctly' for a summary of what is...
Read more >Code Signing Certificate Expired? Here's What This Means for ...
Expired code signing certificates are less secure and, thus, much more prone to being compromised by attackers. How easy would it be for...
Read more >Verify the digital signature on a signed email message
If a digital signature isn't valid, there can be many causes. For example, the sender's certificate may have expired, it may have been...
Read more >When would a Authenticode signature expire?
In case of timestamp, the signature will be valid as long as the certificate is valid. Otherwise, it will expire when the certificate...
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 Free
Top 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
https://github.com/tsndr/cloudflare-worker-jwt/tree/v1.2.0
We happy now? 😉
I think, adding an optional flag (false by default) wouldn’t introduce breaking changes and could level up the developer experience for sure.
I can raise a PR if you’re happy with that.