Skip to content

Commit e31f639

Browse files
committed
refactor: reconcile dpop and attestation challenge implementations
1 parent d655ebd commit e31f639

File tree

12 files changed

+33
-57
lines changed

12 files changed

+33
-57
lines changed

lib/actions/authorization/check_dpop_jkt.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { InvalidRequest } from '../../helpers/errors.js';
2-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
2+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
33
import epochTime from '../../helpers/epoch_time.js';
44
import instance from '../../helpers/weak_cache.js';
55

@@ -18,7 +18,7 @@ export default async function checkDpopJkt(ctx, next) {
1818
const unique = await ReplayDetection.unique(
1919
ctx.oidc.client.clientId,
2020
dPoP.jti,
21-
epochTime() + DPOP_OK_WINDOW,
21+
epochTime() + CHALLENGE_OK_WINDOW,
2222
);
2323

2424
ctx.assert(unique, new InvalidRequest('DPoP proof JWT Replay detected'));

lib/actions/challenge.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default [
88

99
ctx.body = {};
1010

11-
const nextNonce = DPoPNonces?.nextNonce();
11+
const nextNonce = DPoPNonces?.nextChallenge();
1212
if (nextNonce) {
1313
ctx.set('dpop-nonce', nextNonce);
1414
}

lib/actions/grants/authorization_code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import instance from '../../helpers/weak_cache.js';
44
import checkPKCE from '../../helpers/pkce.js';
55
import revoke from '../../helpers/revoke.js';
66
import filterClaims from '../../helpers/filter_claims.js';
7-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
7+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
88
import resolveResource from '../../helpers/resolve_resource.js';
99
import epochTime from '../../helpers/epoch_time.js';
1010
import checkRar from '../../shared/check_rar.js';
@@ -144,7 +144,7 @@ export const handler = async function authorizationCodeHandler(ctx) {
144144
const unique = await ReplayDetection.unique(
145145
ctx.oidc.client.clientId,
146146
dPoP.jti,
147-
epochTime() + DPOP_OK_WINDOW,
147+
epochTime() + CHALLENGE_OK_WINDOW,
148148
);
149149

150150
ctx.assert(unique, new InvalidGrant('DPoP proof JWT Replay detected'));

lib/actions/grants/ciba.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import presence from '../../helpers/validate_presence.js';
55
import instance from '../../helpers/weak_cache.js';
66
import filterClaims from '../../helpers/filter_claims.js';
77
import revoke from '../../helpers/revoke.js';
8-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
8+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
99
import resolveResource from '../../helpers/resolve_resource.js';
1010
import epochTime from '../../helpers/epoch_time.js';
1111
import getCtxAccountClaims from '../../helpers/account_claims.js';
@@ -147,7 +147,7 @@ export const handler = async function cibaHandler(ctx) {
147147
const unique = await ReplayDetection.unique(
148148
ctx.oidc.client.clientId,
149149
dPoP.jti,
150-
epochTime() + DPOP_OK_WINDOW,
150+
epochTime() + CHALLENGE_OK_WINDOW,
151151
);
152152

153153
ctx.assert(unique, new InvalidGrant('DPoP proof JWT Replay detected'));

lib/actions/grants/client_credentials.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import instance from '../../helpers/weak_cache.js';
22
import {
33
InvalidGrant, InvalidTarget, InvalidScope, InvalidRequest,
44
} from '../../helpers/errors.js';
5-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
5+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
66
import checkResource from '../../shared/check_resource.js';
77
import epochTime from '../../helpers/epoch_time.js';
88

@@ -65,7 +65,7 @@ export const handler = async function clientCredentialsHandler(ctx) {
6565
const unique = await ReplayDetection.unique(
6666
client.clientId,
6767
dPoP.jti,
68-
epochTime() + DPOP_OK_WINDOW,
68+
epochTime() + CHALLENGE_OK_WINDOW,
6969
);
7070

7171
ctx.assert(unique, new InvalidGrant('DPoP proof JWT Replay detected'));

lib/actions/grants/device_code.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import presence from '../../helpers/validate_presence.js';
55
import instance from '../../helpers/weak_cache.js';
66
import filterClaims from '../../helpers/filter_claims.js';
77
import revoke from '../../helpers/revoke.js';
8-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
8+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
99
import resolveResource from '../../helpers/resolve_resource.js';
1010
import epochTime from '../../helpers/epoch_time.js';
1111
import getCtxAccountClaims from '../../helpers/account_claims.js';
@@ -146,7 +146,7 @@ export const handler = async function deviceCodeHandler(ctx) {
146146
const unique = await ReplayDetection.unique(
147147
ctx.oidc.client.clientId,
148148
dPoP.jti,
149-
epochTime() + DPOP_OK_WINDOW,
149+
epochTime() + CHALLENGE_OK_WINDOW,
150150
);
151151

152152
ctx.assert(unique, new InvalidGrant('DPoP proof JWT Replay detected'));

lib/actions/grants/refresh_token.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import revoke from '../../helpers/revoke.js';
66
import certificateThumbprint from '../../helpers/certificate_thumbprint.js';
77
import * as formatters from '../../helpers/formatters.js';
88
import filterClaims from '../../helpers/filter_claims.js';
9-
import dpopValidate, { DPOP_OK_WINDOW } from '../../helpers/validate_dpop.js';
9+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../../helpers/validate_dpop.js';
1010
import resolveResource from '../../helpers/resolve_resource.js';
1111
import epochTime from '../../helpers/epoch_time.js';
1212
import checkRar from '../../shared/check_rar.js';
@@ -105,7 +105,7 @@ export const handler = async function refreshTokenHandler(ctx) {
105105
const unique = await ReplayDetection.unique(
106106
client.clientId,
107107
dPoP.jti,
108-
epochTime() + DPOP_OK_WINDOW,
108+
epochTime() + CHALLENGE_OK_WINDOW,
109109
);
110110

111111
ctx.assert(unique, new InvalidGrant('DPoP proof JWT Replay detected'));

lib/actions/userinfo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import noCache from '../shared/no_cache.js';
77
import certificateThumbprint from '../helpers/certificate_thumbprint.js';
88
import instance from '../helpers/weak_cache.js';
99
import filterClaims from '../helpers/filter_claims.js';
10-
import dpopValidate, { DPOP_OK_WINDOW } from '../helpers/validate_dpop.js';
10+
import dpopValidate, { CHALLENGE_OK_WINDOW } from '../helpers/validate_dpop.js';
1111
import epochTime from '../helpers/epoch_time.js';
1212
import {
1313
InvalidToken, InsufficientScope, InvalidDpopProof, UseDpopNonce,
@@ -106,7 +106,7 @@ export default [
106106
const unique = await ctx.oidc.provider.ReplayDetection.unique(
107107
accessToken.clientId,
108108
dPoP.jti,
109-
epochTime() + DPOP_OK_WINDOW,
109+
epochTime() + CHALLENGE_OK_WINDOW,
110110
);
111111

112112
ctx.assert(unique, new InvalidToken('DPoP proof JWT Replay detected'));

lib/helpers/configuration.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ class Configuration {
5959
this.checkCibaDeliveryModes();
6060
this.checkRichAuthorizationRequests();
6161
this.checkPostMethods();
62-
this.checkAttestClientAuth();
6362

6463
delete this.cookies.long.maxAge;
6564
delete this.cookies.long.expires;
@@ -394,15 +393,6 @@ class Configuration {
394393
});
395394
}
396395

397-
checkAttestClientAuth() {
398-
if (this.features.attestClientAuth.enabled) {
399-
const secret = this.features.attestClientAuth.challengeSecret;
400-
if (!Buffer.isBuffer(secret) || secret.byteLength !== 32) {
401-
throw new TypeError('features.attestClientAuth.challengeSecret secret must be a 32-byte Buffer instance');
402-
}
403-
}
404-
}
405-
406396
checkFapiProfile() {
407397
if (!this.features.fapi.enabled) {
408398
this.features.fapi.profile = () => undefined;

lib/helpers/dpop_nonces.js

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)