bug: update revokedAt on PKCE flow (#4918)
The authorization token has an expiry of 5 minutes, we already have checks in place to verify this and throw a Forbidden exception. We need to revoke the token once it's used otherwise it could be used multiple times to gain access to tokens till it expires.
This commit is contained in:
@ -322,13 +322,13 @@ export class TokenService {
|
||||
assert(
|
||||
authorizationCodeAppToken,
|
||||
'Authorization code does not exist',
|
||||
ForbiddenException,
|
||||
NotFoundException,
|
||||
);
|
||||
|
||||
assert(
|
||||
authorizationCodeAppToken.expiresAt.getTime() >= Date.now(),
|
||||
'Authorization code expired.',
|
||||
NotFoundException,
|
||||
ForbiddenException,
|
||||
);
|
||||
|
||||
const codeChallenge = crypto
|
||||
@ -355,7 +355,7 @@ export class TokenService {
|
||||
assert(
|
||||
codeChallengeAppToken.expiresAt.getTime() >= Date.now(),
|
||||
'code challenge expired.',
|
||||
NotFoundException,
|
||||
ForbiddenException,
|
||||
);
|
||||
|
||||
assert(
|
||||
@ -364,6 +364,15 @@ export class TokenService {
|
||||
ForbiddenException,
|
||||
);
|
||||
|
||||
if (codeChallengeAppToken.revokedAt) {
|
||||
throw new ForbiddenException('Token has been revoked.');
|
||||
}
|
||||
|
||||
await this.appTokenRepository.save({
|
||||
id: codeChallengeAppToken.id,
|
||||
revokedAt: new Date(),
|
||||
});
|
||||
|
||||
userId = codeChallengeAppToken.userId;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user