[PR #346] [MERGED] feat(server): auto-trust private networks in basic-auth lockdown #4570

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/346
Author: @LukaTheHero
Created: 5/1/2026
Status: ✅ Merged
Merged: 5/1/2026
Merged by: @LukaTheHero

Base: main ← Head: feat/auto-trust-private-networks-in-lockdown


📝 Commits (2)

  • 1ead801 feat(server): auto-trust private networks in basic-auth lockdown
  • 382a19e feat(server): TRUSTED_PRIVATE_NETWORKS override for lockdown bypass list

📊 Changes

5 files changed (+143 additions, -20 deletions)

View changed files

📝 .env.example (+12 -3)
📝 docs/CONFIGURATION.md (+30 -5)
📝 packages/server/src/config/runtime-config.ts (+9 -0)
📝 packages/server/src/middleware/basic-auth.ts (+25 -11)
📝 packages/server/src/middleware/ip-allowlist.ts (+67 -1)

📄 Description

Summary

Follow-up to #343. The safe-by-default lockdown shipped in that PR blocks all non-loopback / non-allowlisted IPs when no Basic Auth is configured — which protects accidentally-exposed public ports, but also breaks legitimate LAN, Docker, Kubernetes, and Tailscale users who were never the target of the lockdown.

This PR narrows the lockdown so it blocks only public-internet IPs. Private networks pass through automatically when no auth is configured:

  • Loopback (127.0.0.1, ::1) — already allowed.
  • RFC 1918: 10.0.0.0/8, 172.16.0.0/12 (covers Docker default bridge 172.17.0.0/16), 192.168.0.0/16.
  • Link-local: 169.254.0.0/16, fe80::/10.
  • IPv6 ULA: fc00::/7.
  • CGNAT: 100.64.0.0/10 (Tailscale, carrier NAT).
  • Explicit IP_ALLOWLIST entries — already allowed.

These seven ranges are defaults, not hardcoded — operators can override the entire list via TRUSTED_PRIVATE_NETWORKS (see below).

Why

Discord feedback after #343 merged: a Docker user reported a 403 from a container on the same bridge network, and reasonably called it a breaking change. Same problem applies to anyone reaching Marinara from their phone on the LAN, from a Kubernetes pod, from a reverse proxy in another container, or from a Tailscale peer. None of those callers were the threat model of the lockdown — the threat model is "port 7860 got NAT'd onto the public internet by accident."

By restricting the lockdown to public IPs, the safety win is preserved (public exposure is still safe) without breaking any of the "I just want to use it from my phone" workflows that have always worked.

Principle of least surprise

The private-network exemption applies only to the no-auth lockdown. If the operator sets BASIC_AUTH_USER/BASIC_AUTH_PASS, the password is required from every IP except loopback and explicit IP_ALLOWLIST matches — including from the LAN. Reasoning: if you went out of your way to set a password, you meant it; the LAN-bypass would be a surprising security regression for someone trying to lock out a roommate on the same Wi-Fi.

New env var: TRUSTED_PRIVATE_NETWORKS

The seven default ranges cover the vast majority of LAN / Docker / Kubernetes / Tailscale setups. For operators whose network doesn't match — e.g. a publicly-routable corporate /16 they trust, or a shared 10/8 in a hostile datacenter they don't — TRUSTED_PRIVATE_NETWORKS accepts a comma-separated list of IPs / CIDRs that replaces the defaults entirely (matches IP_ALLOWLIST semantics — what you type is what you get):

# Strip 10.0.0.0/8 from the defaults but keep the rest
TRUSTED_PRIVATE_NETWORKS=172.16.0.0/12,192.168.0.0/16,169.254.0.0/16,100.64.0.0/10,fc00::/7,fe80::/10

# Trust only my office subnet
TRUSTED_PRIVATE_NETWORKS=10.42.0.0/16

When unset, the defaults are used. Invalid entries are logged with a warn and skipped.

Behaviour matrix

image

Files

  • packages/server/src/middleware/ip-allowlist.ts — adds DEFAULT_PRIVATE_NETWORK_CIDRS, a cached resolver that respects the override, and an exported isPrivateNetworkIp(ip) helper. Existing IP allowlist hook is unchanged.
  • packages/server/src/middleware/basic-auth.ts — lockdown branch now calls isPrivateNetworkIp(ip) before refusing. Updated docblock, lockdown 403 message, and warn-once log to reflect "public-only" semantics.
  • packages/server/src/config/runtime-config.ts — adds getTrustedPrivateNetworksOverride().
  • docs/CONFIGURATION.md — rewrites the "Safe-by-default lockdown" section to list the auto-allowed ranges, clarifies that the exemption only applies in no-auth mode, and documents TRUSTED_PRIVATE_NETWORKS.
  • .env.example — adds TRUSTED_PRIVATE_NETWORKS example.

Summary by CodeRabbit

  • New Features

    • Added TRUSTED_PRIVATE_NETWORKS env var to override the built-in private-network allowlist.
    • Safe-by-default lockdown now treats only public-internet IPs as blocked when no Basic Auth is configured; private-network contexts remain allowed.
  • Documentation

    • Expanded docs and example env comments clarifying automatic exemptions (loopback, RFC1918, link-local, CGNAT, container/k8s/tailscale), the scope of ALLOW_UNAUTHENTICATED_REMOTE, and how TRUSTED_PRIVATE_NETWORKS replaces defaults.

🔄 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/346 **Author:** [@LukaTheHero](https://github.com/LukaTheHero) **Created:** 5/1/2026 **Status:** ✅ Merged **Merged:** 5/1/2026 **Merged by:** [@LukaTheHero](https://github.com/LukaTheHero) **Base:** `main` ← **Head:** `feat/auto-trust-private-networks-in-lockdown` --- ### 📝 Commits (2) - [`1ead801`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1ead801b96face4528a409ab121b0aa5b23e1a7c) feat(server): auto-trust private networks in basic-auth lockdown - [`382a19e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/382a19eba40da81ab29c979d2235a71a7ea0b75e) feat(server): TRUSTED_PRIVATE_NETWORKS override for lockdown bypass list ### 📊 Changes **5 files changed** (+143 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+12 -3) 📝 `docs/CONFIGURATION.md` (+30 -5) 📝 `packages/server/src/config/runtime-config.ts` (+9 -0) 📝 `packages/server/src/middleware/basic-auth.ts` (+25 -11) 📝 `packages/server/src/middleware/ip-allowlist.ts` (+67 -1) </details> ### 📄 Description ## Summary Follow-up to #343. The safe-by-default lockdown shipped in that PR blocks **all** non-loopback / non-allowlisted IPs when no Basic Auth is configured — which protects accidentally-exposed public ports, but also breaks legitimate LAN, Docker, Kubernetes, and Tailscale users who were never the target of the lockdown. This PR narrows the lockdown so it blocks **only public-internet IPs**. Private networks pass through automatically when no auth is configured: - Loopback (`127.0.0.1`, `::1`) — already allowed. - RFC 1918: `10.0.0.0/8`, `172.16.0.0/12` (covers Docker default bridge `172.17.0.0/16`), `192.168.0.0/16`. - Link-local: `169.254.0.0/16`, `fe80::/10`. - IPv6 ULA: `fc00::/7`. - CGNAT: `100.64.0.0/10` (Tailscale, carrier NAT). - Explicit `IP_ALLOWLIST` entries — already allowed. These seven ranges are **defaults, not hardcoded** — operators can override the entire list via `TRUSTED_PRIVATE_NETWORKS` (see below). ## Why Discord feedback after #343 merged: a Docker user reported a 403 from a container on the same bridge network, and reasonably called it a breaking change. Same problem applies to anyone reaching Marinara from their phone on the LAN, from a Kubernetes pod, from a reverse proxy in another container, or from a Tailscale peer. None of those callers were the threat model of the lockdown — the threat model is "port 7860 got NAT'd onto the public internet by accident." By restricting the lockdown to public IPs, the safety win is preserved (public exposure is still safe) without breaking any of the "I just want to use it from my phone" workflows that have always worked. ## Principle of least surprise The private-network exemption applies **only** to the no-auth lockdown. If the operator sets `BASIC_AUTH_USER`/`BASIC_AUTH_PASS`, the password is required from every IP except loopback and explicit `IP_ALLOWLIST` matches — including from the LAN. Reasoning: if you went out of your way to set a password, you meant it; the LAN-bypass would be a surprising security regression for someone trying to lock out a roommate on the same Wi-Fi. ## New env var: `TRUSTED_PRIVATE_NETWORKS` The seven default ranges cover the vast majority of LAN / Docker / Kubernetes / Tailscale setups. For operators whose network doesn't match — e.g. a publicly-routable corporate `/16` they trust, or a shared `10/8` in a hostile datacenter they don't — `TRUSTED_PRIVATE_NETWORKS` accepts a comma-separated list of IPs / CIDRs that **replaces** the defaults entirely (matches `IP_ALLOWLIST` semantics — what you type is what you get): ``` # Strip 10.0.0.0/8 from the defaults but keep the rest TRUSTED_PRIVATE_NETWORKS=172.16.0.0/12,192.168.0.0/16,169.254.0.0/16,100.64.0.0/10,fc00::/7,fe80::/10 # Trust only my office subnet TRUSTED_PRIVATE_NETWORKS=10.42.0.0/16 ``` When unset, the defaults are used. Invalid entries are logged with a warn and skipped. ## Behaviour matrix <img width="1090" height="834" alt="image" src="https://github.com/user-attachments/assets/93221fe9-0214-4964-88fd-ddf2b2526a3a" /> ## Files - `packages/server/src/middleware/ip-allowlist.ts` — adds `DEFAULT_PRIVATE_NETWORK_CIDRS`, a cached resolver that respects the override, and an exported `isPrivateNetworkIp(ip)` helper. Existing IP allowlist hook is unchanged. - `packages/server/src/middleware/basic-auth.ts` — lockdown branch now calls `isPrivateNetworkIp(ip)` before refusing. Updated docblock, lockdown 403 message, and warn-once log to reflect "public-only" semantics. - `packages/server/src/config/runtime-config.ts` — adds `getTrustedPrivateNetworksOverride()`. - `docs/CONFIGURATION.md` — rewrites the "Safe-by-default lockdown" section to list the auto-allowed ranges, clarifies that the exemption only applies in no-auth mode, and documents `TRUSTED_PRIVATE_NETWORKS`. - `.env.example` — adds `TRUSTED_PRIVATE_NETWORKS` example. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added TRUSTED_PRIVATE_NETWORKS env var to override the built-in private-network allowlist. * Safe-by-default lockdown now treats only public-internet IPs as blocked when no Basic Auth is configured; private-network contexts remain allowed. * **Documentation** * Expanded docs and example env comments clarifying automatic exemptions (loopback, RFC1918, link-local, CGNAT, container/k8s/tailscale), the scope of ALLOW_UNAUTHENTICATED_REMOTE, and how TRUSTED_PRIVATE_NETWORKS replaces defaults. <!-- 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-22 04:08:48 +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#4570
No description provided.