Skip to content
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

verify error message is sometimes "invalid token" instead of documented "jwt malformed" #768

Closed
jedwards1211 opened this issue Feb 17, 2021 · 2 comments

Comments

@jedwards1211
Copy link
Contributor

Description

I expected verify to throw "jwt malformed" errors when it can't describe the problem more specifically. Instead, it's throwing "invalid token" in the following example:

Reproduction

const { sign, verify } = require('jsonwebtoken')

const secret = `;lkjaslknwineijlk4jlksdf`

const signed = sign({ foo: 'bar' }, secret)
try {
  verify(signed.substring(1), secret)
} catch (error) {
  // JsonWebTokenError: invalid token
  console.error(error)
}

Environment

  • Version of this library used: 8.5.1
  • Version of the platform or framework used, if applicable: Node 12.16.0
@panva
Copy link
Contributor

panva commented Feb 17, 2021

invalid token might just need to be documented.

  • invalid token - when the decoded header cannot be parsed as JSON
  • jwt malformed - the token does not have three components (delimited by a ".")

Ultimately I don't see a problem here. They could be merged into one, sure - in the next major.

Feel free to open a PR adding the invalid token message to the list in the JsonWebTokenError section.

@jedwards1211
Copy link
Contributor Author

jedwards1211 commented Feb 17, 2021

ah I see. "invalid header" or "invalid payload" would be more correct since the entire string is referred to as a token

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants