-
Notifications
You must be signed in to change notification settings - Fork 126
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
fix jwt decoded with missing characters in body #91
Conversation
@njl07 thanks for getting involved! |
|
||
var decoded; | ||
try { | ||
decoded = JWT.decode(token); |
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.
JWT2 uses the _asynchronous_ version of JWT.decode
to avoid blocking the V8 event loop.
This try/catch
uses the _synchronous_ (_blocking_) version of JWT.decode
which will introduce a bottle-neck into the authorization process which could easily be exploited by a DOS attacker.
No issue was created for this. I had this problem when I generate a JWT and have it in query parameters and delete some characters in body part. I sent JWT in my server and exception was thrown when plugin tried to decode token. |
is your code somewhere on GitHub so we can help debug it? |
No _asynchronous_ method exists for JWT.decode I've just move your code to surround it with |
I've make a unit test to show the problem |
If you take your code, generate a Are you agree with that? |
I've done test with your code and exception is: stack: SyntaxError: Uncaught error: Unexpected token
Debug: internal, implementation, error
at Object.parse (native)
SyntaxError: Uncaught error: Unexpected token
at Object.jwsDecode [as decode] (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/jsonwebtoken/node_modules/jws/lib/verify-stream.js:71:20)
at Object.JWT.decode (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/jsonwebtoken/index.js:11:21)
at Object.authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi-auth-jwt2/lib/index.js:44:19)
at Object.parse (native)
at Object.jwsDecode [as decode] (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/jsonwebtoken/node_modules/jws/lib/verify-stream.js:71:20)
at Object.JWT.decode (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/jsonwebtoken/index.js:11:21)
at Object.authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi-auth-jwt2/lib/index.js:44:19)
at /Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:227:30
at internals.Protect.run (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/protect.js:56:5)
at authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:218:26)
at internals.Auth._authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:348:5)
at internals.Auth.authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:177:17)
at /Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/request.js:370:13
at /Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:227:30
at internals.Protect.run (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/protect.js:56:5)
at authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:218:26)
at internals.Auth._authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:348:5)
at internals.Auth.authenticate (/Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/auth.js:177:17)
at /Users/njl/Programmation/InTech/WEGA-PROD/wega-manager/node_modules/hapi/lib/request.js:370:13 |
Hello, What's the status of this PR? Do you accept it or are you another issue? I must push in production tomorrow and I would like to know if can trust this library to have no errors when manipulating token in URL. Thanks. |
@njl07 thanks for showing enthusiasm for getting the PR merged. We are in the middle of our day and have our own deadline. I promise to look at it this evening. you will be able to push your code to prod. 👍 |
Given that |
@njl07 from reading the Would you mind plasting the complete stack trace of the Thanks! |
Hello guys, Exception thrown is not by That you show in https://github.com/auth0/node-jsonwebtoken/blob/6a715a13992c888db77cc5b274e5fd28633e4c76/index.js#L198 is not the My PR is a fix of your own code which pass But To fix this issue, I think, the best way is to delete the You don't use After retrieve According that, my PR is not necessary but you must change your code to delete Are you agree with that? Thanks. |
Thanks for your time @njl07 - this is a good catch and something we should fix asap. @nelsonic the issue is that the I think it's reasonable to merge this PR. In related news, we're decoding the JWT twice (once for the key func and again when we verify), even if |
Thanks @alanshaw. Like explain in my last comment, I think it's better to delete It use only in My PR works to fix your code but it's better to optimize code and let |
@njl07, correct me if I'm wrong, but isn't I agree that the extra |
@walling I'm agree with you with the fact that we can be able to select different secret keys for different So |
I vote for merge this now and optimize is separate PR |
Agreed. Merge now to prevent server crash from |
fix jwt decoded with missing characters in body
@njl07 |
Hello,
If someone delete characters in JWT body and send it in an auth route, exception will be thrown by
JWT.decode(token)
method.Perform a
try-catch
around the call to solve the problem.Unit tests are updated and coverage is 100%.
Can you merge ASAP and publish a new version on
npm
if you are agree with that.Thanks.