dhanyqaz on Discord (gateway in Docker on a VPS behind a tunnel, one
gateway key per client): the Image MCP server's file URL
/mcp/magpie/image/files/<name> opened only with the key that made it, so
a link a model relayed to a person was always refused in a browser (no
key 401, another key 404).
The URL handed out now carries ?t=<exp>.<sig> (imageFileToken):
HMAC-SHA256 of the file's name, its expiry (the same hour) and the making
key's id, under a secret made at the first file and kept only in memory,
so a restart, which loses the files, loses the links. It names neither
the key nor its id. lanGuard lets a keyless GET or HEAD of a file path
with a t through (imageTokenAsked), after the allow list and sharing are
judged; imageMCPFile serves it only when the token is that file's,
unexpired, and its key still on (access.On, read outside the store lock).
Anything else is the 401 a keyless request gets; a wrong key with a
token is still 401, a web page's Origin still 403, POST still refused,
the header-key path as before. Rotating a key keeps its id, so its links
stay good for the rest of their hour (they never held the secret);
turning it off or removing it ends them at once. The URL's base is
imageMCPBase as before (MAGPIE_PUBLIC_URL, else the request's host).
Docs: gateway-routing.md's image server section.
Not changed: generate_video's /v1/videos/<id>/content still needs the
key; same class, filed as #4462.
Run at fe3ad3917 on mote: gofmt -l clean; GOOS=linux and GOOS=windows
go vet -tags nogui ./... ok; go test -tags nogui -count=1 ./internal/gateway/
./internal/access/ ok (497s, 2s). New TestImageMCPFileLinkOpensWithoutKey;
TestImageMCPGuarded and the draws test now check the bare URL keeps the
old rules.
Broken by hand (red each): no lanGuard pass-through (no header -> the
reporter's 401); no expiry check (an expired token opened it); no
key-on check (a turned-off key's link opened); key id left out of the
HMAC (another key's token opened it). Dropping the handler's own
sharing check stays green: lanGuard refuses unshared first, so it is
defence in depth only.
Real run (before the rebase, same change) on mote: sandbox HOME, fake
upstream on 3561, magpie serve on 0.0.0.0:3562 with MAGPIE_PUBLIC_URL,
an image made through the MCP generate_image call. The tool gave
https://<public>/mcp/magpie/image/files/<name>.png?t=…, no key in it.
curl to the LAN address and with a tunnel header: link, no header 200
(bytes = upstream's PNG), HEAD 200, another key + link 200; bare URL:
own key 200, no header 401, other key 404; tampered sig, moved expiry,
token on another name, POST, wrong key + link 401; foreign Origin 403;
after `gateway-key remove` 401.
Full suite not run at this head; runs after push.
Not tried: a real browser click, and the reporter's Docker + tunnel
setup itself (the tunnel was a forwarding header).