[PR #7698] [MERGED] fix(server): localhost provider URLs reach 127.0.0.1 when the resolver only answers ::1 #7885

Closed
opened 2026-10-24 04:08:29 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7698
Author: @Gunterlie
Created: 10/15/2026
Status: ✅ Merged
Merged: 10/15/2026
Merged by: @Gunterlie

Base: staging ← Head: fix/localhost-loopback-ipv4-k7q


📝 Commits (2)

  • 9364586 fix(server): localhost provider URLs reach 127.0.0.1 when the resolver only answers ::1
  • e5b50c5 test(server): localhost regression also stubs the callback resolver, so the local-URLs path is proven

📊 Changes

2 files changed (+90 additions, -4 deletions)

View changed files

📝 packages/server/src/utils/security.ts (+24 -4)
➕ scripts/regressions/localhost-loopback-fetch.regression.ts (+66 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7513

Why this change

  • A llama.cpp connection at http://localhost:8080 failed with connect ECONNREFUSED ::1:8080, while llama.cpp listened on 127.0.0.1. On that host the resolver maps localhost to ::1 only, so Node's happy-eyeballs has no IPv4 address to fall back to.
  • With PROVIDER_LOCAL_URLS_ENABLED, validateOutboundUrlForFetch skipped the pinned lookup and let undici resolve the name itself, so the same failure hit that path too.

What changed

  • packages/server/src/utils/security.ts:
    • New isLocalhostName(); normalizeLoopbackUrl uses it.
    • resolveHostname answers localhost names with 127.0.0.1 and ::1 without DNS (RFC 6761: localhost is always loopback).
    • The allowLocal path keeps the pinned lookup for localhost names, and the pinned lookup returns both loopback addresses for all lookups, so the connector can try IPv4 and IPv6.
  • New scripts/regressions/localhost-loopback-fetch.regression.ts: stubs both DNS lookup forms so localhost resolves to ::1 only, then fetches http://localhost:<port> from servers on 127.0.0.1 and ::1, with local URLs off and on. It fails on staging with the reporter's error and passes with this change.

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

Agent-run checks (not a human verification):

  • New regression localhost-loopback-fetch passes; without the fix it fails with ECONNREFUSED ::1 (both policies).
  • Passing regressions: provider-compat, image-result-url-security, opencode-session, extension-security, swarmui-video-origin, request-host-security.
  • Server pnpm run lint (tsc) and Prettier pass.
  • Not run: full pnpm check, container build, a real llama.cpp on an IPv6-only localhost host.

Security note: this touches the outbound URL guard. Only the literal localhost names change; they always map to loopback, which the existing loopback/local policy checks still gate. Other hostnames keep the DNS path and the pinned single address.

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)

Summary by CodeRabbit

  • Bug Fixes
    • Localhost requests now work more reliably with servers listening on either IPv4 or IPv6 loopback addresses, including when local URLs are allowed.
    • Localhost URLs are consistently routed to the IPv4 loopback address, and lookups can return both matching loopback addresses.

🔄 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/7698 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/15/2026 **Status:** ✅ Merged **Merged:** 10/15/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `fix/localhost-loopback-ipv4-k7q` --- ### 📝 Commits (2) - [`9364586`](https://github.com/Pasta-Devs/Marinara-Engine/commit/936458658bb47fe768babdfc2404eec19eb04f1c) fix(server): localhost provider URLs reach 127.0.0.1 when the resolver only answers ::1 - [`e5b50c5`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e5b50c5b7d4ae7ddd57ae6274d8d8ed14cf52a37) test(server): localhost regression also stubs the callback resolver, so the local-URLs path is proven ### 📊 Changes **2 files changed** (+90 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/utils/security.ts` (+24 -4) ➕ `scripts/regressions/localhost-loopback-fetch.regression.ts` (+66 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. ## Linked issue Closes #7513 ## Why this change - A llama.cpp connection at `http://localhost:8080` failed with `connect ECONNREFUSED ::1:8080`, while llama.cpp listened on `127.0.0.1`. On that host the resolver maps `localhost` to `::1` only, so Node's happy-eyeballs has no IPv4 address to fall back to. - With `PROVIDER_LOCAL_URLS_ENABLED`, `validateOutboundUrlForFetch` skipped the pinned lookup and let undici resolve the name itself, so the same failure hit that path too. ## What changed - `packages/server/src/utils/security.ts`: - New `isLocalhostName()`; `normalizeLoopbackUrl` uses it. - `resolveHostname` answers `localhost` names with `127.0.0.1` and `::1` without DNS (RFC 6761: `localhost` is always loopback). - The `allowLocal` path keeps the pinned lookup for `localhost` names, and the pinned lookup returns both loopback addresses for `all` lookups, so the connector can try IPv4 and IPv6. - New `scripts/regressions/localhost-loopback-fetch.regression.ts`: stubs both DNS lookup forms so `localhost` resolves to `::1` only, then fetches `http://localhost:<port>` from servers on `127.0.0.1` and `::1`, with local URLs off and on. It fails on `staging` with the reporter's error and passes with this change. ## 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 Agent-run checks (not a human verification): - New regression `localhost-loopback-fetch` passes; without the fix it fails with `ECONNREFUSED ::1` (both policies). - Passing regressions: provider-compat, image-result-url-security, opencode-session, extension-security, swarmui-video-origin, request-host-security. - Server `pnpm run lint` (tsc) and Prettier pass. - Not run: full `pnpm check`, container build, a real llama.cpp on an IPv6-only `localhost` host. Security note: this touches the outbound URL guard. Only the literal `localhost` names change; they always map to loopback, which the existing loopback/local policy checks still gate. Other hostnames keep the DNS path and the pinned single address. ## 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) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Localhost requests now work more reliably with servers listening on either IPv4 or IPv6 loopback addresses, including when local URLs are allowed. * Localhost URLs are consistently routed to the IPv4 loopback address, and lookups can return both matching loopback addresses. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:08:29 +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#7885
No description provided.