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

Shouldn't verification of additional claims, like iss, aud etc. be enforced when in options? #81

Closed
lwe opened this issue Jun 2, 2015 · 8 comments · Fixed by #82
Closed
Labels

Comments

@lwe
Copy link
Contributor

lwe commented Jun 2, 2015

First of all - thanks for the great gem!

What I've stumbled upon while using the gem is the verification of additional attributes, like e.g. the "iss" claim. When "iss" is supplied to the options in JWT.decode it is not enforced or checked, even when verify_iss is set to true as long as it's not present in the actual payload. Basically I've had the following decoding code:

options = {
  algorithm: 'HS256',
  verify_iss: true,
  'iss' => 'acme.org'
}
payload, = JWT.decode(token, "secret", true, options)

and provided it a token like:

token = JWT.encode({ data: 'payload' }, 'secret', 'HS256')

and expected it to raise an error, because iss is not set in the payload - is this assumption wrong? Should the presence of these attributes be verified again by the application? Looking at jwt.rb#166 the issuer is only verified when it's present in the payload. From my point of view - and I think the more "safe" variant - would be to always trust the options and when "iss" is present in the options then enforcing the check against the issuer.

PS: I'm not savvy with the JWT spec, so it can be that the JWT spec actually proposes the current design. Then just ignore & close my issue :)
PPS: And if this proposal makes sense, I'd be happy to create a PR

@lwe
Copy link
Contributor Author

lwe commented Jun 2, 2015

In the meantime I've checked a few other libraries, noteably:

and they all check the issuer claim when it's present in the options.

@excpt excpt added the bug label Jun 2, 2015
@excpt
Copy link
Member

excpt commented Jun 2, 2015

This is a bug. After inspecting the code, the verification is triggered only when the iss payload is present. See: https://github.com/progrium/ruby-jwt/blob/master/lib/jwt.rb#L166

This affects also all the other verifications.

Thanks for reporting. If you find the time to provide a PR I'd be happy to merge it.

@lwe
Copy link
Contributor Author

lwe commented Jun 2, 2015

All right, I'd propose the following

  1. Setting verify_iss and verify_aud by default to true
  2. Change the conditions to be like if options[:verify_iss] && options["iss"]...

This change then has verification of issuer enabled - as soon as iss option is set, or would you prefer to leave verify_iss to be false by default?

PS: Btw, what is the reasoning behind using "iss" as option and not :iss?

@excpt
Copy link
Member

excpt commented Jun 2, 2015

I agree with your proposal. With these changes it would become more easy to setup the library and check created tokens. But this would break the current api. In this case it would be required to switch to version 2.0. I don't have a problem with this next version step.

The use of 'iss' instead of :iss was a mistake in the code review process. It simply slipped through and now it is in the current version. A fix for this could be this active support library. http://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html But this won't be needed if we make the version 2.0 step. In this case we can change everything to use the hash syntax and drop the ruby 1.8.x support.

@lwe
Copy link
Contributor Author

lwe commented Jun 2, 2015

Then I'd propose the following:

  • Bugfix release 1.5.x, where verify_iss and verify_aud are still set to to false -> will create a PR for this part
  • Breaking changes to be introduced in a 2.0 release, looking at how the current verification works, I think there are a few other areas that could be slightly adapted (similar issues, e.g. there's no way of saying: Hey, I require an exp)

@excpt excpt added this to the Version 2.0.0 milestone Jun 2, 2015
@excpt
Copy link
Member

excpt commented Jun 2, 2015

Sounds excellent. 👍

If you have some ideas for version 2.0 send me a mail.

@excpt
Copy link
Member

excpt commented Jun 2, 2015

I just created a google group. https://groups.google.com/forum/#!forum/ruby-jwt Drop your ideas there. :)

lwe added a commit to lwe/ruby-jwt that referenced this issue Jun 2, 2015
Previously when the following options have been provided

   verify_iss: true, 'iss' => 'acme.org'

and the "iss" claim was missing in the payload - no verification was
executed. The same was true for "aud".

This commit changes the behaviour, so when

   verify_iss: true, 'iss' => 'acme.org'

is set - then the payload is expected to have the "iss" claim and
verification will fail if missing. However, ensure to set `verify_iss`
to `true`, otherwise the verification is not enabled.

This change is backwards compatible, however it might break an app
here or there, because previously the verification did not happen
as expected.

In addition: fixed related test cases and added new ones to ensure
to cover all variants.
@lwe
Copy link
Contributor Author

lwe commented Jun 2, 2015

Created a PR, so I'm closing this.

@lwe lwe closed this as completed Jun 2, 2015
@anakinj anakinj removed this from the Version 3.0.0 milestone Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants