mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #343] [MERGED] feat(server): HTTP Basic Auth + safe-by-default remote lockdown #4568
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#4568
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/343
Author: @LukaTheHero
Created: 5/1/2026
Status: ✅ Merged
Merged: 5/1/2026
Merged by: @LukaTheHero
Base:
main← Head:feat/basic-auth-and-ip-allowlist-toggle📝 Commits (1)
52da81dfeat(server): HTTP Basic Auth + safe-by-default remote lockdown📊 Changes
6 files changed (+267 additions, -0 deletions)
View changed files
📝
.env.example(+17 -0)📝
docs/CONFIGURATION.md(+52 -0)📝
packages/server/src/app.ts(+4 -0)📝
packages/server/src/config/runtime-config.ts(+21 -0)➕
packages/server/src/middleware/basic-auth.ts(+145 -0)📝
packages/server/src/middleware/ip-allowlist.ts(+28 -0)📄 Description
Summary
Adds optional HTTP Basic Auth and an explicit on/off toggle for the existing IP allowlist, plus a safe-by-default lockdown for public-internet IPs only so an accidentally exposed port 7860 cannot be hit by random internet traffic — without breaking LAN, Docker, Kubernetes, or Tailscale traffic.
Motivated by a Discord request from a user hosting Marinara on a Hetzner Cloud server who wanted simple username/password protection for their public deployment, and by the broader concern that any user who flips
HOST=0.0.0.0(every shell launcher does) and forwards a port becomes immediately reachable from the open internet with no auth at all.Why this strengthens an exposed port 7860
Today,
HOST=0.0.0.0plus an exposed port = anyone on the internet can use the entire app, browse chats, exfiltrate data, and burn API credits. With this change:BASIC_AUTH_*configured, the server returns403 Forbiddento any IP that is not loopback, RFC 1918 private, CGNAT (Tailscale), link-local, or inIP_ALLOWLIST. The error response tells the operator exactly how to unlock it. Local use, LAN access from your phone, container-to-container traffic on Docker bridges, Kubernetes pods, and Tailscale peers all keep working with zero configuration.BASIC_AUTH_USER+BASIC_AUTH_PASS— the browser shows a native password prompt; credentials are checked withtimingSafeEqual. Pair with HTTPS via the existingSSL_CERT/SSL_KEY.IP_ALLOWLIST.ALLOW_UNAUTHENTICATED_REMOTE=trueto opt back into the legacy open-access behaviour for public IPs as well.IP_ALLOWLISTcompose cleanly: the allowlist runs first (so blocked IPs never even reach the auth path), and any IP it vouches for is exempt from the password prompt — so e.g. a remote office at a fixed public IP can be allowlisted and skip the password.BASIC_AUTH_*, the password is required from every IP except loopback and explicitIP_ALLOWLISTmatches — including from your LAN. If you set a password, you mean it./api/healthis exempt so external uptime monitors and load balancers can probe the server without credentials.Behaviour matrix
POST UPDATED MATRIX SCREENSHOT HERE
New configuration
All env vars are documented in
docs/CONFIGURATION.mdand.env.example:BASIC_AUTH_USERBASIC_AUTH_PASSBASIC_AUTH_REALMMarinara EngineIP_ALLOWLIST_ENABLEDtrueALLOW_UNAUTHENTICATED_REMOTEfalseThere are no default credentials baked in anywhere —
BASIC_AUTH_USERandBASIC_AUTH_PASSstart unset, and the lockdown rejects all public-internet requests rather than accepting anything until the operator sets real values.Files
packages/server/src/middleware/basic-auth.ts— newonRequesthook, timing-safe credential comparison, public-only lockdown logic.packages/server/src/middleware/ip-allowlist.ts— extractedisLoopbackIp,isInIpAllowlist, andisPrivateNetworkIphelpers (no behaviour change to the existing hook).packages/server/src/config/runtime-config.ts—getBasicAuthConfig,isUnauthenticatedRemoteAllowed, andIP_ALLOWLIST_ENABLEDtoggle.packages/server/src/app.ts— registers the new hook after the IP allowlist..env.example,docs/CONFIGURATION.md— documents the new vars and the new "Access Control" section.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.