-
Notifications
You must be signed in to change notification settings - Fork 115
When decoding, if JWT payload is not valid it returns null #24
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
base: master
Are you sure you want to change the base?
Conversation
|
Hey, BTW, there's already a "safe" JSON parse : https://github.com/brianloveswords/node-jws/blob/master/lib/verify-stream.js#L14 I have the same problem so I would really like to see this PR merged. |
b92fca9 to
9fcaf11
Compare
|
Wow, had forgotten about this PR! @hsablonniere thanks for the suggestion, updated the code. Just updated to master in case this could still get in. I know it changes behaviors compared to the old one, but is seems more consistent. Thoughts? |
|
Hey Damian, Long time no see :-) |
| function safeJsonParse(thing, encoding) { | ||
| if (isObject(thing)) | ||
| return thing; | ||
| try { return JSON.parse(thing); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not supported by the JSON.parse API, see comment here: #86 (comment)
Ref: reviver in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO only the if (!payload) { return null; } check should be added by this CR, encoding support is addressed in newer CR #86
|
I also just ran into this due to a security researcher sending malformed JSON in the base64-encoded payload. @shane-tomlinson, please consider merging this 🤗 |
No description provided.