483b131ef wrote a full-access gateway key ("Magpie Browser") into the
extension zip in Downloads. Anyone with a copy of the zip could use every
model, MCP server and stat, and, with own = key == OwnBrowserKey(), could
connect from another machine as this computer's own browser and receive
this computer's agents' browser calls (page data out, prompt injection
in). A keyed WebSocket also stayed open after its key was turned off.
- access: Key.Browser / Identity.Browser. A browser key is also ReadOnly
(so a magpie from before reads it as read-only) and never issues keys.
access-key and issuer-key refuse it. ScopeBrowser(id) holds an existing
key to the browser with the same secret; the sharing key is never
scoped. Current(who) says whether a key Check took is still on by the
same secret (Identity carries the secret's SHA-256, set on the legacy
sharing-key fallback too, so a legacy caller's identity is the same
before and after its migration).
- gateway readOnlyGuard, the one place every route passes after the key
is known: a browser key gets 403 gateway_key_browser_only on every
pattern except GET /v1/magpie/browser/extension.
- own: the key must be OwnBrowserKey() and the request local(r)
(loopback peer, not proxied, not the page port).
- browserConn keeps its key's identity. call() refuses a connection whose
key is no longer Current, and a 5s watcher closes it (1008).
- gui browserKey: a new key is made Browser; the recorded key is reused
only once ScopeBrowser holds it.
- GUI key row: "Browser only" tag (zh, zh-TW, ja, de), no access toggle.
CLI prints "browser" access. agent gatewayTakes skips a browser key.
Old data: an existing "Magpie Browser" key (OwnBrowserKey) is rescoped in
place, same id and secret, when the gateway starts (ScopeOwnBrowserKey)
and again on the next extension download. Installed extensions keep
connecting with no reinstall. Every copy of an old zip loses models, MCP,
stats and writes, and from another machine it is no longer this
computer's browser. A user who downgrades reads the key as read-only.
Keys a user made themselves are untouched.
Regression, filed as #5529: Magpie in Docker with the host's Chrome
reaches the container from 172.17.0.1, not loopback, so its agents no
longer get the host's browser as their own. #5529 proposes pairing in
its place. docs/reference.md and site docker pages (en, zh, ja) say so.
Docs: docs/subsystems/gateway-routing.md (browser key), library.md
(Download), docs/reference.md (Docker), site/public/docs{,/zh,/ja}/docker.html.
Run on mote at origin/main 2000ae439 + this change:
- gofmt -l internal cmd: empty.
- go vet darwin, GOOS=windows, GOOS=linux -tags nogui over access,
gateway, gui, agent, cli: ok.
- go test -tags nogui -count=1 -timeout 45m ./internal/gateway
./internal/gui ./internal/access ./internal/library ./internal/agent
./internal/cli: all ok except access's
TestLegacyLANFallbackBeforeMigration, red from this change (the legacy
fallback had no secret sum). Fixed here, then ./internal/access in full:
ok.
- GUI, 21 files (gateway-key-*, i18n-*, library-browser-*), chromium and
webkit, every language: 332 of 334. The 2 reds fail the same on
origin/main 6f5d48ea0 run alone: i18n-keys "a plugin's words are its
own" (#5332, #5426, #5482) and gateway-key-models' 560px width check
(#4081, commented).
Rebased onto 6f5d48ea0 (remote_prove: a new POST /v1/magpie/prove route
and edits to readonly.go and gateway.go, so not a -run rerun): gofmt -l
empty, vet on all three ok, go test -count=1 ./internal/gateway
./internal/access ok, ./internal/gui -run Browser ok. A browser key gets
403 on the prove route too (TestBrowserKeyEveryRoute walks every pattern).
Broken by hand, each red on mote:
- guard off: TestBrowserKeyEveryRoute (/v1/ 200, /v1/models read_only
not browser_only).
- no migrate: TestBrowserKeyEveryRoute (/v1/models 200).
- own without local(r): TestOwnBrowserKeyIsThisComputers.
- no watcher: TestBrowserKeyOffClosesItsBrowser (stayed connected).
- no Current check in call(): TestBrowserKeyOffClosesItsBrowser.
- Current ignoring the secret: TestCurrent.
- gui reuse without ScopeBrowser / new key without Browser:
TestBrowserExtensionDownload (both).
Not tried: a real Chrome with the real extension, a real Docker
container, a real old key in a live HOME, the TUI. No CLI test for the
"browser" access word. Tests reach no network (httptest, loopback only).
noahhrreion ran magpie in a container and its Magpie Browser never
connected. The host's Chrome dials ws://127.0.0.1:3425/v1/magpie/browser/
extension, which reaches the container from the bridge (172.17.0.1). That
is not loopback, so the gateway refused it (403). The browser MCP also
refused every caller from elsewhere, and the hub marked the browser
HereOnly. The extension's folder under the container's HOME can't be
loaded by the host's browser either.
Nothing is opened to the network without a key:
- The extension takes a gateway key: its popup has a Gateway key field,
and config.js carries KEY (extension 0.1.7). From another computer the
extension connects only with ?key= of a gateway key that is on, and
only from the extension's own Origin (checked first). Loopback is
unchanged, and a page's origin, null, a keyless call or a rebound Host
are all still refused (TestBrowserExtensionOnlyFromItsOrigin).
- A browser that connects with a key belongs to that key. Sessions are
tagged key:<id>/... (browserOwner, keyedSession), and a remote caller's
session is forced to its own key's whatever it names. The relay filters
every lookup (forSession, all, choose) through browserConn.serves. The
browser MCP admits a remote caller only with a gateway key; a web page
is refused as before.
- The key the page makes is recorded as this magpie's own browser's: its
id goes in settings.Dir()/browser-key, written temp-and-rename. This
goes by where the key came from, not by its name. A browser connecting
with it serves this computer's sessions too, so agents inside the
container use it as they would one on loopback. A record that can't be
read names no key, so no keyed browser is this computer's.
- Router: magpie mcp browser is HubServer.Keyed. A visitor from
elsewhere gets it only with a key (HubVisitor.Key), and hubCall names
its session key:<id>/..., so it reaches only that key's browser.
- GUI: a page whose browser can't reach magpie's folders (InContainer, or
a page from another computer) is "away". The Magpie Browser sheet's
button then reads Download the extension. It does a POST to
/api/library/browser/extension with the page's origin, which answers a
zip pointed at that origin (3430 passes the gateway's routes on) and
holding the recorded key's secret. The key is made the first time and
reused while it is on. The steps (unzip, chrome://extensions, Developer
mode, Load unpacked) are shown in every language. It is a POST so that
a link from another site can't mint a key.
- Docs: reference.md (Docker), subsystems/library.md and mcp-router.md,
and site docker.html in en, zh and ja.
Run, at this tree rebased on origin/main 6302f88bf, on mote:
- gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./..., and darwin, linux and windows builds:
clean, all ok
- go test -tags nogui -run 'Browser|Hub|OwnBrowser' ./internal/gateway/,
and the whole of internal/library, internal/gui and internal/browserext:
ok (gateway 2.4s, library 166s, gui 104s, browserext 0.3s)
- GUI tests library-browser-away (new: every language, Chromium and
WebKit, 1100 and 420 wide), library-browser-setup, library-browser-ask,
i18n-keys and i18n-en-no-cjk: 115 pass. One red, i18n-keys "a plugin's words are its own", is for three
strings this change doesn't touch and is already filed (#5332, #5426,
#5482)
Real use, in Docker Desktop on xiaomi-gpu (Windows 11): this tree's
Dockerfile image, run as `web --addr 0.0.0.0:3430` with 3425 and 3430
published to the host's localhost. The host's Node and Playwright Chromium:
- signed in to the page, which says away:true;
- downloaded the zip (GATEWAY "ws://localhost:3530" and a KEY), twice,
getting the same key both times;
- a keyless /mcp/magpie/browser call from the host got 401;
- loaded the unzipped extension with --load-extension. The container's log
says "Magpie Browser 0.1.7 connected with gateway key 12d2702a…" and
/api/library/browser says connected:true;
- an MCP client on the host with that key listed b1 (Chrome 151), opened
http://localhost:3531/ (served on the host) and read "hello from the
host";
- a second gateway key made in the container got "isn't connected with
this gateway key";
- a curl inside the container to 127.0.0.1:3425/mcp/magpie/browser with no
key listed the host browser's tabs, the host page included.
Broken by hand, each red:
- forSession left unfiltered;
- a remote session not forced to its key;
- no Origin check on a keyed connect;
- hubCall not prefixing the session;
- Keyed given to a visitor with no key;
- the old MCP guard;
- browserKey not reusing the key;
- the away peer check removed;
- serves("") without own (TestOwnBrowserKeyIsThisComputers,
TestOwnBrowserKeyUnreadable);
- OwnBrowserKey reading the wrong file (the gateway tests and
TestBrowserExtensionDownload).
Not tried:
- the reporter's own setup (their compose file and Chrome);
- a real agent's MCP client calling the browser from the host. Node's
fetch sends Sec-Fetch-Mode: cors, which fromBrowser counts as a web page
and refuses. The e2e used node's http instead. Whether an agent's MCP
client built on fetch is hit by this is not checked; filed as #5522.
- Edge, Brave and Firefox;
- a remote page over https/wss through a proxy.
What the user does: update magpie and publish 3425 and 3430. In the web
UI open Library -> Magpie Browser -> Download the extension, unzip it and
Load unpacked in chrome://extensions. An extension 0.1.7 already loaded
can take the address and key in its popup instead.
Reported-by: noahhrreion (Discord)