feat(auth): add workspaceId validation and token expiration (#9134)
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
This commit is contained in:
@ -100,6 +100,7 @@ export class AccessTokenService {
|
|||||||
return {
|
return {
|
||||||
token: this.jwtWrapperService.sign(jwtPayload, {
|
token: this.jwtWrapperService.sign(jwtPayload, {
|
||||||
secret: this.jwtWrapperService.generateAppSecret('ACCESS', workspaceId),
|
secret: this.jwtWrapperService.generateAppSecret('ACCESS', workspaceId),
|
||||||
|
expiresIn,
|
||||||
}),
|
}),
|
||||||
expiresAt,
|
expiresAt,
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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 };
|
return { user, token };
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,10 +123,12 @@ export class RefreshTokenService {
|
|||||||
const refreshTokenPayload = {
|
const refreshTokenPayload = {
|
||||||
userId,
|
userId,
|
||||||
expiresAt,
|
expiresAt,
|
||||||
|
workspaceId,
|
||||||
type: AppTokenType.RefreshToken,
|
type: AppTokenType.RefreshToken,
|
||||||
};
|
};
|
||||||
const jwtPayload = {
|
const jwtPayload = {
|
||||||
sub: userId,
|
sub: userId,
|
||||||
|
workspaceId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const refreshToken = this.appTokenRepository.create(refreshTokenPayload);
|
const refreshToken = this.appTokenRepository.create(refreshTokenPayload);
|
||||||
|
|||||||
Reference in New Issue
Block a user