A modern and elegant dashboard for network traffic visualization and analysis.
fix(auth): accept URL-encoded session tokens
heroixinua45081c4b93e
diff --git a/apps/collector/src/modules/auth/auth.service.test.ts b/apps/collector/src/modules/auth/auth.service.test.tsindex 62862fb..12ac522 100644--- a/apps/collector/src/modules/auth/auth.service.test.ts+++ b/apps/collector/src/modules/auth/auth.service.test.ts@@ -36,6 +36,17 @@ describe('AuthService', () => {expect(result.valid).toBe(true);});+ it('should verify URL-encoded session tokens', async () => {+ const token = 'abc1+/=';+ await authService.enableAuth(token);++ const encodedToken = encodeURIComponent(token);+ expect(encodedToken).toBe('abc1%2B%2F%3D');++ const result = await authService.verifyToken(encodedToken);+ expect(result.valid).toBe(true);+ });+it('should reject incorrect token', async () => {await authService.enableAuth('correct1');diff --git a/apps/collector/src/modules/auth/auth.service.ts b/apps/collector/src/modules/auth/auth.service.tsindex 1df89b9..0685448 100644--- a/apps/collector/src/modules/auth/auth.service.ts+++ b/apps/collector/src/modules/auth/auth.service.ts@@ -87,6 +87,21 @@ export class AuthService {return { valid: true };}+ // WebSocket authentication reads the raw Cookie header, where values set by+ // @fastify/cookie may still be percent-encoded. Keep the original check+ // above for backwards compatibility, then retry with the decoded value.+ try {+ const decodedToken = decodeURIComponent(token);+ if (decodedToken !== token) {+ const decodedTokenHash = await hashToken(decodedToken);+ if (await timingSafeHashEqual(decodedTokenHash, config.tokenHash)) {+ return { valid: true };+ }+ }+ } catch {+ // Malformed percent-encoding is simply treated as an invalid token.+ }+return { valid: false, message: 'Invalid token' };}