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.