fix(dashboard): accept a signed ticket on the log WebSocket (Safari fix)#359
Merged
Conversation
Safari/WebKit does not replay cached HTTP Basic credentials on a WebSocket handshake (Chrome and Firefox do), so the dashboard's `/ws/logs` auth gate rejected Safari with close 1008 — the browser surfaced it as "WebSocket connection failed: bad response from the server". Chrome was fine because it replays the cached same-origin Basic creds on the upgrade. Fix: the log WS now accepts EITHER replayed Basic auth (unchanged, Chrome/Firefox) OR a short-lived signed ticket. The already-authenticated page fetches the ticket from a new `GET /api/ws-ticket` (a normal request, which replays Basic auth in every browser including Safari) and passes it in the handshake URL (`/ws/logs?ticket=...`). The ticket is a stateless HMAC over its own expiry under the dashboard token (~30s TTL) — no server-side state. The Host-pin and Origin gates are unchanged, so the cross-origin / DNS-rebinding defenses still hold. - server.py: `_make_ws_ticket` / `_ws_ticket_ok`, `GET /api/ws-ticket`, WS gate accepts Basic-or-ticket. - app.js: `connectWS` fetches the ticket before opening the socket (graceful fallback to Basic replay). - test_server.py: ticket round-trip, endpoint auth, and unauthenticated-WS-rejected.
…e WS-ticket fix The Safari WS fix lives in app.js, but index.html referenced it as app.js?v=20260611-paper14 (unchanged), so a cached old app.js kept being served and the fix didn't take without a hard refresh. Bump the version query to force a re-fetch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The dashboard live-logs WebSocket failed in Safari only (
WebSocket connection to ws://localhost:61208/ws/logs failed: bad response from the server); Chrome was fine.Cause
The
/ws/logshandler requires HTTP Basic auth on the handshake, relying on the browser replaying the cached same-origin Basic credentials. Safari/WebKit does not attach Basic auth to WebSocket handshakes (long-standing behaviour); Chrome/Firefox do. So Safari hit the auth gate →ws.close(1008)→ "bad response from the server".Fix
The WS now accepts either replayed Basic auth (unchanged) or a short-lived signed ticket:
GET /api/ws-ticket(gated by the existing Basic-auth middleware — a normal request, which replays Basic auth in every browser incl. Safari) returns an HMAC ticket over its own expiry under the dashboard token (~30s TTL, stateless).app.jsfetches the ticket, then opens/ws/logs?ticket=.... Falls back to the Basic-replay path if the fetch fails.Tests
test_server.py: ticket round-trip (valid/tampered/garbage/wrong-token),/api/ws-ticketauth, unauthenticated-WS-rejected. Ticket logic verified standalone;py_compileclean.Dashboard assets are
@embedFiled into mtbuddy, so this ships with the next release (and reinstalling the dashboard rewrites the files).