An images request (/v1/images/edits, /v1/images/generations) may name a
reference image by URL. For a model that takes the image as bytes (an
images API's multipart edit, Gemini's own API, Code Assist), magpie
downloaded the URL itself with the gateway's client, to any address and
through any redirect, and sent what came to the vendor as the image.
fetchPicture, the one place a caller's URL is downloaded (all three draw
paths go through it), now uses publicClient (image_fetch_guard.go):
- the host is resolved and every address must be public (publicAddr:
not loopback, RFC 1918, fc00::/7, link-local incl. 169.254.169.254,
CGNAT 100.64/10, unspecified, multicast, documentation/reserved
ranges, Teredo, nor an IPv4-mapped, NAT64 or 6to4 form of one);
- the request is pinned to the address checked (Host and TLS
ServerName keep the name), so a name resolving differently later
changes nothing; a direct dial is checked again in the dialer's
Control on the address actually connected;
- through a proxy (magpie's, the provider's, the system's) the proxy is
chosen by the name and sent the pinned address (CONNECT or SOCKS);
a plain http:// URL through an HTTP proxy is asked for by address in
Host too, since Go writes the absolute URI from Host;
- redirects (at most 5) go through the same transport; only http(s);
no keep-alives; the existing 64 MB / stall / 5-minute limits stay;
- what comes back must sniff as image/*, else 400 without the body.
Policy: a request from this computer (local(): loopback, no proxy or
tunnel headers, and not fromBrowser) keeps downloading from anywhere,
since its sender reaches those addresses already and a local agent may
serve images on localhost. Everyone else, a gateway key's holder
included, is held to public addresses. Vendor-returned image URLs
(FetchImage for b64_json, imagemcp, video content) are unchanged: they
are the vendor's, not the caller's. No other gateway path downloads a
caller's URL: chat/Responses/Anthropic/Gemini image URLs are passed on
for the vendor to fetch. Documented in docs/subsystems/gateway-routing.md.
Run:
- go test -race -count=3 -run 'PublicAddr|EditImageURL|PrivateDialer'
- broke by hand, each went red: old client in fetchPicture (all three
e2e tests), no Unmap (::ffff:100.64.0.1), no pinning (proxy test
sees the name), no resolve check (redirect to 192.168.1.10 through
the proxy served), no dialer check, no image sniff, browser allowed
- go test -tags nogui ./internal/gateway/... (full)
- gofmt -l; go vet -tags nogui for darwin, GOOS=linux, GOOS=windows
- not tried: an https:// image through a real HTTP or SOCKS proxy