mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-16 13:38:33 +00:00
fix(auth): align WebSocket token_version checks with HTTP (#1744)
* test(auth): cover legacy no-tv JWT rejection on WebSocket upgrades * fix(auth): treat missing tv claim as token_version 1 on WebSocket upgrades
This commit is contained in:
@@ -85,7 +85,9 @@ export function handleGenericWs(
|
||||
console.warn('[Exec] User account not found:', decoded.username);
|
||||
return reject(socket, 401, 'Unauthorized');
|
||||
}
|
||||
if (decoded.tv !== undefined && execUser.token_version !== decoded.tv) {
|
||||
// Missing `tv` is a pre-migration legacy token at version 1, same default
|
||||
// as `authMiddleware`; a bumped account version must reject it.
|
||||
if (execUser.token_version !== (decoded.tv ?? 1)) {
|
||||
console.warn('[Exec] Session invalidated (token version mismatch):', decoded.username);
|
||||
return reject(socket, 401, 'Unauthorized');
|
||||
}
|
||||
|
||||
@@ -201,7 +201,9 @@ export function attachUpgrade(
|
||||
if (!decoded.scope && decoded.username) {
|
||||
const dbUser = DatabaseService.getInstance().getUserByUsername(decoded.username);
|
||||
if (!dbUser) return reject(socket, 401, 'Unauthorized');
|
||||
if (decoded.tv !== undefined && dbUser.token_version !== decoded.tv) {
|
||||
// Missing `tv` is a pre-migration legacy token at version 1, same default
|
||||
// as `authMiddleware`; a bumped account version must reject it.
|
||||
if (dbUser.token_version !== (decoded.tv ?? 1)) {
|
||||
console.log('[Auth] WS session rejected: token version mismatch for:', decoded.username);
|
||||
return reject(socket, 401, 'Unauthorized');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user