Commit Graph
4 Commits
Author SHA1 Message Date
yetone b6cf5e3eab gui: magpie web keeps its sign-in when another service on the same address fills or clears the host's cookies, and a page opened without it says why and takes the key (#2033, 321sssrt-bit)
A browser keeps cookies per host, not per port. magpie web's sign-in
cookie on http://<tailscale-ip>:3430 is the same host's as every other
service on that IP's other ports, so one of them could take it away,
and a bookmark then answered only "open the link magpie web printed
when it started".

Reproduced in Docker (linux/arm64, MAGPIE_WEB_KEY fixed, as the
reporter runs it) with Chromium and WebKit on the old binary:
- docker restart, recreate (an update), browser restart: still signed
  in (the key, its derivation and the 400-day cookie are fine);
- another port on the same host setting ~400 cookies: Chromium evicts
  the sign-in (401), WebKit keeps it;
- another port answering Clear-Site-Data: "cookies" (a sign-out often
  does): 401 in both;
- the page opened by another name for the host (localhost vs IP): 401.

Changed:
- the sign-in cookie is sent with Priority=High, so Chrome evicts it
  last when the host's cookies overflow (with it, the flood case stays
  signed in);
- every magpie_web_<port> cookie the browser sends is tried, so a stale
  one sent first no longer hides the right one;
- an HTML page opened without the sign-in gets a page that says which
  case it is (no cookie sent for this address, or a cookie holding
  another key) and a field to paste MAGPIE_WEB_KEY into; POST
  /_magpie/sign-in sets the cookie and goes back to the page asked for
  (local paths only: no scheme, host, //, /\ or the sign-in itself).
  The key is never in the page. API calls get a plain 401 that now
  says the reason too, and the turn-away is logged with it.
- docs/reference.md's Docker web section says how long a sign-in lasts
  and what can take it away.

Run:
- TestWebGuardBookmark (link cookie has Priority=High; stale cookie
  first still passes; both reasons; API 401; wrong key 401 with no
  cookie; right key 303 to /?view=usage with a 400-day cookie; external,
  //, /\, javascript:, empty, sign-in-path and CRLF back values all go
  to /). Broken by hand: the old guard fails it (link without
  Priority), dropping Priority alone fails it, reading only the first
  cookie fails it (stale cookie: 401).
- The Docker matrix above again on the new binary: the flood keeps the
  sign-in in Chromium; Clear-Site-Data and the other name get the form,
  and the form signs in (wrong key turned away, right key back to
  /?view=usage, 200) in Chromium and WebKit; the log says "turned away
  ... no cookie sent".
- go test -tags nogui ./internal/gui (ok, 173s), gofmt -l, go vet
  darwin, GOOS=linux -tags nogui, GOOS=windows.

Not tried: the reporter's own browser and Tailscale address; which
service on their host takes the cookie is not known.
2026-10-14 05:29:30 +08:00
yetone 8f915a5a23 web: MAGPIE_WEB_KEY takes letters, digits and - . _ ~ only — a cookie can't hold a space, ; or a quote, so the browser was sent a cookie that wasn't the key and turned away with no word why 2026-09-27 17:26:21 +08:00
Arvak 84ef25805e web: MAGPIE_WEB_KEY keeps the page's key across runs — for magpie web kept running as a service, where a new key each start signs every browser out; with it the cookie outlives the browser session too (400 days, Chrome's most). Unset, each run makes its own key in a session cookie, as before. A key under 16 characters is refused. (#109) 2026-09-27 17:26:32 +08:00
yetone 59e4f417b2 web: magpie web serves the app's window to a browser, with the gateway beside it — for a computer that can't show the app: no desktop, WSL, a server over SSH, or the CLI-only build, which now carries the page too (what of the app needs Wails is left out of nogui builds). Every request needs this run's key, which the printed link carries and trades for a cookie other sites' pages can't send with a POST; --lan serves it on the network too, with a warning, --addr elsewhere, --no-open leaves the browser shut. In the browser the page opens links and sign-ins itself, names a folder instead of opening it, and leaves out the tray, the Dock and open at login. Tested from a nogui build in a sandbox: no key, a wrong key and a cookieless POST are refused; with the link Agents, Providers and Settings load and a setting saves. Issue #102 2026-09-27 16:21:26 +08:00