[PR #7816] [MERGED] fix(security): harden auth for local proxies and Docker gateways #7943

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7816
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/harden-auth


📝 Commits (2)

  • fe12123 fix(security): harden auth for local proxies and Docker gateways
  • 35c34dc docs: clarify Docker allowlist bypass in remote access guide

📊 Changes

15 files changed (+582 additions, -57 deletions)

View changed files

📝 .env.example (+14 -1)
📝 README.md (+1 -1)
📝 docs/CONFIGURATION.md (+3 -2)
📝 docs/REMOTE_ACCESS.md (+37 -7)
📝 docs/TROUBLESHOOTING.md (+1 -1)
📝 docs/installation/containers.md (+3 -1)
📝 packages/server/src/config/runtime-config.ts (+12 -0)
📝 packages/server/src/middleware/basic-auth.ts (+71 -25)
📝 packages/server/src/middleware/csrf-protection.ts (+2 -2)
📝 packages/server/src/middleware/ip-allowlist.ts (+53 -7)
📝 packages/server/src/middleware/privileged-gate.ts (+16 -4)
📝 packages/server/src/routes/generate/prompt-preview.ts (+6 -3)
📝 packages/server/src/routes/updates.routes.ts (+3 -3)
➕ scripts/regressions/docker-gateway-auth-security.regression.ts (+102 -0)
➕ scripts/regressions/loopback-proxy-auth-security.regression.ts (+258 -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

No linked issue. This comes from a pre-release hardening pass of the access-control middleware.

Why this change

Basic Auth, IP_ALLOWLIST, ADMIN_SECRET and the loopback-only features are meant to cover every device except the computer running Marinara. Two common setups from our docs need extra handling to keep that true:

  • A reverse proxy or tunnel on the same machine (nginx, Caddy, Traefik, Cloudflare Tunnel, Tailscale Serve/Funnel, ngrok). It connects from 127.0.0.1, so its visitors looked like the local user. REMOTE_ACCESS.md recommends this setup for HTTPS.
  • Docker Desktop, OrbStack and rootless Docker. These relay every client of a published port through the container's gateway, so automatic Docker trust could not tell the host browser from a phone on the LAN, even with a password or allowlist set.

What changed

  • Local proxies (ip-allowlist.ts, basic-auth.ts, privileged-gate.ts, csrf-protection.ts, updates.routes.ts):
    • A loopback request that carries forwarding headers now counts as the remote visitor it relays. These are the existing Docker list (Forwarded, X-Forwarded-*, X-Real-IP) plus CF-Connecting-IP, True-Client-IP, Tailscale's identity and Funnel headers, and Via.
    • Basic Auth, IP allowlist strictness, the admin secret, loopback-only routes, the local channel switch and the CSRF localhost-origin shortcut all apply to those requests.
    • Direct loopback is unchanged.
  • New REQUIRE_AUTH_FOR_LOOPBACK_PROXY setting (default true), mirroring REQUIRE_AUTH_FOR_DOCKER_PROXY. Setting it to false restores the previous behaviour for proxies that enforce their own login.
  • Setup page and messages: the lockdown page, its JSON message and the log line explain the proxy case. They point at Basic Auth or the new setting instead of suggesting IP_ALLOWLIST=127.0.0.1.
  • Prompt preview (prompt-preview.ts): the internal preview request drops every forwarding header and the browser-origin headers. It stays a local call, and the outer route has already passed auth and CSRF.
  • Docker (ip-allowlist.ts):
    • Automatic Docker trust (BYPASS_AUTH_DOCKER empty) now applies only while neither Basic Auth nor IP_ALLOWLIST is configured. It still stands in for the no-password lockdown, so the default 127.0.0.1-bound compose keeps working.
    • BYPASS_AUTH_DOCKER=true keeps its explicit meaning.
    • A one-time [auth-bypass] warning explains when automatic trust is held back.
  • Docs:
    • REMOTE_ACCESS.md has a new "Reverse proxies and tunnels on the same computer" section, plus notes on Docker and the allowlist.
    • Also updated: CONFIGURATION.md, TROUBLESHOOTING.md, installation/containers.md, README.md and .env.example.
  • Regressions: loopback-proxy-auth-security and docker-gateway-auth-security. Both fail on current staging and pass with this change, and pnpm regression:security picks both up.

Behaviour changes operators may notice:

  • A same-machine proxy or tunnel without Basic Auth now shows the setup page. Fix: set Basic Auth, or REQUIRE_AUTH_FOR_LOOPBACK_PROXY=false if the proxy has its own login.
  • On Docker with Basic Auth set, the host browser now gets the login prompt once.
  • On Docker with IP_ALLOWLIST set, the host browser is refused unless the gateway is listed. Fix: list the gateway, or use Basic Auth.

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

What the agent ran (for the reviewer to confirm, not a substitute for the boxes above):

  • pnpm check passed.
  • pnpm regression:security passed: 21/21 in the security filter, plus runtime-integrity, shell-sandbox, extension-ipc, android-local-auth and docker-proxy-auth.
  • The two new regressions failed on unmodified staging and pass with the fix.
  • Related regressions passed, covering every regression that imports the changed modules or builds the app:
    • docker-proxy-auth, request-host-security, android-local-auth, advanced-memory-generation and beholder-state-reachable
    • 28 app-level regressions
    • the launcher format-guard, update and termux-client-build regressions
  • Real buildApp() with Basic Auth, ADMIN_SECRET and TRUSTED_HOSTS set:
    • Proxied loopback requests without credentials return 401.
    • With credentials they return 200, and a backup download without the admin secret returns 403.
    • Direct loopback returns 200.
  • The auth hooks ran in OrbStack containers with the port published on all interfaces. Results for requests from the host's LAN address:
    Configuration Result
    Basic Auth 401 without credentials, 200 with them
    IP_ALLOWLIST only 403
    No auth 200, unchanged
    BYPASS_AUTH_DOCKER=true 200, unchanged

Manual verification notes

  • Manually verify that nginx or Caddy on the same machine, proxying to Marinara with Basic Auth set, shows the login prompt through the proxy, while http://127.0.0.1:7860 on that machine stays passwordless.
  • Manually verify that a Cloudflare Tunnel or Tailscale Serve without Basic Auth shows the setup page with the "Your proxy already asks for a login" option, and that REQUIRE_AUTH_FOR_LOOPBACK_PROXY=false in .env restores access within a few seconds.
  • Manually verify that Peek prompt and preset Preview still work behind an HTTPS reverse proxy.
  • Manually verify that Docker Desktop (macOS or Windows) with BASIC_AUTH_USER/BASIC_AUTH_PASS prompts both the host browser and a phone on the LAN, and that the container logs the one-time [auth-bypass] notice.
  • Manually verify that the default Docker compose (bound to 127.0.0.1, no auth) still opens without a password on the host.
  • Manually verify that update apply and the update channel switch still work from a local browser.

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)

Docs touched: README.md, .env.example, docs/REMOTE_ACCESS.md, docs/CONFIGURATION.md, docs/TROUBLESHOOTING.md, docs/installation/containers.md. Translated packs follow up in #7817. No CHANGELOG.md entry.

UI evidence (if applicable)

None: no client UI changes. The server-rendered setup page gains a proxy-specific variant.

Summary by CodeRabbit

  • Access Control
    • Requests routed through a same-machine proxy or tunnel are treated as remote and subject to authentication and access restrictions by default; direct loopback access remains passwordless.
    • An opt-out is available for trusted proxies that require every visitor to sign in.
    • Automatic Docker authentication bypass applies only when Basic Auth and an IP allowlist are both unset. Explicit Docker bypass remains available.
  • Documentation
    • Updated access-control, Docker networking, and reverse-proxy guidance to clarify these rules, including shared gateway addresses on Docker Desktop and OrbStack.

🔄 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/7816 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/harden-auth` --- ### 📝 Commits (2) - [`fe12123`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe1212334ffef10806cd3103bb24b39205a0fe68) fix(security): harden auth for local proxies and Docker gateways - [`35c34dc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/35c34dc692d9d3bc77d628cff28fcdec0de29e3f) docs: clarify Docker allowlist bypass in remote access guide ### 📊 Changes **15 files changed** (+582 additions, -57 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+14 -1) 📝 `README.md` (+1 -1) 📝 `docs/CONFIGURATION.md` (+3 -2) 📝 `docs/REMOTE_ACCESS.md` (+37 -7) 📝 `docs/TROUBLESHOOTING.md` (+1 -1) 📝 `docs/installation/containers.md` (+3 -1) 📝 `packages/server/src/config/runtime-config.ts` (+12 -0) 📝 `packages/server/src/middleware/basic-auth.ts` (+71 -25) 📝 `packages/server/src/middleware/csrf-protection.ts` (+2 -2) 📝 `packages/server/src/middleware/ip-allowlist.ts` (+53 -7) 📝 `packages/server/src/middleware/privileged-gate.ts` (+16 -4) 📝 `packages/server/src/routes/generate/prompt-preview.ts` (+6 -3) 📝 `packages/server/src/routes/updates.routes.ts` (+3 -3) ➕ `scripts/regressions/docker-gateway-auth-security.regression.ts` (+102 -0) ➕ `scripts/regressions/loopback-proxy-auth-security.regression.ts` (+258 -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`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue No linked issue. This comes from a pre-release hardening pass of the access-control middleware. ## Why this change Basic Auth, `IP_ALLOWLIST`, `ADMIN_SECRET` and the loopback-only features are meant to cover every device except the computer running Marinara. Two common setups from our docs need extra handling to keep that true: - **A reverse proxy or tunnel on the same machine** (nginx, Caddy, Traefik, Cloudflare Tunnel, Tailscale Serve/Funnel, ngrok). It connects from `127.0.0.1`, so its visitors looked like the local user. `REMOTE_ACCESS.md` recommends this setup for HTTPS. - **Docker Desktop, OrbStack and rootless Docker.** These relay every client of a published port through the container's gateway, so automatic Docker trust could not tell the host browser from a phone on the LAN, even with a password or allowlist set. ## What changed - **Local proxies (`ip-allowlist.ts`, `basic-auth.ts`, `privileged-gate.ts`, `csrf-protection.ts`, `updates.routes.ts`):** - A loopback request that carries forwarding headers now counts as the remote visitor it relays. These are the existing Docker list (`Forwarded`, `X-Forwarded-*`, `X-Real-IP`) plus `CF-Connecting-IP`, `True-Client-IP`, Tailscale's identity and Funnel headers, and `Via`. - Basic Auth, IP allowlist strictness, the admin secret, loopback-only routes, the local channel switch and the CSRF localhost-origin shortcut all apply to those requests. - Direct loopback is unchanged. - **New `REQUIRE_AUTH_FOR_LOOPBACK_PROXY` setting** (default `true`), mirroring `REQUIRE_AUTH_FOR_DOCKER_PROXY`. Setting it to `false` restores the previous behaviour for proxies that enforce their own login. - **Setup page and messages:** the lockdown page, its JSON message and the log line explain the proxy case. They point at Basic Auth or the new setting instead of suggesting `IP_ALLOWLIST=127.0.0.1`. - **Prompt preview (`prompt-preview.ts`):** the internal preview request drops every forwarding header and the browser-origin headers. It stays a local call, and the outer route has already passed auth and CSRF. - **Docker (`ip-allowlist.ts`):** - Automatic Docker trust (`BYPASS_AUTH_DOCKER` empty) now applies only while neither Basic Auth nor `IP_ALLOWLIST` is configured. It still stands in for the no-password lockdown, so the default `127.0.0.1`-bound compose keeps working. - `BYPASS_AUTH_DOCKER=true` keeps its explicit meaning. - A one-time `[auth-bypass]` warning explains when automatic trust is held back. - **Docs:** - `REMOTE_ACCESS.md` has a new "Reverse proxies and tunnels on the same computer" section, plus notes on Docker and the allowlist. - Also updated: `CONFIGURATION.md`, `TROUBLESHOOTING.md`, `installation/containers.md`, `README.md` and `.env.example`. - **Regressions:** `loopback-proxy-auth-security` and `docker-gateway-auth-security`. Both fail on current `staging` and pass with this change, and `pnpm regression:security` picks both up. **Behaviour changes operators may notice:** - A same-machine proxy or tunnel without Basic Auth now shows the setup page. Fix: set Basic Auth, or `REQUIRE_AUTH_FOR_LOOPBACK_PROXY=false` if the proxy has its own login. - On Docker with Basic Auth set, the host browser now gets the login prompt once. - On Docker with `IP_ALLOWLIST` set, the host browser is refused unless the gateway is listed. Fix: list the gateway, or use Basic Auth. ## 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` What the agent ran (for the reviewer to confirm, not a substitute for the boxes above): - `pnpm check` passed. - `pnpm regression:security` passed: 21/21 in the `security` filter, plus runtime-integrity, shell-sandbox, extension-ipc, android-local-auth and docker-proxy-auth. - The two new regressions failed on unmodified `staging` and pass with the fix. - Related regressions passed, covering every regression that imports the changed modules or builds the app: - docker-proxy-auth, request-host-security, android-local-auth, advanced-memory-generation and beholder-state-reachable - 28 app-level regressions - the launcher format-guard, update and termux-client-build regressions - Real `buildApp()` with Basic Auth, `ADMIN_SECRET` and `TRUSTED_HOSTS` set: - Proxied loopback requests without credentials return 401. - With credentials they return 200, and a backup download without the admin secret returns 403. - Direct loopback returns 200. - The auth hooks ran in OrbStack containers with the port published on all interfaces. Results for requests from the host's LAN address: | Configuration | Result | | --- | --- | | Basic Auth | 401 without credentials, 200 with them | | `IP_ALLOWLIST` only | 403 | | No auth | 200, unchanged | | `BYPASS_AUTH_DOCKER=true` | 200, unchanged | ### Manual verification notes - Manually verify that nginx or Caddy on the same machine, proxying to Marinara with Basic Auth set, shows the login prompt through the proxy, while `http://127.0.0.1:7860` on that machine stays passwordless. - Manually verify that a Cloudflare Tunnel or Tailscale Serve without Basic Auth shows the setup page with the "Your proxy already asks for a login" option, and that `REQUIRE_AUTH_FOR_LOOPBACK_PROXY=false` in `.env` restores access within a few seconds. - Manually verify that **Peek prompt** and preset **Preview** still work behind an HTTPS reverse proxy. - Manually verify that Docker Desktop (macOS or Windows) with `BASIC_AUTH_USER`/`BASIC_AUTH_PASS` prompts both the host browser and a phone on the LAN, and that the container logs the one-time `[auth-bypass]` notice. - Manually verify that the default Docker compose (bound to `127.0.0.1`, no auth) still opens without a password on the host. - Manually verify that update apply and the update channel switch still work from a local browser. ## 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) Docs touched: `README.md`, `.env.example`, `docs/REMOTE_ACCESS.md`, `docs/CONFIGURATION.md`, `docs/TROUBLESHOOTING.md`, `docs/installation/containers.md`. Translated packs follow up in #7817. No `CHANGELOG.md` entry. ## UI evidence (if applicable) None: no client UI changes. The server-rendered setup page gains a proxy-specific variant. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Access Control** * Requests routed through a same-machine proxy or tunnel are treated as remote and subject to authentication and access restrictions by default; direct loopback access remains passwordless. * An opt-out is available for trusted proxies that require every visitor to sign in. * Automatic Docker authentication bypass applies only when Basic Auth and an IP allowlist are both unset. Explicit Docker bypass remains available. * **Documentation** * Updated access-control, Docker networking, and reverse-proxy guidance to clarify these rules, including shared gateway addresses on Docker Desktop and OrbStack. <!-- 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:09:01 +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#7943
No description provided.