Skip to content

Conversation

@jimmyjames
Copy link
Contributor

Changes

Fixes decodeJWT to decode JWT access tokens:

  • Uses IdTokenVerifier from auth0-php, since Auth0-issued JWTs contain a sub claim and this is used by the Laravel user model.
  • Determines the signature verifier to use via the supported_algs config; defaults to RS256.

Testing

Would like to add additional unit tests, either as a follow-up commit or separate PR. Would be good to use a mock and confirm that the verify API is called with the configured options as we'd expect, but the IdTokenVerifier class is marked as final, so another approach will have to be taken.

Checklist

[X] I have read the Auth0 general contribution guidelines

[X] I have read the Auth0 Code of Conduct

@joshcanhelp
Copy link
Contributor

joshcanhelp commented Apr 21, 2020

@jimmyjames - I have not forgotten about you! I'm working on a fix for the same problem in the SDK (while using a refresh token) and want to see if that change could address this as well. The work here is not lost either way, I think we should examine both approaches to make sure we're doing the right thing here.

Edit: 👇

Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

Once important change and a question ... were you able to pull this down and validate the API quickstart?

}

// Use IdTokenVerifier since Auth0-issued JWTs contain the 'sub' claim, which is used by the Laravel user model
$token_verifier = new IdTokenVerifier(
Copy link
Contributor

Choose a reason for hiding this comment

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

When we were discussing whether to use TokenVerifier or IdTokenVerifier, it didn't occurred to me to look back through the reason why the former even exists in the first place (PHP SDK issue). The problem we'll see with using this is that the azp claim won't appear in the aud array. These are not OIDC JWTs so we should not validate them as such. We have a docs page on validating access tokens which mentions the standard claims (detailed here) and adds aud as well. That was the whole reason behind the existence of TokenVerifier so let's definitely use that here :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the background @joshcanhelp, that makes sense.

I did pull down auth0/auth0-PHP#434, and while it will get past the missing nonce failure if we pass the options ["nonce" => false] when calling decodeIdToken, it will fail on the audience validation as decodeIdToken constructs the token verifier using the clientId instead of the audience.

But given that we should use TokenVerifier instead of IdTokenVerifier for the reasons you listed above, it seems we either still need to do the validation here in laravel-auth0 (but change to use TokenVerifier, or provide another API or configuration point to allow decoding/validating of Auth0-issued JWT access tokens. What do you think the best approach is?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this PR to use TokenVerifier instead of IdTokenVerifier per the discussion above and after discussing with @joshcanhelp

@jimmyjames jimmyjames marked this pull request as ready for review April 22, 2020 16:07
@jimmyjames jimmyjames requested review from a team and joshcanhelp April 22, 2020 16:07
$signature_verifier = new AsymmetricVerifier($jwks);
} else if ('HS256' === $idTokenAlg) {
$signature_verifier = new SymmetricVerifier($this->auth0Config['client_secret']);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

else... alg not supported? if this is not possible at this point, please drop a comment there for the next maintainer / security reviewer

Copy link
Contributor

Choose a reason for hiding this comment

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

This came up in the PHP SDK as well. It does look a bit like null passed to TokenVerifier could be treated as alg:none (which is not the case but still). Same in the PHP SDK:

https://github.com/auth0/auth0-PHP/blob/master/src/Auth0.php#L657

I would throw an InvalidTokenException here.

https://github.com/auth0/auth0-PHP/blob/master/src/Exception/InvalidTokenException.php

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍Pushed another commit that throws an InvalidTokenException when using an unsupported signing algorithm.

Copy link
Contributor

@joshcanhelp joshcanhelp left a comment

Choose a reason for hiding this comment

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

🎉

@joshcanhelp
Copy link
Contributor

❯ composer test
> SHELL_INTERACTIVE=1 "vendor/bin/phpunit" --coverage-text
PHPUnit 8.5.4 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.28 with Xdebug 2.6.0
Configuration: ~/Sites/laravel/auth0-login-dev/laravel-auth0/phpunit.xml.dist

............                                                      12 / 12 (100%)

Time: 1.45 seconds, Memory: 18.00 MB

OK (12 tests, 19 assertions)

@joshcanhelp
Copy link
Contributor

❯ snyk test

Testing ~/Sites/laravel/auth0-login-dev/laravel-auth0...

Organization:      auth0-sdks
Package manager:   composer
Target file:       composer.lock
Project name:      auth0/login
Open source:       no
Project path:      ~/Sites/laravel/auth0-login-dev/laravel-auth0
Licenses:          enabled

✓ Tested 17 dependencies for known issues, no vulnerable paths found.

@joshcanhelp joshcanhelp merged commit acbf6fb into auth0:master Apr 24, 2020
@jimmyjames jimmyjames added this to the 6.0.1 milestone Apr 28, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants