[PR #8772] [MERGED] fix(server): keep redirected outbound requests within the caller's trust #8795

Closed
opened 2026-11-07 17:39:45 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8772
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/4/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/hardening-safe-fetch-redirects


📝 Commits (6)

  • d3d94f0 fix(server): keep redirected outbound requests within the caller's trust
  • 961b50c fix(server): judge redirect trust by the address a hop connected to
  • 9212260 fix(server): judge local-looking redirect hops by the address they reached
  • 25b829a fix(server): trust a redirect hop only on the built-in local ranges
  • a254296 fix(server): let a remote redirect hop keep the caller's non-local allowances
  • a7543a9 fix(server): refuse remote redirects into 192.0.0.0/24 with local URLs on

📊 Changes

5 files changed (+557 additions, -31 deletions)

View changed files

📝 packages/server/src/routes/bot-browser-datacat.routes.ts (+13 -4)
📝 packages/server/src/routes/bot-browser-janny.routes.ts (+16 -5)
📝 packages/server/src/utils/security.ts (+139 -22)
➕ scripts/regressions/bot-browser-upstream-fetch.regression.ts (+58 -0)
➕ scripts/regressions/safe-fetch-redirect-local-trust.regression.ts (+331 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #8769

Why this change

Some outbound requests are allowed to reach loopback, mDNS or local-network addresses: the user configured a local model server, image backend or TTS server, or turned on a *_LOCAL_URLS_ENABLED switch (on by default for providers on Android). That trust is meant only for the server the user chose. Until now, safeFetch checked every redirect hop against the caller's original allowances, so a remote service's redirect inherited them as well. The repository already refuses this for image result URLs, which must not inherit provider trust. Whether a hop counts as local must also come from the address the request actually reached. It must not come from a separate DNS lookup made afterwards, or from how the hostname is spelled. Names ending in .local, .internal or .localhost are answered by DNS or mDNS and can point anywhere; localhost itself is always pinned to loopback. "Local" also has to mean the built-in loopback and local-network ranges, not the broader reserved-address deny-list. That list also covers VPN fake-IP answers (198.18.0.0/15), test and multicast ranges, and any range an operator trusts for sign-in through TRUSTED_PRIVATE_NETWORKS. Separately, the DataCat and JannyAI Card Browser requests were the last catalog calls still using plain fetch. Plain fetch follows redirects with no address checks and reads replies with no size limit; every other Card Browser provider goes through safeFetch.

What changed

  • Stops working: a remote AI, image, TTS, speech-to-text or RunPod service can no longer redirect a request to a loopback, .local or local-network address. This now fails with 'Refused to fetch ...'. It holds with PROVIDER_LOCAL_URLS_ENABLED or IMAGE_LOCAL_URLS_ENABLED on, on Android, and for image/TTS backends that always allow local URLs. Requests sent straight to a local server you configured still work. Redirects between local servers still work (for example localhost to 127.0.0.1, a LAN host or .local host moving from http to https, including dual-stack LAN hosts), and so do redirects between remote services.
  • Whether a redirecting server is local is decided from the address the request actually connected to, never from its hostname. Only the built-in loopback, private (RFC 1918), link-local, IPv6 ULA and CGNAT/Tailscale ranges and the unspecified address (0.0.0.0 or ::) count as local. A server counts as remote if it was reached through the well-known NAT64 prefix or a VPN fake-IP address (198.18.0.0/15), if its address is only in TRUSTED_PRIVATE_NETWORKS, or if it is a named server reached through an HTTP(S) proxy or a caller's own dispatcher. With local URLs allowed, a remote server's redirect keeps the caller's other allowances and loses only local trust. It is refused when the target is a localhost, .local, .internal or .localhost name. It is also refused when the target resolves to an address in any of these ranges: loopback, private, link-local (including cloud metadata), ULA, CGNAT, 0.0.0.0/8, or 192.0.0.0/24 (464XLAT and DS-Lite addresses on this device or its router, and a legacy cloud metadata endpoint). The same applies to an IPv4-mapped or IPv4-compatible form of one of these, and to a NAT64 address that embeds one. Redirects to other remote services are followed, including services answered from fake-IP or NAT64 addresses. A redirect target that does not resolve locally is followed only when an env proxy carries the request, because the proxy looks the name up itself. Sent directly, it is refused. A NO_PROXY host is refused when it connects rather than being looked up again. Without local URLs (the desktop default), a remote server's redirect is checked against the full reserved-address deny-list, with no loopback or mDNS exemption.
  • With local URLs allowed, a server addressed by DNS name, including .local, .internal and .localhost names, is now resolved once and connected through its first IPv4 address (IPv6 if it has none), the same way desktop provider calls and localhost are already handled. Before, Node's default connection handling was used.
  • DataCat Card Browser requests stay on datacat.run with no redirects, and replies are capped at 10 MiB.
  • JannyAI search requests stay on search.jannyai.com with no redirects. The JannyAI search-token page scrapes (direct and through corsproxy.io) now check every redirect hop's address and are capped at 8 MiB.
  • Two regressions cover this. One covers redirect trust in safeFetch: .local and .internal names on remote addresses, fake-IP and TRUSTED_PRIVATE_NETWORKS hops, NAT64, a 0.0.0.0 server, and a hop sent through a caller's dispatcher. The other covers the DataCat and JannyAI routes.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • In the app's Card Browser, check that DataCat browse, search, tags, character detail and download still load against the live datacat.run API.
  • In the app's Card Browser, check that JannyAI search and character detail still load, and that GET /api/bot-browser/janny/token?force=1 still returns a scraped token rather than only the built-in fallback.
  • Check that a local model server (Ollama, KoboldCPP or LM Studio on localhost) still generates replies, and that a LAN server addressed by DNS name with PROVIDER_LOCAL_URLS_ENABLED=true does too, including one behind a reverse proxy that redirects http to https.
  • Check a LAN server whose DNS name has both a private IPv4 and a global IPv6 address (common on IPv6 home networks): it should still connect, and its http-to-https redirect should still be followed.
  • Check that a local image backend (ComfyUI, SwarmUI or SD WebUI on loopback or a LAN name) still generates images and saves results, and that PocketTTS on a LAN name still speaks.
  • Check on Android, where PROVIDER_LOCAL_URLS_ENABLED is on by default, that a remote provider such as OpenRouter still works, both streaming and non-streaming.
  • Check that a setup with NODE_USE_ENV_PROXY=1 and HTTPS_PROXY set still reaches remote providers through the proxy, and NO_PROXY LAN hosts directly.
  • Manually verify that a local provider addressed by a .local mDNS name (e.g. http://gpu-box.local:5001) still connects and follows an http to https redirect on itself, both with PROVIDER_LOCAL_URLS_ENABLED off (the default) and on.
  • Manually verify that a provider reached by a host.docker.internal-style name still works with PROVIDER_LOCAL_URLS_ENABLED=true.
  • Manually verify, with NODE_USE_ENV_PROXY=1 and HTTPS_PROXY set, that a .local provider host that is not in NO_PROXY still loads a direct request. Then verify that its http to https redirect on the same .local name is refused ('hostname ... is local or reserved'), and that adding the host to NO_PROXY makes that redirect work again.
  • Manually verify on Android with a fake-IP VPN app in TUN mode (Clash, Surge or sing-box), that direct provider requests still work. Then check that a provider or image CDN redirect to another remote host is followed, for example an image result URL that redirects to a CDN.
  • Manually verify on Android with a fake-IP VPN in TUN mode that a provider redirect to a LAN address or to localhost is still refused with 'Refused to fetch ...'.
  • Manually verify on Android on an IPv6-only mobile network that uses 464XLAT that remote providers still work, both streaming and non-streaming, with PROVIDER_LOCAL_URLS_ENABLED on (the default).
  • Manually verify with NODE_USE_ENV_PROXY=1, HTTPS_PROXY set and local DNS that cannot resolve the provider's redirect target (for example a corporate split-DNS setup) that, with PROVIDER_LOCAL_URLS_ENABLED=true, a remote provider's redirect to another remote host is followed through the proxy.
  • Manually verify on an IPv6-only network with DNS64 (where IPv4-only providers resolve into 64:ff9b::/96) that, with local URLs on, a provider redirect to another remote host is followed.
  • Manually verify that, with PROVIDER_LOCAL_URLS_ENABLED=false (the desktop default), a provider redirect into a reserved range is still refused as before.
  • Manually verify that a local server configured as http://0.0.0.0: with PROVIDER_LOCAL_URLS_ENABLED=true still follows a redirect to itself.
  • Manually verify that setting TRUSTED_PRIVATE_NETWORKS to a narrower list (for example only 10.0.0.0/8) does not stop a 192.168.x.x LAN provider from redirecting to itself.

Agent-run checks (for reference; each regression was shown to fail without its fix):

  • node ./scripts/pnpm-runner.mjs build:shared: succeeded

  • node ./scripts/run-regressions.mjs --filter safe-fetch-redirect-local-trust: PASSED at 961b50c873 and again at 25b829a4ce. With the d3d94f0236 security.ts it FAILED on the dual-stack case ('Refused to fetch https://nas.test:11434/v1/models ...')

  • Temporary per-case copy of that regression (zz-tmp-proof-relay.regression.ts), run with the earlier security.ts and again with the fix, then deleted: Before: relay.test and nat64.test redirects to loopback were FOLLOWED under both local-URL policies (4 extra /blocked hits on loopback). After: all 4 refused, relay.test looked up once, only the 4 exp

  • Temporary real-connection probe (zz-tmp-real-pin.regression.ts), then deleted: PASSED: an allowLocal DNS name with [::1, 127.0.0.1] records reached an IPv4-only server through the pinned IPv4 record, with one DNS call, and followed its local redirect

  • node ./scripts/run-regressions.mjs --filter <file> --concurrency 1 for each of the 109 regressions that reference utils/security, safeFetch, llmFetch, base-prov: 109/109 passed (run after the source change; the only later edit was a comment in the test file, and that regression was re-run and passed)

  • node ./scripts/run-regressions.mjs --filter security: 32/32 passed (also at 25b829a4ce)

  • Follow-up 25b829a4ce, with the 9212260be7 security.ts restored: FAILED on the fake-IP case ('fakeip.test cannot redirect to loopback') and, in a throwaway copy, on the TRUSTED_PRIVATE_NETWORKS case; both pass with the fix. With the 0.0.0.0 branch disabled, the 0.0.0.0 server case FAILED.

  • node ./scripts/run-regressions.mjs --filter bot-browser: 4/4 passed

  • node ./scripts/pnpm-runner.mjs lint in packages/server (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activity.json): exit 0

  • npx tsc -p <scratchpad tsconfig covering the two new regression files, same lib/types as the repo's regression tsconfig>: exit 0

  • npx prettier --write / --check on all 5 changed files: all pass

  • eslint: not applicable: ESLint covers only packages/client; the server and scripts lint step is the tsc run above

  • Follow-up a2542969c0/a7543a9fe3 (Dottore LOW: remote fake-IP redirects): node ./scripts/run-regressions.mjs --filter safe-fetch-redirect-local-trust: PASSED; with the 25b829a4ce security.ts it FAILED on fake-IP to fake-IP, and with the a2542969c0 security.ts it FAILED on the 192.0.0.4 redirect. --filter security 32/32, fetch 6/6, proxy 4/4, provider 13/13, image 28/28, loopback 2/2, audio 14/14, tts 13/13, bot-browser 4/4; server lint exit 0.

Independent adversarial review: changes, 2 issue(s), all addressed in a fix-up pass. Local CodeRabbit review then raised 3 issues (trust range, a wording error, the proxy caveat); all three were accepted and fixed in 9212260be7 and 25b829a4ce. A second local CodeRabbit pass on those commits raised 2 more: the remote-to-remote redirect finding is fixed in a2542969c0 for fake-IP targets, while its suggestion to also follow redirects to .local names is rejected (a remote hop redirecting to a .local name is the case this PR closes, since mDNS can answer it with a LAN host); the request to split the loopback-hit assertion is rejected because the single assertion already lists every expected hit in order, including the 0.0.0.0 case. Dottore's later LOW finding (remote fake-IP redirects refused with local URLs on) is fixed in a2542969c0, and an adversarial review of that fix found 192.0.0.0/24 missing from the refused targets, fixed in a7543a9fe3.

Known limits and risks:

Behaviour changes:

  • With local URLs allowed (Android providers by default, ComfyUI/SwarmUI/A1111, PocketTTS, *_LOCAL_URLS_ENABLED), a hop addressed by DNS name, including .local, .internal and .localhost names, is now resolved once and pinned to one address. The hop the caller configured is pinned IPv4 first; a remote hop's redirect target is pinned to its first record in resolver order. Previously it used Node's default connection handling, which could fall back across every record. A host that publishes an IPv4 record that cannot be reached, but serves on IPv6, would now fail to connect. Desktop provider calls already work this way.

  • Those pinned hops get a per-request connection that is closed after the response, instead of the shared connection pool. That costs a new TCP/TLS handshake per request for DNS-named servers in local-URL mode. IP literals and localhost are unchanged.

  • A hop whose connected address is unknown counts as remote, so its redirects cannot reach local addresses. That covers a hop carried by an env proxy, a name that does not resolve locally, and a hop sent through a caller's own dispatcher (no production caller passes one). Behind an env proxy, a .local, .internal or .localhost host that is not in NO_PROXY cannot follow even an http-to-https redirect on its own name; adding it to NO_PROXY is the workaround.

  • Only the built-in loopback, RFC 1918, link-local, ULA and CGNAT/Tailscale ranges, plus exactly 0.0.0.0 and ::, count as local when deciding whether to trust a redirecting hop. VPN fake-IP hops (198.18.0.0/15) are remote. With local URLs on (the Android provider default), a fake-IP hop's redirect is refused when the target is a local-looking name or an address in the local ranges. It is followed otherwise, including to another name the VPN answers with a fake-IP address. A fake-IP address does not show where the VPN app will connect, so for those targets the VPN app's routing decides, as with an env proxy. A name the VPN routes to a local server, or the VPN's own TUN address, can still be reached. Without local URLs (the desktop default), fake-IP addresses were already refused and still are.

  • A remote hop's redirect target is refused on a slightly wider set than the set that makes a hop trusted: all of 0.0.0.0/8, all of 192.0.0.0/24 (464XLAT, DS-Lite and a legacy cloud metadata endpoint), IPv4-compatible IPv6 forms such as ::7f00:1, and NAT64 addresses that embed one of the refused IPv4 addresses. If a DNS filter answers a provider's redirect target with 0.0.0.0 or ::, that redirect fails, even behind an env proxy.

  • With local URLs on, a redirect target that does not resolve locally is followed only when an env proxy carries the request. The proxy looks the name up itself, so the app cannot check where it leads, as with any proxied request. Without a proxy, through a caller's own dispatcher, or for a NO_PROXY host, that target is refused.

  • Checks are by address range only. An address this machine holds outside those ranges, such as its own global IPv6 or public IPv4 address, is not recognised as this machine. This is unchanged and applies to the desktop deny-list too.

  • An address that is only in TRUSTED_PRIVATE_NETWORKS no longer makes a hop local. This matches isReservedIp's existing rule that the sign-in trust list does not change outbound checks. With local URLs on, a remote hop may redirect into such a range, as it may to any public address. Without local URLs it stays refused. When deciding whether to trust a hop, all of these count as remote: TEST-NET, multicast, class E, 192.0.0.0/24, deprecated IPv4-compatible IPv6 forms and the rest of 0.0.0.0/8. The well-known NAT64 prefix (64:ff9b::/96) counts as remote because it carries IPv4 internet traffic. As a redirect target, a NAT64 address is judged by the IPv4 address it embeds.

  • A LAN host whose only records are global IPv6 counts as remote. Redirects to its own global address still work; redirects into private addresses do not.

  • DataCat and the JannyAI search calls no longer follow redirects at all. If either API starts redirecting, for example to a www host, those calls will fail until the policy is relaxed. This matches fetchBotBrowserJson and the Janny card download. Neither live endpoint redirects today.

  • A same-origin redirect from a remote hop that now resolves to a local address is refused as well.

Gaps:

  • The NO_PROXY connect-time refusal of a redirect target that did not resolve is tested through a real dispatcher. Only the NO_PROXY lookup path that records the trusted address for a local hop is still covered by a manual check, not a test.
  • docs/CONFIGURATION.md § Local address opt-ins does not yet say that a redirect from a remote service never gets local-address trust. Adding that line would also need the docs-i18n follow-up, so it is left to the maintainer.
  • Not run: the full pnpm check (client build, localization, impeccable) and the full regression suite. Only the targeted checks listed above were run; CI runs the rest. No client copy changed.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/8772 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/3/2026 **Status:** ✅ Merged **Merged:** 11/4/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/hardening-safe-fetch-redirects` --- ### 📝 Commits (6) - [`d3d94f0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d3d94f02366f180f696d7bd23e51a45c4b2a0110) fix(server): keep redirected outbound requests within the caller's trust - [`961b50c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/961b50c873bb8c22617450d3edeea72da9c86e98) fix(server): judge redirect trust by the address a hop connected to - [`9212260`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9212260be70adc92489170ec9c6ee71277b22083) fix(server): judge local-looking redirect hops by the address they reached - [`25b829a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/25b829a4ce16c48c09a2f7ffdbac827f68849864) fix(server): trust a redirect hop only on the built-in local ranges - [`a254296`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a2542969c07d428d83e038bef9b16f66e22aecb2) fix(server): let a remote redirect hop keep the caller's non-local allowances - [`a7543a9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a7543a9fe30dd97797490ff29759295234743660) fix(server): refuse remote redirects into 192.0.0.0/24 with local URLs on ### 📊 Changes **5 files changed** (+557 additions, -31 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/routes/bot-browser-datacat.routes.ts` (+13 -4) 📝 `packages/server/src/routes/bot-browser-janny.routes.ts` (+16 -5) 📝 `packages/server/src/utils/security.ts` (+139 -22) ➕ `scripts/regressions/bot-browser-upstream-fetch.regression.ts` (+58 -0) ➕ `scripts/regressions/safe-fetch-redirect-local-trust.regression.ts` (+331 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #8769 ## Why this change Some outbound requests are allowed to reach loopback, mDNS or local-network addresses: the user configured a local model server, image backend or TTS server, or turned on a *_LOCAL_URLS_ENABLED switch (on by default for providers on Android). That trust is meant only for the server the user chose. Until now, safeFetch checked every redirect hop against the caller's original allowances, so a remote service's redirect inherited them as well. The repository already refuses this for image result URLs, which must not inherit provider trust. Whether a hop counts as local must also come from the address the request actually reached. It must not come from a separate DNS lookup made afterwards, or from how the hostname is spelled. Names ending in .local, .internal or .localhost are answered by DNS or mDNS and can point anywhere; localhost itself is always pinned to loopback. "Local" also has to mean the built-in loopback and local-network ranges, not the broader reserved-address deny-list. That list also covers VPN fake-IP answers (198.18.0.0/15), test and multicast ranges, and any range an operator trusts for sign-in through TRUSTED_PRIVATE_NETWORKS. Separately, the DataCat and JannyAI Card Browser requests were the last catalog calls still using plain fetch. Plain fetch follows redirects with no address checks and reads replies with no size limit; every other Card Browser provider goes through safeFetch. ## What changed - Stops working: a remote AI, image, TTS, speech-to-text or RunPod service can no longer redirect a request to a loopback, .local or local-network address. This now fails with 'Refused to fetch ...'. It holds with PROVIDER_LOCAL_URLS_ENABLED or IMAGE_LOCAL_URLS_ENABLED on, on Android, and for image/TTS backends that always allow local URLs. Requests sent straight to a local server you configured still work. Redirects between local servers still work (for example localhost to 127.0.0.1, a LAN host or .local host moving from http to https, including dual-stack LAN hosts), and so do redirects between remote services. - Whether a redirecting server is local is decided from the address the request actually connected to, never from its hostname. Only the built-in loopback, private (RFC 1918), link-local, IPv6 ULA and CGNAT/Tailscale ranges and the unspecified address (0.0.0.0 or ::) count as local. A server counts as remote if it was reached through the well-known NAT64 prefix or a VPN fake-IP address (198.18.0.0/15), if its address is only in TRUSTED_PRIVATE_NETWORKS, or if it is a named server reached through an HTTP(S) proxy or a caller's own dispatcher. With local URLs allowed, a remote server's redirect keeps the caller's other allowances and loses only local trust. It is refused when the target is a localhost, .local, .internal or .localhost name. It is also refused when the target resolves to an address in any of these ranges: loopback, private, link-local (including cloud metadata), ULA, CGNAT, 0.0.0.0/8, or 192.0.0.0/24 (464XLAT and DS-Lite addresses on this device or its router, and a legacy cloud metadata endpoint). The same applies to an IPv4-mapped or IPv4-compatible form of one of these, and to a NAT64 address that embeds one. Redirects to other remote services are followed, including services answered from fake-IP or NAT64 addresses. A redirect target that does not resolve locally is followed only when an env proxy carries the request, because the proxy looks the name up itself. Sent directly, it is refused. A NO_PROXY host is refused when it connects rather than being looked up again. Without local URLs (the desktop default), a remote server's redirect is checked against the full reserved-address deny-list, with no loopback or mDNS exemption. - With local URLs allowed, a server addressed by DNS name, including .local, .internal and .localhost names, is now resolved once and connected through its first IPv4 address (IPv6 if it has none), the same way desktop provider calls and localhost are already handled. Before, Node's default connection handling was used. - DataCat Card Browser requests stay on datacat.run with no redirects, and replies are capped at 10 MiB. - JannyAI search requests stay on search.jannyai.com with no redirects. The JannyAI search-token page scrapes (direct and through corsproxy.io) now check every redirect hop's address and are capped at 8 MiB. - Two regressions cover this. One covers redirect trust in safeFetch: .local and .internal names on remote addresses, fake-IP and TRUSTED_PRIVATE_NETWORKS hops, NAT64, a 0.0.0.0 server, and a hop sent through a caller's dispatcher. The other covers the DataCat and JannyAI routes. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - In the app's Card Browser, check that DataCat browse, search, tags, character detail and download still load against the live datacat.run API. - In the app's Card Browser, check that JannyAI search and character detail still load, and that GET /api/bot-browser/janny/token?force=1 still returns a scraped token rather than only the built-in fallback. - Check that a local model server (Ollama, KoboldCPP or LM Studio on localhost) still generates replies, and that a LAN server addressed by DNS name with PROVIDER_LOCAL_URLS_ENABLED=true does too, including one behind a reverse proxy that redirects http to https. - Check a LAN server whose DNS name has both a private IPv4 and a global IPv6 address (common on IPv6 home networks): it should still connect, and its http-to-https redirect should still be followed. - Check that a local image backend (ComfyUI, SwarmUI or SD WebUI on loopback or a LAN name) still generates images and saves results, and that PocketTTS on a LAN name still speaks. - Check on Android, where PROVIDER_LOCAL_URLS_ENABLED is on by default, that a remote provider such as OpenRouter still works, both streaming and non-streaming. - Check that a setup with NODE_USE_ENV_PROXY=1 and HTTPS_PROXY set still reaches remote providers through the proxy, and NO_PROXY LAN hosts directly. - Manually verify that a local provider addressed by a .local mDNS name (e.g. http://gpu-box.local:5001) still connects and follows an http to https redirect on itself, both with PROVIDER_LOCAL_URLS_ENABLED off (the default) and on. - Manually verify that a provider reached by a host.docker.internal-style name still works with PROVIDER_LOCAL_URLS_ENABLED=true. - Manually verify, with NODE_USE_ENV_PROXY=1 and HTTPS_PROXY set, that a .local provider host that is not in NO_PROXY still loads a direct request. Then verify that its http to https redirect on the same .local name is refused ('hostname ... is local or reserved'), and that adding the host to NO_PROXY makes that redirect work again. - Manually verify on Android with a fake-IP VPN app in TUN mode (Clash, Surge or sing-box), that direct provider requests still work. Then check that a provider or image CDN redirect to another remote host is followed, for example an image result URL that redirects to a CDN. - Manually verify on Android with a fake-IP VPN in TUN mode that a provider redirect to a LAN address or to localhost is still refused with 'Refused to fetch ...'. - Manually verify on Android on an IPv6-only mobile network that uses 464XLAT that remote providers still work, both streaming and non-streaming, with PROVIDER_LOCAL_URLS_ENABLED on (the default). - Manually verify with NODE_USE_ENV_PROXY=1, HTTPS_PROXY set and local DNS that cannot resolve the provider's redirect target (for example a corporate split-DNS setup) that, with PROVIDER_LOCAL_URLS_ENABLED=true, a remote provider's redirect to another remote host is followed through the proxy. - Manually verify on an IPv6-only network with DNS64 (where IPv4-only providers resolve into 64:ff9b::/96) that, with local URLs on, a provider redirect to another remote host is followed. - Manually verify that, with PROVIDER_LOCAL_URLS_ENABLED=false (the desktop default), a provider redirect into a reserved range is still refused as before. - Manually verify that a local server configured as http://0.0.0.0:<port> with PROVIDER_LOCAL_URLS_ENABLED=true still follows a redirect to itself. - Manually verify that setting TRUSTED_PRIVATE_NETWORKS to a narrower list (for example only 10.0.0.0/8) does not stop a 192.168.x.x LAN provider from redirecting to itself. Agent-run checks (for reference; each regression was shown to fail without its fix): - `node ./scripts/pnpm-runner.mjs build:shared`: succeeded - `node ./scripts/run-regressions.mjs --filter safe-fetch-redirect-local-trust`: PASSED at 961b50c873 and again at 25b829a4ce. With the d3d94f0236 security.ts it FAILED on the dual-stack case ('Refused to fetch https://nas.test:11434/v1/models ...') - `Temporary per-case copy of that regression (zz-tmp-proof-relay.regression.ts), run with the earlier security.ts and again with the fix, then deleted`: Before: relay.test and nat64.test redirects to loopback were FOLLOWED under both local-URL policies (4 extra /blocked hits on loopback). After: all 4 refused, relay.test looked up once, only the 4 exp - `Temporary real-connection probe (zz-tmp-real-pin.regression.ts), then deleted`: PASSED: an allowLocal DNS name with [::1, 127.0.0.1] records reached an IPv4-only server through the pinned IPv4 record, with one DNS call, and followed its local redirect - `node ./scripts/run-regressions.mjs --filter <file> --concurrency 1 for each of the 109 regressions that reference utils/security, safeFetch, llmFetch, base-prov`: 109/109 passed (run after the source change; the only later edit was a comment in the test file, and that regression was re-run and passed) - `node ./scripts/run-regressions.mjs --filter security`: 32/32 passed (also at 25b829a4ce) - `Follow-up 25b829a4ce, with the 9212260be7 security.ts restored`: FAILED on the fake-IP case ('fakeip.test cannot redirect to loopback') and, in a throwaway copy, on the TRUSTED_PRIVATE_NETWORKS case; both pass with the fix. With the 0.0.0.0 branch disabled, the 0.0.0.0 server case FAILED. - `node ./scripts/run-regressions.mjs --filter bot-browser`: 4/4 passed - `node ./scripts/pnpm-runner.mjs lint in packages/server (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activity.json)`: exit 0 - `npx tsc -p <scratchpad tsconfig covering the two new regression files, same lib/types as the repo's regression tsconfig>`: exit 0 - `npx prettier --write / --check on all 5 changed files`: all pass - `eslint`: not applicable: ESLint covers only packages/client; the server and scripts lint step is the tsc run above - `Follow-up a2542969c0/a7543a9fe3 (Dottore LOW: remote fake-IP redirects): node ./scripts/run-regressions.mjs --filter safe-fetch-redirect-local-trust`: PASSED; with the 25b829a4ce security.ts it FAILED on fake-IP to fake-IP, and with the a2542969c0 security.ts it FAILED on the 192.0.0.4 redirect. `--filter security` 32/32, fetch 6/6, proxy 4/4, provider 13/13, image 28/28, loopback 2/2, audio 14/14, tts 13/13, bot-browser 4/4; server lint exit 0. Independent adversarial review: changes, 2 issue(s), all addressed in a fix-up pass. Local CodeRabbit review then raised 3 issues (trust range, a wording error, the proxy caveat); all three were accepted and fixed in 9212260be7 and 25b829a4ce. A second local CodeRabbit pass on those commits raised 2 more: the remote-to-remote redirect finding is fixed in a2542969c0 for fake-IP targets, while its suggestion to also follow redirects to .local names is rejected (a remote hop redirecting to a .local name is the case this PR closes, since mDNS can answer it with a LAN host); the request to split the loopback-hit assertion is rejected because the single assertion already lists every expected hit in order, including the 0.0.0.0 case. Dottore's later LOW finding (remote fake-IP redirects refused with local URLs on) is fixed in a2542969c0, and an adversarial review of that fix found 192.0.0.0/24 missing from the refused targets, fixed in a7543a9fe3. Known limits and risks: Behaviour changes: - With local URLs allowed (Android providers by default, ComfyUI/SwarmUI/A1111, PocketTTS, *_LOCAL_URLS_ENABLED), a hop addressed by DNS name, including .local, .internal and .localhost names, is now resolved once and pinned to one address. The hop the caller configured is pinned IPv4 first; a remote hop's redirect target is pinned to its first record in resolver order. Previously it used Node's default connection handling, which could fall back across every record. A host that publishes an IPv4 record that cannot be reached, but serves on IPv6, would now fail to connect. Desktop provider calls already work this way. - Those pinned hops get a per-request connection that is closed after the response, instead of the shared connection pool. That costs a new TCP/TLS handshake per request for DNS-named servers in local-URL mode. IP literals and localhost are unchanged. - A hop whose connected address is unknown counts as remote, so its redirects cannot reach local addresses. That covers a hop carried by an env proxy, a name that does not resolve locally, and a hop sent through a caller's own dispatcher (no production caller passes one). Behind an env proxy, a .local, .internal or .localhost host that is not in NO_PROXY cannot follow even an http-to-https redirect on its own name; adding it to NO_PROXY is the workaround. - Only the built-in loopback, RFC 1918, link-local, ULA and CGNAT/Tailscale ranges, plus exactly 0.0.0.0 and ::, count as local when deciding whether to trust a redirecting hop. VPN fake-IP hops (198.18.0.0/15) are remote. With local URLs on (the Android provider default), a fake-IP hop's redirect is refused when the target is a local-looking name or an address in the local ranges. It is followed otherwise, including to another name the VPN answers with a fake-IP address. A fake-IP address does not show where the VPN app will connect, so for those targets the VPN app's routing decides, as with an env proxy. A name the VPN routes to a local server, or the VPN's own TUN address, can still be reached. Without local URLs (the desktop default), fake-IP addresses were already refused and still are. - A remote hop's redirect target is refused on a slightly wider set than the set that makes a hop trusted: all of 0.0.0.0/8, all of 192.0.0.0/24 (464XLAT, DS-Lite and a legacy cloud metadata endpoint), IPv4-compatible IPv6 forms such as ::7f00:1, and NAT64 addresses that embed one of the refused IPv4 addresses. If a DNS filter answers a provider's redirect target with 0.0.0.0 or ::, that redirect fails, even behind an env proxy. - With local URLs on, a redirect target that does not resolve locally is followed only when an env proxy carries the request. The proxy looks the name up itself, so the app cannot check where it leads, as with any proxied request. Without a proxy, through a caller's own dispatcher, or for a NO_PROXY host, that target is refused. - Checks are by address range only. An address this machine holds outside those ranges, such as its own global IPv6 or public IPv4 address, is not recognised as this machine. This is unchanged and applies to the desktop deny-list too. - An address that is only in TRUSTED_PRIVATE_NETWORKS no longer makes a hop local. This matches isReservedIp's existing rule that the sign-in trust list does not change outbound checks. With local URLs on, a remote hop may redirect into such a range, as it may to any public address. Without local URLs it stays refused. When deciding whether to trust a hop, all of these count as remote: TEST-NET, multicast, class E, 192.0.0.0/24, deprecated IPv4-compatible IPv6 forms and the rest of 0.0.0.0/8. The well-known NAT64 prefix (64:ff9b::/96) counts as remote because it carries IPv4 internet traffic. As a redirect target, a NAT64 address is judged by the IPv4 address it embeds. - A LAN host whose only records are global IPv6 counts as remote. Redirects to its own global address still work; redirects into private addresses do not. - DataCat and the JannyAI search calls no longer follow redirects at all. If either API starts redirecting, for example to a www host, those calls will fail until the policy is relaxed. This matches fetchBotBrowserJson and the Janny card download. Neither live endpoint redirects today. - A same-origin redirect from a remote hop that now resolves to a local address is refused as well. Gaps: - The NO_PROXY connect-time refusal of a redirect target that did not resolve is tested through a real dispatcher. Only the NO_PROXY lookup path that records the trusted address for a local hop is still covered by a manual check, not a test. - docs/CONFIGURATION.md § Local address opt-ins does not yet say that a redirect from a remote service never gets local-address trust. Adding that line would also need the docs-i18n follow-up, so it is left to the maintainer. - Not run: the full `pnpm check` (client build, localization, impeccable) and the full regression suite. Only the targeted checks listed above were run; CI runs the rest. No client copy changed. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:45 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#8795
No description provided.