ac4af582301a4e8a29245dbba767eba31334ddf9
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c6bdc172a0 |
netguard: a fake-IP resolver's own AAAA beside its fake A is left out, not refused
jiezhengj (Discord, 11-08): under Clash Verge Rev's TUN (mihomo
1.19.33, enhanced-mode fake-ip, fake-ip-range 198.18.0.1/16) every
web_fetch of `magpie mcp search` answered "it is at a private address".
#2593 already lets a name whose every answer is in 198.18.0.0/15 through,
so that wasn't it. Clash Verge Rev writes dns.ipv6: true and
fake-ip-range6: fdfe:dcba:9876::1/64 into its default config (and fills
in 2001:2::/64 when IPv6 is on without one), and mihomo then answers
AAAA from that pool too (dns/middleware.go withFakeIP, read at
v1.19.33). The resolver's answer was 198.18.x.y beside fdfe:dcba:9876::z,
the ULA is private, a fake answer beside a private one is refused, so
every name failed.
netguard.FakePaired names that AAAA: an IPv6 address in fc00::/7 or
2001:2::/48 while the same answer holds an IPv4 one in 198.18.0.0/15.
It is dropped where Loon's paired AAAA is dropped (dropLoon in the
gateway's publicTransport, iconIPs for a provider's icon, the two
places that share netguard), and the fake A is judged and pinned in its
place. 2001:2::/48 (RFC 5180 benchmarking) joins Public's special ranges;
it wasn't covered by 2001::/32 and passed as public.
Why this opens nothing new: the AAAA is never dialled. What is dialled
is the fake A, exactly as when the resolver answered the A alone, which
#2593 already allows: an address in 198.18.0.0/15, which no host on a
normal network uses, so without a TUN it goes to the default route and
reaches the internet or nothing. A hostile DNS that pairs 198.18.0.9
with fd00::<a LAN host> gets the 198.18 address dialled, never the LAN
one. Through a proxy on this computer the proxy gets the name, as for a
pure fake answer; a hostile resolver could already give a proxy another
answer for that name than it gave magpie, so the pairing adds no route.
What stays refused (tests below): a ULA or 2001:2:: alone or beside a
real A, a fake pair beside 10.0.0.1 or ::1, a fake A beside a public
address, and ULA / 2001:2:: / 198.18 address literals.
Ran (on mote; whole packages at base
|
||
|
|
240f3eb4c5 |
gateway: a name a fake-IP resolver answers is fetched through its TUN or a local proxy (#2593)
With Clash's TUN fake-ip (Clash Verge Rev on Windows, TomXPRIME), Surge's enhanced mode (h4rk8s) or Loon on, the system resolver answers every name in 198.18.0.0/15, which the download guard (image_fetch_guard.go) listed as special. So web_fetch, a caller's image (fetchPicture), a vendor's image or video by URL and generate_image's download (imagemcp) refused every URL as "a private address". All of them go through publicTransport; nothing else uses it. What changed: - The address rule moved into internal/netguard (Public, FakeIP, LoonPaired), shared by the gateway's guard and a provider's icon (icon.go's publicIP is now netguard.Public or FakeIP, as #252 meant). The icon guard gets the gateway's stricter list with it (Teredo, 240/4, NAT64 and 6to4 forms of a private address are refused there too). - publicTransport: a name (never an address literal) whose every answer is in 198.18.0.0/15 is fetched. With no proxy (pure TUN) the fake address is pinned and dialled, and the dial guard lets that one address in, no other. Through a proxy on this computer (loopback or localhost) the proxy is given the name, never the fake address: h4rk8s showed a real Surge CONNECT by name works and by the 198.18 address doesn't. A plain http:// request's Host to that proxy is the checked name, never the caller's own Host. Through a proxy elsewhere it is refused. - An answer with any other address beside the fake ones (private or public) is judged as before, so fake + 192.168.x is refused; loopback, RFC 1918, link-local with 169.254.169.254, CGNAT, unspecified, multicast and documentation stay refused; every non-fake answer is still pinned; redirects are re-checked as before. - Loon's synthesized AAAA (fd27:712::/96 holding an A answer of the same reply) is left out and the A answer judged in its place, as icon.go already did, so a Loon answer isn't refused as fc00::/7. - docs/subsystems/gateway-routing.md says all of this, and the trust it asks for: where a fake-IP name really goes is decided by the fake-IP resolver, which magpie can't see, so a name pointing at the user's network is reached if that resolver's rules send it there. The icon path already accepted this (#252). Credit: ggbdpq found the cause and wrote both patches on the issue (hunt/2593-webfetch-fakeip, then hunt51-a-fakeip-proxy: the fake-only, loopback-proxy, name-not-literal predicate and its test shapes, which this follows); h4rk8s's real Surge comparison showed the pin had to go for a proxy; TomXPRIME's Windows report showed pure TUN needs the direct dial. Run (darwin/arm64, worktree rebased on origin/main |
||
|
|
ea3dee96a8 |
gateway: a URL magpie didn't choose is downloaded from public addresses only, wherever the request came from
|
||
|
|
5241de909a |
gateway: an image URL a caller sends is downloaded only from public addresses
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 |