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

Add id_token validation (HS256 and RS256) #295

Merged
merged 10 commits into from
Sep 28, 2018
Merged

Conversation

luisrudge
Copy link
Contributor

@luisrudge luisrudge commented Aug 22, 2018

This PR adds id_token validation for all oauth.signIn, oauth.passwordGrant and authorizationCodeGrant. This means that if the response for those calls contains an id_token, it will be properly validated.

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.

Also need a better PR description here.

src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAUthWithIDTokenValidation.js Outdated Show resolved Hide resolved
src/auth/OAuthAuthenticator.js Outdated Show resolved Hide resolved
@joshcanhelp
Copy link
Contributor

I'm also thinking you should probably test against a generated ID token to make sure everything goes through from start to finish. It's a bit of work to get it running with RS256 but certainly possible. I think it's important to test against potential ID token problems as that's what this is meant to catch. I found, in that Rails PR, that the token verifier had a number of options that needed to be set in order to make sure all the validation was happening properly. I don't know if the Node lib you're using is the same but I think it's worth the effort. CodeCov might stop complaining as well :).

@luisrudge
Copy link
Contributor Author

Added integration tests (full id_token validation)

src/auth/OAUthWithIDTokenValidation.js Show resolved Hide resolved
@@ -12,6 +14,7 @@ var RestClient = require('rest-facade').Client;
*
* @param {Object} options Authenticator options.
* @param {String} options.baseUrl The auth0 account URL.
* @param {String} options.domain AuthenticationClient server domain
Copy link
Contributor

Choose a reason for hiding this comment

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

Still not indented properly

@@ -12,6 +14,7 @@ var RestClient = require('rest-facade').Client;
*
* @param {Object} options Authenticator options.
* @param {String} options.baseUrl The auth0 account URL.
Copy link
Contributor

Choose a reason for hiding this comment

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

"Auth0" ... capital "A"

});
});
describe('#integration', function() {
it('with a HS256 id_token and `options.supportedAlgorithms===RS256`', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

it('fails with a HS256 id_token ...

done();
});
});
it('when `token.header.alg===RS256` and `options.supportedAlgorithms===HS256`', done => {
Copy link
Contributor

Choose a reason for hiding this comment

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

it('fails when 'token.header.alg===RS256 ' ...

supportedAlgorithms: ['RS256']
});
oauthWithValidation.create(PARAMS, DATA, function(e, d) {
expect(e.message).to.eq('jwt issuer invalid. expected: https://auth.brucke.club/');
Copy link
Contributor

Choose a reason for hiding this comment

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

I issue we don't have any control over the error message here? I wonder if it's bad practice to show what we were expecting.

clientId: 'foobar',
clientSecret: CLIENT_SECRET,
domain: 'brucke.auth0.com',
supportedAlgorithms: ['RS256']
Copy link
Contributor

Choose a reason for hiding this comment

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

How are you creating an RS256 token that can be used indefinitely?

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.

That pem library looks nice!

A few small ones left.

}
);
var oauthWithValidation = new OAUthWithIDTokenValidationProxy(oauth, {
clientId: 'foobar',
Copy link
Contributor

Choose a reason for hiding this comment

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

How about __test_client_id__?

var idtoken = jwt.sign({ foo: 'bar' }, c.serviceKey, {
algorithm: 'RS256',
issuer: 'wrong_issuer',
audience: 'foobar',
Copy link
Contributor

Choose a reason for hiding this comment

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

How about __test_audience__?

done();
});
});
describe('when using a valid token', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

when using a valid token

Aren't these invalid?

done();
});
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you test for nbf failing as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Auth0 tokens do not return an nbf so not necessary for this use case.

it('Calls jwt.verify with token and algs', function(done) {
var oauth = {
create: function() {
return new Promise(res => res({ id_token: 'foobar' }));
Copy link
Contributor

Choose a reason for hiding this comment

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

How about __test_id_token__? Many more below ...

joshcanhelp
joshcanhelp previously approved these changes Sep 21, 2018
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.

I would still replace foobar with something a little more generic but LGTM besides that.

@esarafianou
Copy link

LGTM from a security perspective

@luisrudge luisrudge merged commit 58d45f2 into master Sep 28, 2018
@luisrudge luisrudge deleted the feature/idtoken-validation branch September 28, 2018 17:31
@luisrudge luisrudge changed the title Adding id_token validation Add id_token validation (HS256 and RS256) Sep 28, 2018
@luisrudge luisrudge added this to the v2.13.0 milestone Sep 28, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants