[GH-ISSUE #5588] [Feature]: Add optional outbound proxy support (MARINARA_PROXY) #3095

Closed
opened 2026-10-21 05:59:33 +07:00 by bsakaguchi · 4 comments
Owner

Originally created by @stbanana on GitHub (Aug 28, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5588

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

On restricted networks (for example mainland China), raw.githubusercontent.com is often unreachable, which breaks agent and capability-package installation:

  • package-manager.service.ts's fetchBytes() calls safeFetch(), which is backed by undici's fetch plus a self-built Agent — not Node's native http or axios.
  • The download target is fixed to raw.githubusercontent.com/Pasta-Devs/Marinara-Agents.

undici ignores both the OS/system proxy and the HTTP_PROXY / HTTPS_PROXY environment variables, so a direct connection to GitHub times out. Marinara Engine currently has no proxy path at all, and manually downloading Marinara-Agents does not import correctly either (there may be a correct manual-import workflow I have not found).

It would be much more convenient if outbound requests could optionally route through a local proxy, so users on restricted networks can pull agents and artifacts — and, when needed, send model requests through the same proxy.

Proposed solution

Add an environment variable, tentatively named MARINARA_PROXY. When it is set, safeFetch swaps its self-built Agent for undici's Socks5ProxyAgent (SOCKS5) or ProxyAgent (HTTP/HTTPS) as the dispatcher; when it is unset, behavior is identical to today.

  • Supported schemes: socks5://, socks5h://, http://, https://
  • Read order: MARINARA_PROXY → HTTPS_PROXY → ALL_PROXY
  • Read lazily: process.env is checked per request, so .env changes take effect within ~2s without a restart
  • policy.allowLocal requests (Ollama / LM Studio / loopback) never go through the proxy
- dispatcher?: Agent,
+ dispatcher?: Dispatcher,

Alternatives considered

I tried several alternative approaches with Claude's help — TUN proxying, injection/hooking, and so on — but each introduced additional side effects. A source-level change that adds one optional proxy branch is the only approach with no side effects and is user-friendly.

Additional context

  1. Unchanged when no proxy is configured: resolveOutboundProxyUrl() returns null, so the existing new Agent({...}) direct path runs exactly as before.
  2. Local requests unaffected: when policy.allowLocal is true (Ollama / LM Studio / loopback), the original direct branch runs and never touches the proxy.
  3. SSRF protection unchanged: protocol allowlists, hostname allowlists, and the private/loopback/reserved-IP DNS checks (validateOutboundUrl + validateResolvedAddresses) all run before the proxy branch.
  4. Timeouts still guaranteed: the proxy branch no longer passes agentOptions.bodyTimeout/headersTimeout, but every caller already supplies signal: AbortSignal.timeout(...).
  5. New failure modes are limited: only an explicitly configured malformed or unsupported proxy URL raises a descriptive error (for example Unsupported outbound proxy protocol ...).

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @stbanana on GitHub (Aug 28, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5588 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? On restricted networks (for example mainland China), `raw.githubusercontent.com` is often unreachable, which breaks agent and capability-package installation: - `package-manager.service.ts`'s `fetchBytes()` calls `safeFetch()`, which is backed by undici's `fetch` plus a self-built `Agent` — not Node's native `http` or `axios`. - The download target is fixed to `raw.githubusercontent.com/Pasta-Devs/Marinara-Agents`. undici ignores both the OS/system proxy and the `HTTP_PROXY` / `HTTPS_PROXY` environment variables, so a direct connection to GitHub times out. Marinara Engine currently has no proxy path at all, and manually downloading [Marinara-Agents](https://github.com/Pasta-Devs/Marinara-Agents) does not import correctly either (there may be a correct manual-import workflow I have not found). It would be much more convenient if outbound requests could optionally route through a local proxy, so users on restricted networks can pull agents and artifacts — and, when needed, send model requests through the same proxy. ## Proposed solution Add an environment variable, tentatively named **MARINARA_PROXY**. When it is set, `safeFetch` swaps its self-built `Agent` for undici's `Socks5ProxyAgent` (SOCKS5) or `ProxyAgent` (HTTP/HTTPS) as the dispatcher; when it is unset, behavior is identical to today. - Supported schemes: `socks5://`, `socks5h://`, `http://`, `https://` - Read order: `MARINARA_PROXY` → `HTTPS_PROXY` → `ALL_PROXY` - Read lazily: `process.env` is checked per request, so `.env` changes take effect within ~2s without a restart - `policy.allowLocal` requests (Ollama / LM Studio / loopback) never go through the proxy ```diff - dispatcher?: Agent, + dispatcher?: Dispatcher, ``` ## Alternatives considered I tried several alternative approaches with Claude's help — TUN proxying, injection/hooking, and so on — but each introduced additional side effects. A source-level change that adds one optional proxy branch is the only approach with no side effects and is user-friendly. ## Additional context 1. **Unchanged when no proxy is configured**: `resolveOutboundProxyUrl()` returns `null`, so the existing `new Agent({...})` direct path runs exactly as before. 2. **Local requests unaffected**: when `policy.allowLocal` is true (Ollama / LM Studio / loopback), the original direct branch runs and never touches the proxy. 3. **SSRF protection unchanged**: protocol allowlists, hostname allowlists, and the private/loopback/reserved-IP DNS checks (`validateOutboundUrl` + `validateResolvedAddresses`) all run before the proxy branch. 4. **Timeouts still guaranteed**: the proxy branch no longer passes `agentOptions.bodyTimeout`/`headersTimeout`, but every caller already supplies `signal: AbortSignal.timeout(...)`. 5. **New failure modes are limited**: only an explicitly configured malformed or unsupported proxy URL raises a descriptive error (for example `Unsupported outbound proxy protocol ...`). ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:59:33 +07:00
Author
Owner

@kolacheee commented on GitHub (Aug 28, 2026):

Thank you for the contribution @stbanana! Just giving you a heads up that Marinara is the only one with the power to merge PRs from non-Pasta Dev contributors and she is on vacation currently, so you will unfortunately have to wait some days before it gets reviewed.

<!-- gh-comment-id:5456437663 --> @kolacheee commented on GitHub (Aug 28, 2026): Thank you for the contribution @stbanana! Just giving you a heads up that Marinara is the only one with the power to merge PRs from non-Pasta Dev contributors and she is on vacation currently, so you will unfortunately have to wait some days before it gets reviewed.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 30, 2026):

Maintainer review: the user problem is valid, but the proposed acceptance criteria need tightening before implementation.

The Engine should support restricted-network agent/package downloads, but proxying must preserve the existing trust boundary:

  • Proxy routing must not discard the DNS addresses validated by safeFetch. The request must remain bound to the validated destination, or proxy support must be limited to exact trusted origins where equivalent egress validation is enforceable.
  • Local bypass must be based on the validated destination, not policy.allowLocal. That property grants permission to use local URLs; it does not mean every request using that policy is local.
  • Existing agentOptions, header/body timeouts, redirect validation, and TCP keepalive behavior must be preserved or explicitly rejected when unsupported.
  • Decide whether this is truly opt-in through MARINARA_PROXY, or whether ambient HTTPS_PROXY / ALL_PROXY variables are also supported. If standard environment variables are honored, NO_PROXY semantics and the resulting behavior change must be addressed and documented.
  • Proxy credentials must never appear in validation errors or logs.
  • Add automated coverage for direct behavior, HTTP and SOCKS proxies, loopback/mDNS bypass, public providers when local URLs are enabled, split-horizon/proxy-side DNS, redirects, timeouts, and credential-bearing invalid configuration.

The smallest safe first delivery would proxy only the official Marinara-Agents catalog and artifact downloads through explicit MARINARA_PROXY, restricted to their exact trusted GitHub origins. Provider-wide proxying can follow once the broader SSRF and local-routing semantics are proven.

PR #5602 is aligned with the feature direction, but its current implementation does not yet satisfy these requirements.

<!-- gh-comment-id:5467932420 --> @SpicyMarinara commented on GitHub (Aug 30, 2026): Maintainer review: the user problem is valid, but the proposed acceptance criteria need tightening before implementation. The Engine should support restricted-network agent/package downloads, but proxying must preserve the existing trust boundary: - Proxy routing must not discard the DNS addresses validated by `safeFetch`. The request must remain bound to the validated destination, or proxy support must be limited to exact trusted origins where equivalent egress validation is enforceable. - Local bypass must be based on the validated destination, not `policy.allowLocal`. That property grants permission to use local URLs; it does not mean every request using that policy is local. - Existing `agentOptions`, header/body timeouts, redirect validation, and TCP keepalive behavior must be preserved or explicitly rejected when unsupported. - Decide whether this is truly opt-in through `MARINARA_PROXY`, or whether ambient `HTTPS_PROXY` / `ALL_PROXY` variables are also supported. If standard environment variables are honored, `NO_PROXY` semantics and the resulting behavior change must be addressed and documented. - Proxy credentials must never appear in validation errors or logs. - Add automated coverage for direct behavior, HTTP and SOCKS proxies, loopback/mDNS bypass, public providers when local URLs are enabled, split-horizon/proxy-side DNS, redirects, timeouts, and credential-bearing invalid configuration. The smallest safe first delivery would proxy only the official Marinara-Agents catalog and artifact downloads through explicit `MARINARA_PROXY`, restricted to their exact trusted GitHub origins. Provider-wide proxying can follow once the broader SSRF and local-routing semantics are proven. PR #5602 is aligned with the feature direction, but its current implementation does not yet satisfy these requirements.
Author
Owner

@SpicyMarinara commented on GitHub (Aug 30, 2026):

On hold until properly addressed.

<!-- gh-comment-id:5467941239 --> @SpicyMarinara commented on GitHub (Aug 30, 2026): On hold until properly addressed.
Author
Owner

@stbanana commented on GitHub (Aug 31, 2026):

Thank you, Collaborators, for the detailed explanation! I had originally assumed that routing all requests through the proxy—bypassing the existing trust boundary—was the expected behavior for users who employ a proxy, as this would make it more convenient to access resources within a VPN's internal network (e.g., a campus network).
Once again, thank you for your dedication and hard work!

<!-- gh-comment-id:5472390187 --> @stbanana commented on GitHub (Aug 31, 2026): Thank you, Collaborators, for the detailed explanation! I had originally assumed that routing all requests through the proxy—bypassing the existing trust boundary—was the expected behavior for users who employ a proxy, as this would make it more convenient to access resources within a VPN's internal network (e.g., a campus network). Once again, thank you for your dedication and hard work!
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#3095
No description provided.