security(relay): minor hardening follow-ups from PR review
- Uniform auth responses remove the session-enumeration oracle: unknown session and wrong password now return an identical 401 at the API layer and an identical WS handshake/close; desktop-status and the 503 "not connected" signal are only exposed after successful auth. - Session-count cap re-checked after bcrypt.hash so concurrent creates can't overshoot maxSessions. - Relay web client reconnect backoff resets only after a successful auth response (an accept-then-close server no longer defeats the backoff). - idGenerator comment corrected to match the rejection-sampling; drop unused recordFailure return value. - DEPLOY.md: document ALLOWED_ORIGINS for reverse-proxy deployments. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -32,31 +32,19 @@ export function handleWebClientConnection(
|
||||
// client IP. This prevents one abusive IP (which knows the shareable session
|
||||
// id) from locking out other web clients or the desktop for this session.
|
||||
const throttleKey = `web:${sessionId}:${clientIp}`;
|
||||
// Check if session exists
|
||||
const session = sessionManager.getSession(sessionId);
|
||||
if (!session) {
|
||||
socket.send(JSON.stringify({
|
||||
type: 'error',
|
||||
error: 'Session not found'
|
||||
}));
|
||||
socket.close();
|
||||
return;
|
||||
}
|
||||
|
||||
// Add client (not authenticated yet)
|
||||
// Do NOT reveal whether the session exists. A non-existent session id and
|
||||
// an existing one must be indistinguishable to an unauthenticated client so
|
||||
// session ids cannot be enumerated: we always run the same handshake and let
|
||||
// the (uniform) auth response be the only signal. validatePassword() safely
|
||||
// returns false for an unknown session id, and desktop connectivity is only
|
||||
// disclosed AFTER a successful auth (see the 'auth' case below).
|
||||
const client = connectionManager.addWebClient(sessionId, socket, false);
|
||||
|
||||
// Track failed auth attempts on this individual socket.
|
||||
let socketAuthFailures = 0;
|
||||
|
||||
// Check if desktop is connected
|
||||
const desktop = connectionManager.getDesktopBySessionId(sessionId);
|
||||
socket.send(JSON.stringify({
|
||||
type: 'desktop_status',
|
||||
status: desktop ? 'connected' : 'disconnected'
|
||||
}));
|
||||
|
||||
// Request authentication
|
||||
// Request authentication.
|
||||
socket.send(JSON.stringify({
|
||||
type: 'auth_required'
|
||||
}));
|
||||
@@ -76,6 +64,12 @@ export function handleWebClientConnection(
|
||||
}
|
||||
} else {
|
||||
socketAuthFailures = 0;
|
||||
// Authenticated: only now do we disclose desktop connectivity.
|
||||
const desktop = connectionManager.getDesktopBySessionId(sessionId);
|
||||
socket.send(JSON.stringify({
|
||||
type: 'desktop_status',
|
||||
status: desktop ? 'connected' : 'disconnected'
|
||||
}));
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -142,7 +136,7 @@ async function handleAuth(
|
||||
socket.send(JSON.stringify({
|
||||
type: 'auth_response',
|
||||
success: false,
|
||||
error: 'Invalid password'
|
||||
error: 'Authentication failed'
|
||||
}));
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user