Skip to content

Commit 4942489

Browse files
author
Philip Skinner
committed
Added two further checks for the JWT and the JWS
1 parent ac1c025 commit 4942489

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/strategy.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,14 @@ Strategy.prototype.authenticate = function(req, options) {
9797

9898
var idTokenSegments = idToken.split('.')
9999
, jwtClaimsStr
100-
, jwtClaims;
100+
, jwtClaims
101+
, joseHeader;
101102

102103
try {
103104
jwtClaimsStr = new Buffer(idTokenSegments[1], 'base64').toString();
104105
jwtClaims = JSON.parse(jwtClaimsStr);
106+
107+
joseHeader = JSON.parse(new Buffer(idTokenSegments[0], 'base64').toString());
105108
} catch (ex) {
106109
return self.error(ex);
107110
}
@@ -144,6 +147,12 @@ Strategy.prototype.authenticate = function(req, options) {
144147
return self.error(new Error('Invalid nonce in id_token'));
145148
}
146149

150+
// http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation - check 10
151+
if (jwtClaims.iat >= jwtClaims.exp) return self.error(new Error('id token has expired'));
152+
153+
// http://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation - check 7-ish
154+
if (!joseHeader.alg || typeof(joseHeader.alg) === 'undefined') return self.error(new Error('Invalid algorithm type'));
155+
147156
var iss = jwtClaims.iss;
148157
var sub = jwtClaims.sub;
149158
// Prior to OpenID Connect Basic Client Profile 1.0 - draft 22, the

0 commit comments

Comments
 (0)