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

Make algorithm option required to verify signature #184

Merged
merged 1 commit into from
Feb 2, 2017

Conversation

EmilioCristalli
Copy link
Contributor

Looks like this was discussed before in #107, which was closed with a README update specifying the algorithm was required, but it doesn't seem like the code is actually requiring it.

If the algorithm is not provided and the one in the token's header is used
instead, we might be vulnerable to the attack explained here:

https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/

For ex:

A server expecting an RSA signed token would do this:

JWT.decode(token, rsa_public)

So an attacker can potentially sign a token with HS256 using the same RSA public
key (which is publicly available), and the server will think it's valid.

JWT.encode({ user: 1 }, rsa_public, 'HS256')

This doesn't seem to be exploitable right now because the current implementation
of OpenSSL::HMAC.digest expects a string as the key, so if rsa_public is an
OpenSSL::PKey::RSA object, JWT.decode will raise an error. But it would be
better not to depend on this OpenSSL::HMAC.digest behavior

If the algorithm is not provided and the one in the token's header is used
instead, we might be vulnerable to the attack explained here:

https://auth0.com/blog/critical-vulnerabilities-in-json-web-token-libraries/

For ex:

A server expecting an RSA signed token would do this:

`JWT.decode(token, rsa_public)`

So an attacker can potentially sign a token with HS256 using the same RSA public
key (which is publicly available), and the server will think it's valid.

`JWT.encode({ user: 1 }, rsa_public, 'HS256')`

This doesn't seem to be exploitable right now because the current implementation
of OpenSSL::HMAC.digest expects a string as the key, so if rsa_public is an
OpenSSL::PKey::RSA object, JWT.decode will raise an error. But it would be
better not to depend on this OpenSSL::HMAC.digest behavior
@excpt excpt self-requested a review January 17, 2017 16:38
@excpt excpt self-assigned this Jan 17, 2017
@excpt excpt added the bug label Jan 17, 2017
@excpt excpt added this to the Version 1.6.0 milestone Jan 17, 2017
Copy link
Member

@excpt excpt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this security issue. 👍

@excpt excpt merged commit ffceff6 into jwt:master Feb 2, 2017
@EmilioCristalli EmilioCristalli deleted the require-algorithm branch February 4, 2017 22:40
jurriaan added a commit to jurriaan/signet that referenced this pull request Sep 15, 2017
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.
jurriaan added a commit to jurriaan/google-auth-library-ruby that referenced this pull request Sep 15, 2017
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

I've created a PR on signet to. That has to be merged before ruby-jwt
2.0 can be really used (see googleapis/signet#93).

Tested locally against ruby-jwt 2.0 and 1.5.6.
jurriaan added a commit to jurriaan/google-auth-library-ruby that referenced this pull request Sep 15, 2017
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

I've created a PR on signet to. That has to be merged before ruby-jwt
2.0 can be really used (see googleapis/signet#93).

Tested locally against ruby-jwt 2.0 and 1.5.6.
jurriaan added a commit to jurriaan/google-auth-library-ruby that referenced this pull request Sep 15, 2017
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

I've created a PR on signet to. That has to be merged before ruby-jwt
2.0 can be really used (see googleapis/signet#93).

Tested locally against ruby-jwt 2.0 and 1.5.6.
jurriaan added a commit to jurriaan/signet that referenced this pull request Sep 18, 2017
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.
dazuma pushed a commit to googleapis/signet that referenced this pull request Oct 4, 2017
* Support ruby-jwt 2.0

This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

* Use specific version of JRuby to fix CI for now
oleksandrbyk added a commit to oleksandrbyk/olek-google-auth-library that referenced this pull request Mar 4, 2019
This version of ruby-jwt requires specification of the algorithm (see
jwt/ruby-jwt#184) for more information.

I've created a PR on signet to. That has to be merged before ruby-jwt
2.0 can be really used (see googleapis/signet#93).

Tested locally against ruby-jwt 2.0 and 1.5.6.
nhocki added a commit to aha-app/omniauth-jwt that referenced this pull request Mar 22, 2023
Since JWT 2.0 the signature verification checks that the algorithm
passed to `encode` is the same as the `alg` value in the token. If you
support multiple algorithms you can pass an `algorithms: []` option to
the `JWT.decode` call.

This updates the omniauth strategy to allow us passing multiple options
to the `decode` call to support multiple algorithms (and not just
HS256).

* jwt/ruby-jwt#184
pboling pushed a commit to omniauth/omniauth-jwt2 that referenced this pull request Nov 30, 2023
Since JWT 2.0 the signature verification checks that the algorithm
passed to `encode` is the same as the `alg` value in the token. If you
support multiple algorithms you can pass an `algorithms: []` option to
the `JWT.decode` call.

This updates the omniauth strategy to allow us passing multiple options
to the `decode` call to support multiple algorithms (and not just
HS256).

* jwt/ruby-jwt#184
pboling pushed a commit to omniauth/omniauth-jwt2 that referenced this pull request Nov 30, 2023
Since JWT 2.0 the signature verification checks that the algorithm
passed to `encode` is the same as the `alg` value in the token. If you
support multiple algorithms you can pass an `algorithms: []` option to
the `JWT.decode` call.

This updates the omniauth strategy to allow us passing multiple options
to the `decode` call to support multiple algorithms (and not just
HS256).

* jwt/ruby-jwt#184
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 this pull request may close these issues.

2 participants