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).
fe61503e6 had a Remote magpie whose address didn't dial look for it on
the old address's /24 and this computer's private /24s, and sent GET
/v1/models, signed with the provider's gateway key (Authorization,
x-api-key and the provider's own headers), to every address that took
the connection at the port. On a café's or hotel's network, or with the
other computer off, anything listening there got the key in clear and,
by answering {"data":[]}, became the provider: the failed request and
every later one went to it. 18a9a2d88 turned the look off.
Now an address that takes the connection is first asked to prove it
holds the key, with nothing keyed sent:
- B POSTs {"nonce": 32 random bytes hex, "key_id": sha256(key) hex} to
/v1/magpie/prove (provider.RemoteProvePath), no key, no provider
headers, no proxy, no redirects (proves in remote_moved.go).
- A (gateway's remote_prove.go) finds the enabled gateway key with that
sha256 (access.ProveSecret: constant-time compares over every key,
the legacy settings sharing key too, then Check, so an off, expired
or orphaned issued key has none) and answers
HMAC-SHA256(key, "magpie-prove-v1\n" nonce "\n" address), the address
being the one the connection reached it at (http.LocalAddrContextKey);
404 when no key matches. A host that relays B's nonce to A elsewhere
gets a proof for A's address, which B, checking against the address it
dialled with hmac.Equal, refuses.
- Only after that does isRemote ask /v1/models with the key, as before.
- The route goes through lanGuard like OIDC's trade (proveAsked: POST,
exact path, no gateway key): from another machine only while shared,
past the allow list and rebinding check; corsGuard still judges its
Origin, the handler refuses anything fromBrowser, and an unknown id
from another machine counts against tooManyAuthFails. readOnlyRoutes
lists it (it carries no key and answers none).
seekAt is lanNeighbours again: the old /24 and this computer's own
private /24s, both behind the proof.
Not found, and so safe: a remote magpie from before this route (404), one
not shared (403), one reached through a port forward, NAT or a Docker
port (it sees another local address than the one dialled), and one behind
a proxy that needs the provider's headers. Each fails as before
fe61503e6 and the user types the new address.
Tests (local httptest servers only):
- TestRemoteMagpieKeyGoesToNoNeighbour, rewritten from 18a9a2d88's "no
address looked at": four impostors that list 200 for anything (no
proof route; a well-formed proof under another key; a garbled proof;
one relaying B's ask to the real magpie and handing back its proof)
are asked only the proof, never see the key or the provider's custom
header, and aren't saved; then the real magpie, last in the list, is
found and saved.
- TestRemoteProof: another key, nonce, address or port is another proof;
an IPv4-mapped IPv6 address is the same address.
- TestRemoteProveAnswersOnlyTheKeysHolder (gateway): from another
machine while shared, the key's holder answers the right HMAC and never
the key; an unknown id and a key turned off get 404; Origin, a Mozilla
User-Agent and Sec-Fetch-Mode are refused; not shared, 403.
- TestRemoteMagpieMovedIsFound now uses a real gateway key on A.
Run on mote at this tree (base 18a9a2d88):
- gofmt -l internal cmd: clean
- go vet ./internal/provider ./internal/gateway ./internal/access (darwin,
with and without -tags nogui), GOOS=windows go vet, GOOS=linux go vet
-tags nogui: ok
- go test -tags nogui -count=1 -timeout 45m ./internal/provider
./internal/gateway ./internal/access: provider ok (206s), access ok,
gateway FAIL on TestUnroutedHeldReportSaved only ("(under way)"),
the open #4300, a file this change doesn't touch; it passes alone
with -count=3 on mote.
Rebased onto 2000ae439 (its gateway.go change, the Antigravity format
check in models(), sits beside this one's route line). Rerun on mote at
the rebased head: gofmt clean; the same four vets ok; go test -tags
nogui -count=1 -run 'RemoteMagpie|RemoteProof|RemoteProve|LANNeighbours|
Dialable|ReadOnlyKeyEveryRoute|OIDCToken|Antigravity|KeyPage' over the
three packages: ok. The full suite was not run again.
Broken by hand, each red:
- isRemote without the proves check: the impostor with no proof route
is sent the key and the header, is saved, and the real magpie is never
reached.
- RemoteProof without the address: the relaying impostor passes, is
sent the key and saved; TestRemoteProof red too.
Not tried: a real look across two computers on a LAN (A on mote, B in
WSL as fe61503e6 did); a real Windows A; IPv6 link-local addresses (not
looked at). Residual: a user-chosen weak gateway key (8+ characters)
can be guessed offline by an impostor from its sha256; magpie's own keys
are 24 random bytes.
Push rejected once; rebased onto f4068ccc2 (proc only, none of this
change's files). Rerun on mote there: gofmt, the same vets and the -run
tests above: ok.
steven_4422 (Discord) runs magpie in Docker and Claude Code on the host.
The status line square writes the host's settings.json, which the
container can't reach, with a command naming a binary inside the container.
GET or POST /v1/magpie/statusline answers the line `magpie statusline`
prints, as text/plain, so the host needs only curl:
curl -fsS -m 1 -H 'Authorization: Bearer <key>' --data-binary @- http://<host>:3425/v1/magpie/statusline || true
Claude Code's stdin JSON (session_id) adds the model, as /v1/magpie/route
does; ?session= and ?only= work too. The renderer moved to
provider.StatuslineText, shared by the CLI and the endpoint. A caller that
isn't this computer needs a gateway key (lanGuard, unchanged; the handler
also refuses a non-local caller without one). A read-only key is allowed
(GET and POST in readOnlyRoutes) and gets the windows without the model; a
key held to budget, models or accounts sees only its own (scopeQuotas).
corsGuard and origin checks are untouched.
magpie web shows the command in Settings -> About (en, zh, zh-TW, ja, de).
Docs: reference.md, agent-wiring.md, gateway-routing.md, docker pages en/zh/ja.
Run at this head (rebased on d8b3749ef), on mote:
- go build, gofmt -l, GOOS=windows go vet and GOOS=linux go vet -tags nogui
on gateway, cli, provider: clean.
- go test: internal/gateway ok (a first full run failed once, 888s, name not
kept; the rerun had no failure), TestStatusline*, TestReadOnlyKeyEveryRoute,
TestStatuslineEndpointIsTheCLIsLine ok. internal/agent ok earlier, at the
pre-rebase base.
- TestCoreScriptBudget ok after shortening the new strings (no raise).
- GUI: statusline-remote (22: 2 engines x 5 languages x 1100/400, plus the
app without the row), public-url-default, i18n-keys, claude-statusline: all pass.
Broken by hand: model made wrong -> TestStatuslineEndpoint red; held-key
scope removed -> red; separator changed in the shared renderer ->
TestStatuslineEndpoint and cli TestStatuslineTellsRouteAndEveryAccount red;
the row's web check inverted -> the GUI test 0 of 22. Removing the
handler's own key check stays green because lanGuard refuses first (the
401 asserts hold through it).
Reds not from this change: cli TestEveryRouteHasACommandOrIsNamed
(GET /api/context/reply, from main), gui TestMainWindowCorners (red on
origin/main on mote), provider TestMoveToPlugin and TestMoveCutShort (red in
the full run, green alone).
Not tried: Docker or any container (not on mote or WSL); the real binary
from another computer over the LAN with a real Claude Code; the whole GUI
suite (running, 1182 files, finishes after the push); Windows and Linux
test runs.
prgrmrwy runs magpie on a home server and uses it from work through a
remote magpie (and DSH). The remote Codex card said "1 reset", but the
reset could only be used from the GUI of the computer that holds the
sign-in.
What changed:
- Gateway: POST /v1/magpie/quotas/codex-reset?user=<email>[&credit=<id>]
(Server.codexReset) spends one of that account's resets with
provider.SpendCodexReset. That is the Usage page's own code
(UseCodexResetCard, then AwaitAllowance), moved out of
internal/gui/usage.go so both use it. A reset can't be undone, so the
route needs an enabled gateway key with full access, from loopback too.
No key gets 401, and that covers every corsGuard exemption that has no
key: Origin null, app schemes, *.localhost and a missing Origin. A
read-only key gets 403 gateway_key_read_only (readOnlyGuard, which
readOnlyRefused now lists, and again in the handler). A held key gets
403 gateway_key_held, even one told quotas. The account must be named
(400 otherwise). One ask runs per account at a time (409). When the
reset is used, that card is read again.
- Remote client: UseRemoteCodexReset (remote_quotas.go) asks the remote
with the provider's key. remoteJSON's status mapping is shared through
remoteBody. A read-only key there is told as such, and a 404 as a
remote too old. With no answer in time it says the reset may have been
used, and it never asks again by itself. A remote Codex card now keeps
its Resets; a GLM team's (byWindow) and every check-in are still
dropped.
- GUI: "Use a reset" / "Use one..." show on a remote Codex card
(codexResetCard). They open the same in-app confirmation sheet, with a
line saying which computer's magpie uses it, and send the card's
provider to /api/usage/codex-reset. The remote's errors are put in the
user's words. New strings are in all 5 languages.
- DSH: no code here. Its provider plugin reads /v1/magpie/quotas/cards
and can call the new route with a full key.
- resetOutcome (a reset's result in words) moved from app.js into
resetask.js, the only place that says it, so the core's scripts stay
in TestCoreScriptBudget's 1,533,802 with no raise (1,533,003 after;
origin/main b967b1620 is 1,533,756).
- Docs: reference.md (remote quotas, gateway keys), gateway-routing.md
(read-only list, the route's admission), providers-accounts.md.
What was run (rebased on origin/main b967b1620, then on 2e4735f8f):
- mote, at the head before the rebase and the resetOutcome move:
go test -count=1 -timeout 45m ./internal/provider ./internal/gateway
./internal/gui at load ~300-450. provider ok. gateway: only
TestCompactionOverByteCapEveryTime (#4862). gui: TestCoreScriptBudget
(this change, 158 bytes over; fixed by the move), TestMainWindowCorners
(#3949) and TestGatewaySkewOfAnotherIsSaidNotQuit/own_build (#5053,
passes alone here and at b967b1620).
- mote, same run: 155 GUI files (reset|quota|usage-|panel-|i18n|budget|
remote|gui-|old-webkit|core-script|script-size), 1856 of 1904 pass.
- WSL (magpie-desktop), the 9 red files alone, at this change and at
origin/main b967b1620: this change 147 pass / 43 fail, main 146 / 44;
every test red here is red on main too: codex-auto-reset webkit de
(#4790), remote-magpie (#4398), usage-agents-hide (#3414), usage-fold
(#3415, #4790), usage-heatmap (#4718), usage-ledger (#5048).
codex-reset-lead (#5054) and panel-routing-providers (#5055) were red
only under mote's load and pass alone on both.
- mote, at this head: TestCoreScriptBudget and
TestGatewaySkewOfAnotherIsSaidNotQuit ok.
- WSL, at this head: account-every-reset, codex-resets-used, i18n-keys,
providers-reset-use, remote-codex-reset, reset-each-title,
reset-pick-card, reset-providers, quota-used-no-reset: 99 of 102 pass.
The 3 reds are providers-reset-use's 420px Windows cases ("a click
moved the page", #4873); that file alone is red on origin/main
b967b1620 too (3 of 40 there, 2 of 40 here).
- WSL, rebased on 2e4735f8f (main had changed internal/gateway): the new
tests and the read-only, CORS, LAN-guard, held-key, remote-magpie and
UseCodexResetCard tests in ./internal/gateway ./internal/provider ok;
core scripts 1,532,960 under 1,533,802; gofmt clean.
- Earlier on mote: TestCodexResetNeedsAFullKey,
TestRemoteCodexResetThroughTheGateway, TestRemoteCodexResetAnswers, the
read-only, CORS, LAN-guard, held-key and remote-magpie tests ok;
remote-codex-reset and reset-pick-card 20 of 20 (chromium and webkit,
5 languages, 900/390/440px). gofmt clean; go vet darwin, windows ok,
linux for provider and gateway.
Broken by hand:
- With the handler's key check turned off, TestCodexResetNeedsAFullKey
went red: "this computer, no key: 200 {code: reset}" and a reset was
spent.
- With codexResetCard put back to provider === "codex",
remote-codex-reset.test.cjs went red ("one Use, on the remote Codex
card"). On the old code the route doesn't exist, so the full-key case
gets 404.
Not tried:
- A real Codex reset spent between two real magpies: none was spent, to
keep the owner's resets. The ChatGPT backend is the fake from
codex_autoreset_test.
- DSH's plugin calling the route.
- GOOS=linux vet of internal/gui: it needs gtk4/webkitgtk, which neither
mote nor magpie-desktop has. Its change is usage.go only, and that was
vetted on darwin and windows.
Thanks to prgrmrwy for the report and the proposal.
joe21_eee (sywyyhykkk on GitHub) wrote this for an ESP32 screen that
shows each agent's requests live: started, each try, the first content,
fallback, done. Ported from their route-events branch (42e1fa43f) with
the changes below.
What a display gets (route_events.go):
- GET /v1/magpie/route-events/snapshot: cursor, active, routes (every
request the trace has that is still going).
- GET /v1/magpie/route-events?after=<cursor> (or Last-Event-ID): SSE,
one "route" event a change, id = cursor, from a 512-change ring under
trace.mu, so a short request is told step by step. 409
snapshot_required for a cursor not this process's or too old, "event:
reset" for a reader that fell behind, a heartbeat every 15s, a 10s
write deadline.
- A route is routeActivity, an allow list: trace id (base 36), time,
agent label, the provider of the seat the last try went to (never the
seat id, which names an account or a key fingerprint), model, attempt,
fallback, phase, status, failed, ms, ttft_ms. No session, account,
key, folder, prompt, reply or error text.
- firstToken.onFirst tells the first content as it comes (serve and the
ChatGPT backend's reads), written to an unexported Try.firstMs so the
full trace's TTFT is unchanged.
Changed from the branch:
- No new key type. The branch added an "sk-magpie-route-" key, its CLI
flag and its own Authenticate path through access, identifyCaller and
corsGuard. main has read-only keys now (readOnlyGuard), and the feed
is answered as /v1/magpie/usage is: this computer, and another machine
with an enabled key while shared; a held key is refused (refuseHeld).
Both GETs are in readOnlyRoutes, so the display gets
`magpie gateway-key add Screen --read-only`. A full key already reads
more than this (every call's usage). access, cli, cors.go and lan.go
are untouched.
- A route the trace drops unfinished (drop: an unrouted request's
stand-in once its own route begins; trim past twice traceKeep) is told
request_dropped and marked offFeed. The branch kept its own active map
that only "done" cleared, so a stand-in stayed going forever. The
snapshot is read from t.routes, no second map.
- A stream ends when the gateway stops serving (Server.streamsEnding,
closed first thing in ListenAndServe's drain). Before, an open stream
held srv.Shutdown for its whole drain, 15 minutes on a handover.
- Revocation is access.On(KeyID) (identifyCaller swaps the secret out
before handlers see it), asked at most once a second when there are
changes and at every heartbeat, and remoteKeyed for a remote reader. A
rotated key keeps its id, so its open stream goes on until it
reconnects (said in the docs).
Docs: gateway-routing.md "Route events for a display" and the
read-only key's route list; reference.md beside the usage API.
Run at the pushed head on mote (Go 1.26.8):
- At daaafeb6e (rebased on ffc4aa684): gofmt -l internal/gateway empty;
GOOS=linux go vet -tags nogui and GOOS=windows go vet of
./internal/gateway ./internal/access ok; go test -race -run
'TestRouteEvents|TestReadOnlyKeyEveryRoute' ./internal/gateway ok.
- At daaafeb6e, every package that imports the gateway: internal/agent,
browsermcp, cli, davsync, imagemcp, library, settingsapi, tui,
access and the root package ok. internal/gui: one red,
TestMainWindowCorners/macOS_26_SDK, which is #3949 (mote runs macOS
27; this change touches no GUI code).
- Before the rebase (eb779ce92 base; gateway and access are the same
at ffc4aa684): go build ./..., go vet, and the whole internal/gateway
package, -timeout 45m. All ok except TestCodexPoolSaysTheClientsVersion,
which is #4807 (red in a full package run on mote, passes alone; it
passes alone at origin/main bf05291e2 too).
- At the pushed head (rebased on 443e53d6b, which changed search.go):
gofmt, go vet ./internal/gateway and the -race run above again, ok.
- Not run: go test ./... in full. Other sessions' suites had mote at
load 60 to 120.
Broken by hand (each on mote, then restored), the test that went red:
- serve's onFirst line removed: TestRouteEventsLiveFallback.
- drop's request_dropped removed: TestRouteEventsDroppedRouteGoes.
- the offFeed check removed: TestRouteEventsDroppedRouteGoes.
- the streamsEnding case removed: TestRouteEventsEndWithTheGateway.
- refuseHeld skipped: TestRouteEventsTold.
- the access.On recheck skipped: TestRouteEventsReplayAndRevocation.
- the snapshot taken out of readOnlyRoutes: TestRouteEventsTold,
ReplayAndRevocation, LiveFallback.
- the seat's id told for its provider: TestRouteEventsReplayAndRevocation.
- the handler's own local/sharedWith gate removed: still green, since
lanGuard refuses another machine first when not shared. It stays, as
usage's does.
Not tried: an ESP32 or any real display, a real gateway with real
agents (tests drive httptest servers and fake upstreams), a handover
between two real magpie processes.
Co-authored-by: Junyu Zhou <feijifeibudao@gmail.com>
ferock on Discord: the community chat page's "use all of magpie's MCP
servers" gave a chat only the servers in library.json, never magpie's own
web search, image recognition or image generation. Nothing told an app
which of magpie's own servers are on, so the page couldn't add them.
GET /v1/magpie/mcp (OwnMCPPath, own_mcp.go) answers
{"servers":[{"name","title","path"}]} for the ones on now, each named
as its initialize names it: magpie-web-search while plugins/search serves
and something searches (canSearch), magpie-vision while a model sees
(seer: not Off), magpie-image while a model draws (drawer: not Off),
magpie-tools while plugins/tools serves and a plugin that is on gives a
tool (plugin.ToolsOn; a note that can't be read lists it). It holds no
secret, so a read-only gateway key may read it (readOnlyRoutes); it is
otherwise guarded as every /v1/magpie/* route is. It is in / "apis".
page-chat 0.1.7 (magpie-community/plugins) reads it in every route the
page takes its MCP list from (readMcp: the list, a chat's tools, a tool
call, the connection check). Documented in gateway-routing.md.
Run (mote, at e2a65cbc9 plus this change, before the rebase onto
2987f5e2b, which adds three commits in gateway/gui/provider that this
doesn't touch):
- gofmt -l: clean. go vet ./..., GOOS=linux go vet -tags nogui ./...,
GOOS=windows go vet ./...: ok.
- go test -tags nogui -timeout 45m ./... in a sandbox HOME: 81 packages
ok; internal/gateway ok. Two reds, neither in code this touches, both
filed: internal/gui TestSettingsSaveKeepsWhatItDoesNotSend (SearchAll,
#4514) and internal/update TestRelaunchOpenTriedAgain (#3881).
The first run, at d6e111638, also had TestReadOnlyKeyEveryRoute red on
the new route; it is in readOnlyRoutes now.
- At the pushed head (on 2987f5e2b): go vet ./internal/gateway and
-run 'OwnMCP|ReadOnlyKey|ClientPath|ServingGates' ok.
- TestOwnMCP* (5 tests) red on the old code by hand: the route taken
out, each answers 404.
- Real binary (go build -tags nogui, sandbox HOME, MAGPIE_ADDR
127.0.0.1:3591, a fake vendor listing gpt-image-1 and gpt-4o): the list
was magpie-image; tools/list on its path answered generate_image,
generate_video, generation_result; with vision and imageGen "off" in
settings.json the list was empty; a request with a foreign Origin got
403.
Not tried: image recognition and web search listed by the real binary
(the fake vendor's gpt-4o wasn't known to see offline, and no search API
was set up; the unit tests cover both); a real vendor; the GUI (no GUI
change); Windows and Linux runs (vet only).
zytszone on X runs one magpie's gateway for a whole department, whose
people can't be given the admin's app. Each now opens the gateway's /me
at the address they reach it at, types the gateway key they were given,
and sees that key's own name, limits and what is spent of them, its
usage over today, 7 and 30 days with its most used models, the models
it may use, and copy-ready setup for Claude Code (settings.json env),
Codex (config.toml provider, /v1, responses), any OpenAI-compatible
client and a curl test. The base URL is the address the page was
opened at, never 127.0.0.1; the key is a placeholder until "Put my key
in the setup" is ticked. Strings in en, zh, zh-TW, ja and de.
- GET /me (keypage.html, embedded) is the same bytes for everyone and
holds no data, so lanGuard serves exactly GET/HEAD /me (no escaped
path) to another machine without a key, after the allow list, the
rebinding check and the not-shared 403, which still apply. Its CSP
loads nothing from elsewhere, posts no form and forbids framing.
- GET /v1/magpie/me (keyInfo) answers access.Caller's own key only. No
key, a wrong one, one turned off and magpie's own token are 401
alike; ?key= is refused 400 so a key never sits in an address or a
log. It names no account, other key, provider or secret; its models
are /v1/models' for that key (keyAllowed), none for a read-only key.
The page sends the key as Authorization to its own origin with
credentials omitted and keeps it in sessionStorage only.
- Both are in readOnlyRoutes, /me in clientPrefixes (magpie web's page
port), and Gateway -> Gateway keys shows the page's address
(MAGPIE_PUBLIC_URL, else the LAN address offered) with a Copy, while
shared and with a key. Docs: gateway-routing.md, reference.md.
Run:
- mote: go build -tags nogui ./...; go vet -tags nogui gateway+gui;
GOOS=linux and GOOS=windows go vet -tags nogui ./internal/gateway;
go test -tags nogui -count=1 ./internal/gateway ./internal/gui: ok
(gateway 732s). gofmt -l clean. Rebased onto 18b63fe5f after that;
there: build, vet, and the KeyPage, read-only, client path, page
port, LAN guard, caller usage and core script budget tests ok.
- Key page Go tests, through the real lanGuard(Handler()) chain, from
the network and from loopback: the key sees its own name, usage, top
model, limits and allowed models and nothing of Bob, Bob's secret,
the upstream key or magpie's token; no key, wrong key, turned-off key
(Bearer and x-api-key), magpie's Token, ?key=, Origin null, an
evil.localhost page, a foreign origin with a good key and a rebound
Host all get nothing; the page opens without a key, not on POST,
/me/x or /%6De, and not while unshared; a read-only key gets no
models.
- GUI, key-page.test.cjs: Chromium on mote and WebKit on the Linux box
(magpie-desktop), 390px, all five languages, 24 of 24; i18n-keys ok.
The 46 Gateway/caller-key GUI files and i18n-keys on the Linux box,
both engines: 645 pass, 11 red at concurrency 4. Serially 6 stay red,
and the same tests are red on origin/main a0cb8b646 there:
api-key-theme "system", gateway-key-limit webkit en/zh,
connect-snippet-shell, gateway-key-models (#4120), phone-rows (#4218).
Broken by hand, each red then restored: lanGuard's /me exemption
removed (page 401); the KeyID check removed (no key/wrong/off/Token got
data); keyAllowed dropped (Alice saw plan/m2); the RawPath check dropped
(/%6De served); the ?key refusal dropped (200 with Alice's data).
Not tried: a real Claude Code or Codex pointed at a shared gateway with
the page's snippets; WebKit on macOS (every WebKit launch on mote hangs
right now, for every session, a bare launch included); the whole GUI
suite and a full go test ./... (one suite per machine; mote is running
other sessions' suites).
Steven's ESP32 desk display polls magpie (Docker, on his LAN) every 15s
on GET /v1/magpie/quotas and /v1/magpie/usage and never sends a model
request. Only a key held to nothing was told the usage summary, so the
key kept in the device's flash had to be one that could spend every
account.
A gateway key can now be read-only (access.Key.ReadOnly):
- `magpie gateway-key add <name> --read-only`, `magpie gateway-key access
<id> [read-only|full]` (`gateway-key --help` lists it; `list` has an
ACCESS column), and "Make read-only" / "Give full access" in the key's
menu in Gateway -> Gateway keys, with a "Read only" tag on its row.
- readOnlyGuard (internal/gateway/readonly.go), after callerGuard and
before withCaller/keyLimited, judges the pattern ServeMux.Handler routes
the request to. A read-only key is answered GET /, /v1, the quotas,
their history and cards, the usage summary and its requests, its limit
and the concurrency. Every other route is refused with 403
gateway_key_read_only: every model route, count_tokens, the Responses
WebSocket's upgrade, every MCP server, Codex's and Gemini's backends,
/v1/models and the Ollama routes, the catch-all, the trace and route,
debug profiles, and every write (usage ingest, quotas refresh). It is
default deny, so a route added later is refused until it is classified.
- The key is held to nothing else, so heldKey leaves it alone: it reads the
usage summary and every account's quotas, as a key held to nothing does.
None of those routes holds a key's secret.
- The sharing key can't be made read-only, since magpie gives it to its own
agents (LANSecret). Update refuses it, and the GUI item is off with why.
Older versions: a magpie from before this commit doesn't know `readOnly`
and treats such a key as a full one, so downgrading magpie widens the key.
Tests:
- TestReadOnlyKeyEveryRoute (internal/gateway/readonly_test.go) takes the
patterns from the router itself (routes() records each HandleFunc). It
fails when a pattern is in neither readOnlyRoutes nor its refused list.
It sends every refused pattern, by each method it takes, from
192.168.1.9 and from loopback, plus a WebSocket upgrade and an unclean
chat path, and expects 403 gateway_key_read_only with the upstream never
reached. It checks that every allowed route answers, that no body holds
any key's secret or the upstream key, that the usage summary names the
other key's use, and that a full key and a key made full again still
reach the model.
- TestReadOnlyKey (access) covers add-key and access-key on and off,
Authenticate, List, and the sharing key refused.
- TestGatewayKeyCLIReadOnly covers --read-only before and after the name
and beside --key, access, the list column, bad values, and --help.
- gateway-key-readonly.test.cjs runs Chromium and WebKit, 1100 and 420px,
in en/zh/zh-TW/ja/de. It covers the tag, both menu items and what they
post, the status line, the sharing key's item off with its why, no
scroll on click, no sideways scroll, no select, and no left stripe.
gateway-card.test.cjs now expects the menu's 4th item.
- TestClientPathCoversHandler takes the patterns from routes() instead of
parsing Handler's source, which moved into routes().
Broken by hand:
- readOnlyGuard passing everything: TestReadOnlyKeyEveryRoute red (103
lines, /v1/models 200 onward).
- A new `POST /v1/new-thing` route in routes(): red, "in neither
readOnlyRoutes nor readOnlyRefused".
- The GUI item not off for the sharing key: gateway-key-readonly red 10 of
10 in Chromium.
Run at the pushed head (on origin/main 0911a65e7), on mote: TestReadOnly*,
TestHeldKey*, TestClientPathCoversHandler, TestGatewayKey*, TestCaller*
in access, cli and gateway ok; TestCoreScriptBudget ok; on Linux
(wsl-run, both engines) gateway-key-readonly, gateway-card, i18n-keys,
gateway-caller-keys and gateway-key-quotas 68/68.
Full Go suite on mote (macOS) at the same change on origin/main
dca3e2d71 (94630237d), -timeout 45m: 78 packages ok; internal/gateway
red only on the four TestAntigravityTurned* and
TestCodexSpentGrokFailingIsTold (red the same at origin/main, #4362);
internal/gui red only on ten AppKit window tests that hit their 30s
bar while mote's launchd throttled every app launch (#4125).
Run on mote (macOS) on origin/main dca3e2d71:
- go test ./internal/access ./internal/cli ./internal/gateway: access ok;
cli red only on TestLibraryMCPHub's TempDir cleanup (#4140); gateway
red only on the four TestAntigravityTurned* and
TestCodexSpentGrokFailingIsTold, red the same at origin/main (#4362).
TestReadOnly*, TestHeldKey*, TestClientPathCoversHandler,
TestGatewayKeyCLIReadOnly pass.
- TestCoreScriptBudget ok (no budget raised). gofmt clean; go vet
darwin (access, cli, gateway), GOOS=windows ./... and GOOS=linux
-tags nogui ./... clean.
- GUI, earlier at 807048470 on mote: gateway-key-readonly,
gateway-key-quotas, i18n-keys, gateway-card, api-key-theme,
gateway-connect-keys and gateway-caller-keys 34/34 in both engines.
At this tree mote's WebKit hung at launch for every test (#4125), so
the 43 gateway-*/key-*/api-key-*/caller-*/menu-*/i18n-* files ran on
Linux (wsl-run, both engines): 501 of 514. The reds in api-key-theme,
gateway-key-limit, gateway-key-models, key-replace and menu-input-scroll
are red the same at origin/main e8d42c02d (#4120, #3523, #4081, #4126,
#3402); gateway-keys-empty's WebKit wait was red 1 in ~13 runs here and
0 in 4 at main, filed as #4383 (this change doesn't touch its path).
- Full Go suite on Linux (wsl-run, at 807048470 with this change): reds
only where Linux can't build the GUI (no gtk4/webkitgtk) and in
internal/agent's install tests (#4033) and the gateway reds above,
each red the same at origin/main dca3e2d71; plus
TestClientPathCoversHandler, which parsed Handler's source and is now
read from routes() (fixed here).
Not tried: a real ESP32 or Docker magpie; a remote client against a
running gateway (only httptest through lanGuard/Handler); the Windows
test runs (vet only); the whole GUI suite (mote's WebKit hung, #4125).