question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expired or wrong signature?

See original GitHub issue

I 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:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tsndrcommented, Jun 1, 2022
2reactions
defudefcommented, Apr 25, 2022

I think, adding an optional flag (false by default) wouldn’t introduce breaking changes and could level up the developer experience for sure.

jwt.verify(token, SECRET) // returns boolean. "throwError" flag set as false by default
jwt.verify(token, SECRET, { throwError: true }) // returns true or throws an error (data type still the same)

I can raise a PR if you’re happy with that.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found