Skip to content

Commit

Permalink
feat(auth): add workspaceId validation and token expiration (#9134)
Browse files Browse the repository at this point in the history
Added validation to ensure refresh tokens include a workspaceId,
throwing an exception for malformed tokens. Included workspaceId in
payloads and introduced expiration handling for access tokens. This
enhances token security and prevents potential misuse.

Close #9126
  • Loading branch information
AMoreaux authored Dec 18, 2024
1 parent f620fd3 commit a2423fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export class AccessTokenService {
return {
token: this.jwtWrapperService.sign(jwtPayload, {
secret: this.jwtWrapperService.generateAppSecret('ACCESS', workspaceId),
expiresIn,
}),
expiresAt,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ export class RefreshTokenService {
);
}

// TODO: Delete this useless condition and error after March 31st 2025
if (!token.workspaceId) {
throw new AuthException(
'This refresh token is malformed',
AuthExceptionCode.INVALID_INPUT,
);
}

return { user, token };
}

Expand All @@ -115,10 +123,12 @@ export class RefreshTokenService {
const refreshTokenPayload = {
userId,
expiresAt,
workspaceId,
type: AppTokenType.RefreshToken,
};
const jwtPayload = {
sub: userId,
workspaceId,
};

const refreshToken = this.appTokenRepository.create(refreshTokenPayload);
Expand Down

0 comments on commit a2423fa

Please sign in to comment.