[PR #7934] [MERGED] refactor(server): one shared access-policy decision (#7911 prep) #8010

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7934
Author: @Gunterlie
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/21/2026
Merged by: @Gunterlie

Base: staging ← Head: chore/access-policy-7911


📝 Commits (2)

  • 754903d refactor(server): extract access decision into pure access-policy module (#7911)
  • 2503c47 refactor(server): memoize access policy per request, extend regression (#7911)

📊 Changes

5 files changed (+403 additions, -105 deletions)

View changed files

➕ packages/server/src/middleware/access-policy.ts (+156 -0)
📝 packages/server/src/middleware/basic-auth.ts (+10 -25)
📝 packages/server/src/middleware/ip-allowlist.ts (+87 -68)
📝 packages/server/src/middleware/privileged-gate.ts (+4 -12)
➕ scripts/regressions/access-policy.regression.ts (+146 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Part of #7911 (parent #7909). Prep slice; the owner-facing status lands in a follow-up PR.

Why this change

#7911 wants the owner to see, in Settings, who can reach their Marinara and why. Today the answer is spread across basic-auth.ts, ip-allowlist.ts and privileged-gate.ts, each with its own copy of the loopback / forwarded / allowlist / Docker / Tailscale logic. A status screen built on top of that would be a fourth copy that can drift from what the hooks actually enforce — exactly the kind of drift behind GHSA-25hr. This PR puts the decision in one pure function that the hooks call, so the status screen can later report the same answer the server enforces.

No access decision changes. An adversarial review compared old vs new for every hook and case (plain / forwarded / relayed-Host loopback, own hostname, :authority, LAN with and without opt-in, allowlist set/unset/unparseable, Tailscale, Docker gateway with and without forwarding headers and REQUIRE_AUTH_FOR_DOCKER_PROXY, basic auth on/off, runtime-config hot reload) and found no case that became more permissive.

What changed

  • New packages/server/src/middleware/access-policy.ts: evaluateAccessPolicy(facts) — pure, plain data in and out (local, forwardedLoopback, trustedPeer, trustedInterface, allowlisted, ipAllowed, authRequired, lockedDown, basicAuthConfigured, adminSecretConfigured, reason).
  • ip-allowlist.ts: getAccessPolicy(request) gathers the facts and memoizes them per request (WeakMap), so hooks that ask several times pay once; getRequestAccess adds the existing once-per-process bypass warnings. ipAllowlistHook, isTrustedInterfaceRequest, isForwardedLoopbackRequest use it.
  • basic-auth.ts, privileged-gate.ts: call getRequestAccess instead of their own copies.
  • New scripts/regressions/access-policy.regression.ts pinning the decision for loopback variants, own hostname, LAN, allowlist, Tailscale, remote opt-in, and Docker gateway cases.

Known difference: the Tailscale/Docker bypass warnings (still once per process) can now be logged on the first non-loopback request through any hook rather than only at the trusted-interface check. Trigger conditions are unchanged.

Validation

  • pnpm check (full) passes locally.

  • Regressions passing locally: access-policy, loopback-proxy-auth-security, docker-gateway-auth-security, docker-proxy-auth, basic-auth-throttle-security, request-host-security, multiplayer-control-security, android-local-auth.

  • Local CodeRabbit: 2 trivial findings (stale doc comment, eager per-request facts), both fixed.

  • 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

  • Manually verify local browser on the same machine still opens without a password.
  • Manually verify a LAN device is still asked for credentials when basic auth is set, and blocked when it is not (without the private-network opt-in).
  • Manually verify a same-host reverse proxy with X-Forwarded-For still requires auth.
  • Manually verify Docker Desktop LAN access behaves as on staging.

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)

UI evidence (if applicable)

Server-only; no UI change.

Summary by CodeRabbit

  • Bug Fixes

    • Improved access decisions for local, forwarded, private-network, remote, Tailscale, and Docker connections.
    • Correctly applies authentication and IP allowlist requirements across trusted and forwarded requests.
    • Prevents automatic Docker trust when authentication or an IP allowlist is configured.
    • Adds clearer locked-down and password-required outcomes for restricted access.
    • Preserves proxy authentication requirements for forwarded trusted traffic when enabled.
  • Tests

    • Added regression coverage for network access, authentication, allowlists, bypass settings, forwarding, and proxy behavior.

🔄 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/7934 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/21/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `staging` ← **Head:** `chore/access-policy-7911` --- ### 📝 Commits (2) - [`754903d`](https://github.com/Pasta-Devs/Marinara-Engine/commit/754903d5e6e638aaa9807c50ca493e19e051e860) refactor(server): extract access decision into pure access-policy module (#7911) - [`2503c47`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2503c479add9f2b000212d799ccdaa21bcd3d38e) refactor(server): memoize access policy per request, extend regression (#7911) ### 📊 Changes **5 files changed** (+403 additions, -105 deletions) <details> <summary>View changed files</summary> ➕ `packages/server/src/middleware/access-policy.ts` (+156 -0) 📝 `packages/server/src/middleware/basic-auth.ts` (+10 -25) 📝 `packages/server/src/middleware/ip-allowlist.ts` (+87 -68) 📝 `packages/server/src/middleware/privileged-gate.ts` (+4 -12) ➕ `scripts/regressions/access-policy.regression.ts` (+146 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Part of #7911 (parent #7909). Prep slice; the owner-facing status lands in a follow-up PR. ## Why this change #7911 wants the owner to see, in Settings, who can reach their Marinara and why. Today the answer is spread across `basic-auth.ts`, `ip-allowlist.ts` and `privileged-gate.ts`, each with its own copy of the loopback / forwarded / allowlist / Docker / Tailscale logic. A status screen built on top of that would be a fourth copy that can drift from what the hooks actually enforce — exactly the kind of drift behind GHSA-25hr. This PR puts the decision in one pure function that the hooks call, so the status screen can later report the same answer the server enforces. **No access decision changes.** An adversarial review compared old vs new for every hook and case (plain / forwarded / relayed-Host loopback, own hostname, `:authority`, LAN with and without opt-in, allowlist set/unset/unparseable, Tailscale, Docker gateway with and without forwarding headers and `REQUIRE_AUTH_FOR_DOCKER_PROXY`, basic auth on/off, runtime-config hot reload) and found no case that became more permissive. ## What changed - New `packages/server/src/middleware/access-policy.ts`: `evaluateAccessPolicy(facts)` — pure, plain data in and out (`local`, `forwardedLoopback`, `trustedPeer`, `trustedInterface`, `allowlisted`, `ipAllowed`, `authRequired`, `lockedDown`, `basicAuthConfigured`, `adminSecretConfigured`, `reason`). - `ip-allowlist.ts`: `getAccessPolicy(request)` gathers the facts and memoizes them per request (`WeakMap`), so hooks that ask several times pay once; `getRequestAccess` adds the existing once-per-process bypass warnings. `ipAllowlistHook`, `isTrustedInterfaceRequest`, `isForwardedLoopbackRequest` use it. - `basic-auth.ts`, `privileged-gate.ts`: call `getRequestAccess` instead of their own copies. - New `scripts/regressions/access-policy.regression.ts` pinning the decision for loopback variants, own hostname, LAN, allowlist, Tailscale, remote opt-in, and Docker gateway cases. Known difference: the Tailscale/Docker bypass warnings (still once per process) can now be logged on the first non-loopback request through any hook rather than only at the trusted-interface check. Trigger conditions are unchanged. ## Validation - `pnpm check` (full) passes locally. - Regressions passing locally: access-policy, loopback-proxy-auth-security, docker-gateway-auth-security, docker-proxy-auth, basic-auth-throttle-security, request-host-security, multiplayer-control-security, android-local-auth. - Local CodeRabbit: 2 trivial findings (stale doc comment, eager per-request facts), both fixed. - [ ] `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 - Manually verify local browser on the same machine still opens without a password. - Manually verify a LAN device is still asked for credentials when basic auth is set, and blocked when it is not (without the private-network opt-in). - Manually verify a same-host reverse proxy with `X-Forwarded-For` still requires auth. - Manually verify Docker Desktop LAN access behaves as on staging. ## 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) ## UI evidence (if applicable) Server-only; no UI change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **Bug Fixes** - Improved access decisions for local, forwarded, private-network, remote, Tailscale, and Docker connections. - Correctly applies authentication and IP allowlist requirements across trusted and forwarded requests. - Prevents automatic Docker trust when authentication or an IP allowlist is configured. - Adds clearer locked-down and password-required outcomes for restricted access. - Preserves proxy authentication requirements for forwarded trusted traffic when enabled. - **Tests** - Added regression coverage for network access, authentication, allowlists, bypass settings, forwarding, and proxy behavior. <!-- 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:38 +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#8010
No description provided.