Skip to content

Commit

Permalink
fix: ensure jwt replay detection takes clockTolerance into account
Browse files Browse the repository at this point in the history
  • Loading branch information
panva committed Apr 20, 2022
1 parent 3fca22b commit f167233
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/actions/authorization/process_request_object.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ module.exports = async function processRequestObject(PARAM_LIST, rejectDupesMidd

if (route !== 'pushed_authorization_request' && payload.jti && payload.exp && payload.iss) {
const unique = await ctx.oidc.provider.ReplayDetection.unique(
payload.iss, payload.jti, payload.exp,
payload.iss, payload.jti, payload.exp + conf.clockTolerance,
);

if (!unique) {
Expand Down
7 changes: 5 additions & 2 deletions lib/shared/token_jwt_auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const instance = require('../helpers/weak_cache');
const JWT = require('../helpers/jwt');

module.exports = function getTokenJwtAuth(provider) {
const clockTolerance = instance(provider).configuration('clockTolerance');
return async function tokenJwtAuth(ctx, keystore, algorithms) {
const acceptedAud = ctx.oidc.clientJwtAuthExpectedAudience();
const { header, payload } = JWT.decode(ctx.oidc.params.client_assertion);
Expand Down Expand Up @@ -41,14 +42,16 @@ module.exports = function getTokenJwtAuth(provider) {

try {
await JWT.verify(ctx.oidc.params.client_assertion, keystore, {
clockTolerance: instance(provider).configuration('clockTolerance'),
clockTolerance,
ignoreAzp: true,
});
} catch (err) {
throw new InvalidClientAuth(err.message);
}

const unique = await provider.ReplayDetection.unique(payload.iss, payload.jti, payload.exp);
const unique = await provider.ReplayDetection.unique(
payload.iss, payload.jti, payload.exp + clockTolerance,
);

if (!unique) {
throw new InvalidClientAuth('client assertion tokens must only be used once');
Expand Down

0 comments on commit f167233

Please sign in to comment.