-
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
added parameter to irgnore url token #146
Conversation
Current coverage is
|
@bitcloud Thanks for this contribution! Thanks again 😊 |
I think this is still in the suggestion phase. Didn't know that there is a process ;-) |
var auth; | ||
|
||
if(request.query[urlKey]) { // tokens via url: https://github.com/dwyl/hapi-auth-jwt2/issues/19 | ||
if(allowUrlToken && request.query[urlKey]) { // tokens via url: https://github.com/dwyl/hapi-auth-jwt2/issues/19 |
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.
What about when allowUrlToken
has a falsy value and request.query[urlKey]
a truthly one ? If this case is not possible, please add a comment to state that.
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.
That was the whole idea to be able to turn the url key off. And I wanted it to default to true, so that it's not a breaking change. Another way would probably be to set the urlKey explicit to false.
@bitcloud there is already an easy way of achieving this result. server.auth.strategy('jwt', 'jwt',{
key: 'YourJWTSecret',
validateFunc: validate, // your validate function
urlKey: require('crypto').randomBytes(256).toString('base64'), // the NSA cannot crack this!
verifyOptions: { algorithms: [ 'HS256' ] }
});
} Try running the following command in your terminal: node -e "console.log(require('crypto').randomBytes(256).toString('base64'));" It would take all the computing power in the world the rest of time, to crack that key.
The person trying to "hack" your Hapi website/app would literally be better off |
seriously? So you suggest to request another lib to generate enough noise so that the key couldn't be guessed?!? I would have accepted something like setting it to an empty string because this is kind of achieve the same result, but this is really bad. In my opinion it should be the default behaviour that urlKeys are not allowed, because this just adds an unnecessary attack vector. But its your call. |
ok, I just checked it with an empty string. It is really possible to pass a query string with no parameter name ... but still. Setting it to boolean false and check on that would be better (as I mentioned in the inline comment). |
My 2¢ is that it would be much nicer to simply have a feature to disable accepting the token from the URL. The workaround is easy enough but results in more complicated source for projects using this module. |
@wprl your @bitcloud is _totally right_ setting the We could/should add that to the Docs so others know how to disable tokens via URL. Also, @bitcloud I don't understand how allowing JWTs via the URL creates an _attack vector_ any more than accepting JWTs in the We could set |
@nelsonic concerning the security, it is perhaps a little bit constructed but: The whole reason I introduced the additional parameter was because of not having a breaking change ;-) |
Yeah, that does make an assumption that you are able to intercept a valid JWT. A much easier way of the JWT leaking is if your server sends an email (containing a url with a valid JWT token e.g. "Click link to verify your account") to an inbox on an un-encrypted email service provider ... but this is no longer the security "fault" of JWTs but of the email service provider ... 💔 I really like your empty string solution to blocking JWTs in URLs. 👍 |
And the users for using an unencrypted service. ;-) The server doesn't even need to be firewalled, it is sufficient if the client IP is encoded in the JWT token for his session. And I think the biggest part of leaking a session is probably stupid and simple "look at that" copy&pasting URL's in a chat. But thats the reason why JWT shouldn't be used in URLs anyway besides that they are logged to the server.log as well... It all boils down to "you should know what you do" and If someone whats to use JWT in an unsecure whey - well he can and there is nothing we can do about it :-/ Ok, back to topic now ... I could try to update my pull request in the next days to the empty string solution. Is mostly docs and testcases anyway. Probably even allow a boolean false to make it more explicit. At least a false shouldn't default to 'token' ;-) |
Good plan. yes, please do update the PR. 👍 |
hmm, I updated the branch, but it doesn't appear here. Probably because you already closed it. Do you want to reopen it? |
@bitcloud re-opened. 👍 |
From a systems hardening perspective, any feature is part of the attack surface, because it is another "moving part" that could be broken in some unforeseen way to gain unauthorized access to a system. It's a paranoid way of thinking, but also effective :) Glad to see this getting some polish. Really happy with how easy this plugin is to drop in place! |
# Conflicts: # README.md # lib/extract.js
ok, finally some time to resolve the conflicts ;-) |
@bitcloud looks good. will merge and publish to NPM when back desk. thanks! 👍 |
Merging. |
damn it, I missed something in the docs. There is still your example of setting it to 'something impossible to guess'. Probably you can clean that up on the next readme update? I don't know if I can update the pull request anymore now :) |
Ah, I did not spot it either... ok. lets fix that on the next PR. 👍 |
added allowUrlToken to be able to disable the URL Token for security reasons. defaults to true, to avoid breaking change.