[PR #5602] [CLOSED] feat(server): add optional outbound proxy support (MARINARA_PROXY) #6843

Closed
opened 2026-10-23 04:14:13 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5602
Author: @stbanana
Created: 8/28/2026
Status: ❌ Closed

Base: staging ← Head: feat/5588-outbound-proxy


📝 Commits (2)

  • 6b45201 feat(server): route non-local outbound fetches through an optional proxy
  • 3932e13 docs(changelog): note MARINARA_PROXY outbound proxy (#5588)

📊 Changes

4 files changed (+54 additions, -4 deletions)

View changed files

📝 .env.example (+12 -0)
📝 CHANGELOG.md (+1 -0)
📝 docs/CONFIGURATION.md (+3 -0)
📝 packages/server/src/utils/security.ts (+38 -4)

📄 Description

PR title

feat(server): add optional outbound proxy support (MARINARA_PROXY)


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 #5588

Why this change

On networks where direct GitHub (or provider) access is blocked, Marinara Engine cannot download agents or capability packages, and provider requests can time out: safeFetch() is backed by undici's fetch plus a self-built Agent, and undici ignores both the OS proxy and the HTTP_PROXY/HTTPS_PROXY environment variables.

This adds an opt-in outbound proxy so restricted-network installs can route non-local outbound requests through a local SOCKS5 or HTTP(S) proxy. Behavior is unchanged when no proxy is configured.

What changed

  • packages/server/src/utils/security.ts
    • Import ProxyAgent, Socks5ProxyAgent, and type Dispatcher from undici.
    • Add resolveOutboundProxyUrl() (reads MARINARA_PROXY → HTTPS_PROXY → ALL_PROXY) and createOutboundProxyDispatcher() (SOCKS5/SOCKS5H/HTTP/HTTPS).
    • In validateOutboundUrlForFetch(), after SSRF validation, return a proxy dispatcher when a proxy is configured; otherwise keep the existing direct Agent path unchanged.
    • Widen the dispatcher parameter of readCappedResponse() / capStreamingResponse() from Agent to Dispatcher.
  • .env.example — document the new MARINARA_PROXY setting.
  • docs/CONFIGURATION.md — document the setting and its scope.

Reviewer notes:

  • SSRF validation (protocol/hostname allowlists plus DNS and private/loopback/reserved-IP checks) still runs before the proxy branch, and policy.allowLocal requests (Ollama, LM Studio, loopback) never use the proxy.
  • The proxy applies to all non-local outbound fetches — provider calls, media, wiki, docs — not just GitHub downloads. This is intentional.
  • When MARINARA_PROXY is unset, the standard HTTPS_PROXY / ALL_PROXY env vars are honored, so an ambient host proxy is picked up automatically.

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

  • Verify Download Agents lists packages when MARINARA_PROXY=socks5://... is set on a network that blocks direct GitHub access.
  • Verify an agent/package download succeeds through the proxy.
  • Verify behavior is unchanged (direct path) when MARINARA_PROXY is empty or unset.
  • Verify a local provider (e.g. Ollama) still connects directly and is not routed through the proxy.
  • Verify an unsupported or malformed proxy URL raises the descriptive error.

Docs and release impact

  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

UI evidence (if applicable)

No UI changes.

Summary by CodeRabbit

  • New Features
    • Added optional outbound proxy configuration through MARINARA_PROXY.
    • Supports SOCKS5, SOCKS5H, HTTP, and HTTPS proxies for external requests, including provider calls and downloads.
    • Automatically falls back to HTTPS_PROXY or ALL_PROXY when the new setting is not configured.
  • Documentation
    • Documented proxy configuration, supported formats, local-network bypass behavior, and configuration error reporting.

🔄 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/5602 **Author:** [@stbanana](https://github.com/stbanana) **Created:** 8/28/2026 **Status:** ❌ Closed **Base:** `staging` ← **Head:** `feat/5588-outbound-proxy` --- ### 📝 Commits (2) - [`6b45201`](https://github.com/Pasta-Devs/Marinara-Engine/commit/6b4520175e9e7f02bce6d8785e21aded5809c8ff) feat(server): route non-local outbound fetches through an optional proxy - [`3932e13`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3932e13792242dec586a38963bb79a6a6b7089cd) docs(changelog): note MARINARA_PROXY outbound proxy (#5588) ### 📊 Changes **4 files changed** (+54 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+12 -0) 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/CONFIGURATION.md` (+3 -0) 📝 `packages/server/src/utils/security.ts` (+38 -4) </details> ### 📄 Description # PR title feat(server): add optional outbound proxy support (MARINARA_PROXY) --- > [!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`. <!-- Change the PR base branch from `main` to `staging` before submitting. --> ## Linked issue Closes #5588 ## Why this change On networks where direct GitHub (or provider) access is blocked, Marinara Engine cannot download agents or capability packages, and provider requests can time out: `safeFetch()` is backed by undici's `fetch` plus a self-built `Agent`, and undici ignores both the OS proxy and the `HTTP_PROXY`/`HTTPS_PROXY` environment variables. This adds an opt-in outbound proxy so restricted-network installs can route non-local outbound requests through a local SOCKS5 or HTTP(S) proxy. Behavior is unchanged when no proxy is configured. ## What changed - `packages/server/src/utils/security.ts` - Import `ProxyAgent`, `Socks5ProxyAgent`, and `type Dispatcher` from `undici`. - Add `resolveOutboundProxyUrl()` (reads `MARINARA_PROXY` → `HTTPS_PROXY` → `ALL_PROXY`) and `createOutboundProxyDispatcher()` (SOCKS5/SOCKS5H/HTTP/HTTPS). - In `validateOutboundUrlForFetch()`, after SSRF validation, return a proxy dispatcher when a proxy is configured; otherwise keep the existing direct `Agent` path unchanged. - Widen the dispatcher parameter of `readCappedResponse()` / `capStreamingResponse()` from `Agent` to `Dispatcher`. - `.env.example` — document the new `MARINARA_PROXY` setting. - `docs/CONFIGURATION.md` — document the setting and its scope. Reviewer notes: - SSRF validation (protocol/hostname allowlists plus DNS and private/loopback/reserved-IP checks) still runs before the proxy branch, and `policy.allowLocal` requests (Ollama, LM Studio, loopback) never use the proxy. - The proxy applies to **all** non-local outbound fetches — provider calls, media, wiki, docs — not just GitHub downloads. This is intentional. - When `MARINARA_PROXY` is unset, the standard `HTTPS_PROXY` / `ALL_PROXY` env vars are honored, so an ambient host proxy is picked up automatically. ## Validation - [x] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [x] Ran the app, clicked through the changes manually - [x] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [x] Read and followed `CONTRIBUTING.md` ### Manual verification notes - [x] Verify `Download Agents` lists packages when `MARINARA_PROXY=socks5://...` is set on a network that blocks direct GitHub access. - [x] Verify an agent/package download succeeds through the proxy. - [x] Verify behavior is unchanged (direct path) when `MARINARA_PROXY` is empty or unset. - [ ] Verify a local provider (e.g. Ollama) still connects directly and is not routed through the proxy. - [ ] Verify an unsupported or malformed proxy URL raises the descriptive error. ## Docs and release impact - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) ## UI evidence (if applicable) No UI changes. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added optional outbound proxy configuration through `MARINARA_PROXY`. * Supports SOCKS5, SOCKS5H, HTTP, and HTTPS proxies for external requests, including provider calls and downloads. * Automatically falls back to `HTTPS_PROXY` or `ALL_PROXY` when the new setting is not configured. * **Documentation** * Documented proxy configuration, supported formats, local-network bypass behavior, and configuration error reporting. <!-- 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-23 04:14:13 +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#6843
No description provided.