[PR #8070] [MERGED] feat(server): set the first login from the lockdown page with the setup code (#7912) #8088

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

📋 Pull Request Information

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

Base: feat/7912-remote-login ← Head: feat/lockdown-setup-7912


📝 Commits (8)

  • a8d781a feat(server): set the first login from the lockdown page with the setup code (#7912)
  • 9d7cb64 docs: describe the first login from any device with the setup code (#7912)
  • 1f0038e test: expect the setup form, not an allowlist snippet, on the LAN lockdown page (#7912)
  • 52279de fix: format the lockdown page, isolate its regression data, split the troubleshooting bullet (#7912)
  • 6403127 fix(server): print a new setup code when saving the login fails, name the setup code in the lockdown log (#7912)
  • 4ea6ca1 fix(server): let the lockdown setup form pass CSRF from real browsers, cap public form bodies (#7912)
  • 245571a fix(server): offer the setup form to proxied visitors when a code exists, clarify the Docker reset (#7912)
  • 09c5a4c fix(server): keep setup-code guesses off the password lockout and away from proxied visitors (#7912)

📊 Changes

11 files changed (+413 additions, -76 deletions)

View changed files

📝 README.md (+1 -1)
📝 docs/CONFIGURATION.md (+2 -0)
📝 docs/FAQ.md (+3 -3)
📝 docs/REMOTE_ACCESS.md (+31 -21)
📝 docs/TROUBLESHOOTING.md (+3 -2)
📝 docs/UPGRADING.md (+1 -1)
📝 packages/server/src/config/login-credential.ts (+7 -1)
📝 packages/server/src/middleware/basic-auth.ts (+128 -44)
📝 packages/server/src/middleware/csrf-protection.ts (+2 -2)
➕ scripts/regressions/lockdown-setup-security.regression.ts (+233 -0)
📝 scripts/regressions/loopback-proxy-auth-security.regression.ts (+2 -1)

📄 Description

PR 4 of 4 into the #7912 integration branch (feat/7912-remote-login). Builds on PR 1 (stored login, setup code, /login, sessions) and PR 2 (TRUSTED_AUTH_PROXY). Rebased onto the integration branch after PR 3 (#8061) merged.

Why

  • Docker and NAS owners have no browser on the host. Today the one-time setup code only works through PUT /api/access/login, which a refused remote device cannot reach from the lockdown page. So these owners must edit .env by hand. Now the lockdown page has a form: setup code (from the server log, e.g. docker logs) + username + password. The first login is set from any device, and that device stays signed in.
  • The lockdown page should not advertise ways around itself. It used to invite the visitor to add their IP to IP_ALLOWLIST. The page and its JSON message now offer only a login (setup form, Settings on the host, or BASIC_AUTH_USER/BASIC_AUTH_PASS). The "equal bypass option" text in docs/REMOTE_ACCESS.md goes too.

What changed

  • POST /login/setup (server-rendered form on the lockdown page): checks the setup code with the existing constant-time compare (isLoginSetupCode), consumes it before the first await so it stays single-use, saves the login, starts a browser session, redirects to /.
  • Wrong codes reuse the counter code (countGuess / lockoutSeconds) but in their own bucket, per direct address only: 10 wrong codes give that address 429 + Retry-After on the setup form, and never lock /login. Visitors behind a proxy on this computer share one address, so they are not counted (the code is 96 random bits and single-use); otherwise a stranger behind Tailscale Serve or a tunnel could keep the owner out. Wrong codes log as "Wrong setup code from …".
  • The form shows for a direct remote visitor, and for a visitor through a proxy on this computer while a setup code exists. Without a code (e.g. Tailscale Serve to a loopback-bound server, which prints none) the page says "set a login in Settings on this computer".
  • CSRF: the page sets <meta name="referrer" content="same-origin"> (as the /login page does), so the form posts its real Origin, and /login/setup shares the same-origin shortcut of /login, including sameServerOrigin for plain HTTP.
  • /login and /login/setup accept at most 8 KB bodies (413), because anyone can post them during lockdown.
  • If saving the login fails after the code is used, the server logs the error, prints a new setup code, and the page says so.
  • The owner-facing lockdown log line now names the setup code, Settings and .env first; IP_ALLOWLIST stays there for the owner.
  • The sign-in and setup pages share one form CSS block.
  • The code is never shown on the page; the page only says where to find it.
  • Docs: first-login flow, pnpm reset-login, "Add a device" pairing codes, and an upgrade note for same-host proxy users without a password.
  • New regression scripts/regressions/lockdown-setup-security.regression.ts: form and referrer meta shown, code not leaked, no bypass flag names in the HTML pages (direct, proxied, 400, 403, 429, 500, success) or JSON replies (direct and proxied), 12 wrong proxied codes then the right code → 303, wrong setup codes do not lock /login, browser-like headers (same-origin passes, plain-HTTP own Origin passes, cross-site and Origin: null refused), 413 for large bodies, a failed save prints a new code, wrong codes lock out, right code sets the login and a session, code works once.

Manual verification

  • Start with no login and HOST=0.0.0.0; open the app from a phone on the LAN. The lockdown page shows the setup form and says where the code is.
  • Type the setup code from the server log plus a username and a 10+ character password. You land in the app signed in.
  • Reload the phone; you stay signed in. Another device gets the /login page.
  • Use the same code again from another device; it does not work.
  • Type a wrong code 10 times from one device; the page says to try again later.
  • Docker: the code is visible with docker logs <container> and works on the lockdown page.
  • Tailscale Serve (or another same-host proxy) to a loopback-bound server, no login: the page tells you to set a login in Settings on the host; after that, sign-in through the proxy works.
  • Check the lockdown page at 390 px and 1440 px.

Release note

  • A device that the server refuses can now set the first login itself: type the one-time setup code from the server log (for Docker: docker logs) plus a username and password on the lockdown page.
  • Upgrade note: if you reach Marinara through Tailscale Serve or another proxy on the same computer and have no password set, remote devices are locked out after this update. Set a login in Settings on the computer that runs Marinara, or set BASIC_AUTH_USER and BASIC_AUTH_PASS in .env.

Local validation

  • heavy pnpm check → exit 0 (see the latest run in the agent report).
  • pnpm --filter @marinara-engine/server lint (server tsc) → exit 0.
  • node scripts/run-regressions.mjs --filter lockdown 1/1, --filter auth 6/6, --filter remote-login 1/1, --filter access-status 1/1.
  • The new regression fails without the /login/setup CSRF shortcut (checked by reverting it once).
  • The new regression fails when setup codes use the shared password buckets (12 proxied wrong codes then hit 429; checked by reverting once).
  • Native server proof (HOST=0.0.0.0, request from the host's LAN IP with browser headers): lockdown page 403 with form and referrer meta; right code with Origin over plain HTTP → 303 + session cookie; cross-site Origin → 403; 10 KB sign-in body → 413.

Local CodeRabbit review

  • Run 1: 2 findings, both fixed (isolated DATA_DIR in the regression; split Troubleshooting bullet).
  • Run 2 (after rebase): 3 findings. Fixed: proxied visitors see the form when a code exists; the Docker reset line now covers a custom DATA_DIR. Not changed: "remove the internal file name from CONFIGURATION.md" — that file is the server configuration reference, and the file name tells Docker owners which file holds the app login (.env.example names it too).

Follow-ups

  • docs-i18n: the docs/ changes from PR 2 (TRUSTED_AUTH_PROXY) and this PR need a [docs-i18n] follow-up for the translated language packs.

Linked issue: #7912


🔄 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/8070 **Author:** [@Gunterlie](https://github.com/Gunterlie) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@Gunterlie](https://github.com/Gunterlie) **Base:** `feat/7912-remote-login` ← **Head:** `feat/lockdown-setup-7912` --- ### 📝 Commits (8) - [`a8d781a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a8d781a2aaec651120ef9ee04824820a5e79e794) feat(server): set the first login from the lockdown page with the setup code (#7912) - [`9d7cb64`](https://github.com/Pasta-Devs/Marinara-Engine/commit/9d7cb64990574e5b920cbd38d1760d2821a3c0b8) docs: describe the first login from any device with the setup code (#7912) - [`1f0038e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1f0038ee9b7185b3fab999a2a9c5f0f04a9c41df) test: expect the setup form, not an allowlist snippet, on the LAN lockdown page (#7912) - [`52279de`](https://github.com/Pasta-Devs/Marinara-Engine/commit/52279de5bf0537ebf8e418d91a7d4427e245ad6e) fix: format the lockdown page, isolate its regression data, split the troubleshooting bullet (#7912) - [`6403127`](https://github.com/Pasta-Devs/Marinara-Engine/commit/64031272a526d5a6aabeb1b3e4c7326bc747086c) fix(server): print a new setup code when saving the login fails, name the setup code in the lockdown log (#7912) - [`4ea6ca1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/4ea6ca113056a23d390c408bb4939e45ece74e87) fix(server): let the lockdown setup form pass CSRF from real browsers, cap public form bodies (#7912) - [`245571a`](https://github.com/Pasta-Devs/Marinara-Engine/commit/245571a5b7f45ac1ce7a8cb67372ee6cbee6bf2e) fix(server): offer the setup form to proxied visitors when a code exists, clarify the Docker reset (#7912) - [`09c5a4c`](https://github.com/Pasta-Devs/Marinara-Engine/commit/09c5a4c2a09fdea8ac131f665408dea2e2edfd47) fix(server): keep setup-code guesses off the password lockout and away from proxied visitors (#7912) ### 📊 Changes **11 files changed** (+413 additions, -76 deletions) <details> <summary>View changed files</summary> 📝 `README.md` (+1 -1) 📝 `docs/CONFIGURATION.md` (+2 -0) 📝 `docs/FAQ.md` (+3 -3) 📝 `docs/REMOTE_ACCESS.md` (+31 -21) 📝 `docs/TROUBLESHOOTING.md` (+3 -2) 📝 `docs/UPGRADING.md` (+1 -1) 📝 `packages/server/src/config/login-credential.ts` (+7 -1) 📝 `packages/server/src/middleware/basic-auth.ts` (+128 -44) 📝 `packages/server/src/middleware/csrf-protection.ts` (+2 -2) ➕ `scripts/regressions/lockdown-setup-security.regression.ts` (+233 -0) 📝 `scripts/regressions/loopback-proxy-auth-security.regression.ts` (+2 -1) </details> ### 📄 Description PR 4 of 4 into the #7912 integration branch (`feat/7912-remote-login`). Builds on PR 1 (stored login, setup code, `/login`, sessions) and PR 2 (`TRUSTED_AUTH_PROXY`). Rebased onto the integration branch after PR 3 (#8061) merged. ## Why - **Docker and NAS owners have no browser on the host.** Today the one-time setup code only works through `PUT /api/access/login`, which a refused remote device cannot reach from the lockdown page. So these owners must edit `.env` by hand. Now the lockdown page has a form: setup code (from the server log, e.g. `docker logs`) + username + password. The first login is set from any device, and that device stays signed in. - **The lockdown page should not advertise ways around itself.** It used to invite the visitor to add their IP to `IP_ALLOWLIST`. The page and its JSON message now offer only a login (setup form, Settings on the host, or `BASIC_AUTH_USER`/`BASIC_AUTH_PASS`). The "equal bypass option" text in `docs/REMOTE_ACCESS.md` goes too. ## What changed - `POST /login/setup` (server-rendered form on the lockdown page): checks the setup code with the existing constant-time compare (`isLoginSetupCode`), consumes it before the first `await` so it stays single-use, saves the login, starts a browser session, redirects to `/`. - Wrong codes reuse the counter code (`countGuess` / `lockoutSeconds`) but in their own bucket, per direct address only: 10 wrong codes give that address 429 + `Retry-After` on the setup form, and never lock `/login`. Visitors behind a proxy on this computer share one address, so they are not counted (the code is 96 random bits and single-use); otherwise a stranger behind Tailscale Serve or a tunnel could keep the owner out. Wrong codes log as "Wrong setup code from …". - The form shows for a direct remote visitor, and for a visitor through a proxy on this computer while a setup code exists. Without a code (e.g. Tailscale Serve to a loopback-bound server, which prints none) the page says "set a login in Settings on this computer". - CSRF: the page sets `<meta name="referrer" content="same-origin">` (as the `/login` page does), so the form posts its real Origin, and `/login/setup` shares the same-origin shortcut of `/login`, including `sameServerOrigin` for plain HTTP. - `/login` and `/login/setup` accept at most 8 KB bodies (413), because anyone can post them during lockdown. - If saving the login fails after the code is used, the server logs the error, prints a new setup code, and the page says so. - The owner-facing lockdown log line now names the setup code, Settings and `.env` first; `IP_ALLOWLIST` stays there for the owner. - The sign-in and setup pages share one form CSS block. - The code is never shown on the page; the page only says where to find it. - Docs: first-login flow, `pnpm reset-login`, "Add a device" pairing codes, and an upgrade note for same-host proxy users without a password. - New regression `scripts/regressions/lockdown-setup-security.regression.ts`: form and referrer meta shown, code not leaked, no bypass flag names in the HTML pages (direct, proxied, 400, 403, 429, 500, success) or JSON replies (direct and proxied), 12 wrong proxied codes then the right code → 303, wrong setup codes do not lock `/login`, browser-like headers (same-origin passes, plain-HTTP own Origin passes, cross-site and `Origin: null` refused), 413 for large bodies, a failed save prints a new code, wrong codes lock out, right code sets the login and a session, code works once. ## Manual verification - [ ] Start with no login and `HOST=0.0.0.0`; open the app from a phone on the LAN. The lockdown page shows the setup form and says where the code is. - [ ] Type the setup code from the server log plus a username and a 10+ character password. You land in the app signed in. - [ ] Reload the phone; you stay signed in. Another device gets the `/login` page. - [ ] Use the same code again from another device; it does not work. - [ ] Type a wrong code 10 times from one device; the page says to try again later. - [ ] Docker: the code is visible with `docker logs <container>` and works on the lockdown page. - [ ] Tailscale Serve (or another same-host proxy) to a loopback-bound server, no login: the page tells you to set a login in Settings on the host; after that, sign-in through the proxy works. - [ ] Check the lockdown page at 390 px and 1440 px. ## Release note - A device that the server refuses can now set the first login itself: type the one-time setup code from the server log (for Docker: `docker logs`) plus a username and password on the lockdown page. - **Upgrade note:** if you reach Marinara through Tailscale Serve or another proxy on the same computer and have no password set, remote devices are locked out after this update. Set a login in Settings on the computer that runs Marinara, or set `BASIC_AUTH_USER` and `BASIC_AUTH_PASS` in `.env`. ## Local validation - `heavy pnpm check` → exit 0 (see the latest run in the agent report). - `pnpm --filter @marinara-engine/server lint` (server tsc) → exit 0. - `node scripts/run-regressions.mjs --filter lockdown` 1/1, `--filter auth` 6/6, `--filter remote-login` 1/1, `--filter access-status` 1/1. - The new regression fails without the `/login/setup` CSRF shortcut (checked by reverting it once). - The new regression fails when setup codes use the shared password buckets (12 proxied wrong codes then hit 429; checked by reverting once). - Native server proof (`HOST=0.0.0.0`, request from the host's LAN IP with browser headers): lockdown page 403 with form and referrer meta; right code with `Origin` over plain HTTP → 303 + session cookie; cross-site Origin → 403; 10 KB sign-in body → 413. ## Local CodeRabbit review - Run 1: 2 findings, both fixed (isolated `DATA_DIR` in the regression; split Troubleshooting bullet). - Run 2 (after rebase): 3 findings. Fixed: proxied visitors see the form when a code exists; the Docker reset line now covers a custom `DATA_DIR`. Not changed: "remove the internal file name from CONFIGURATION.md" — that file is the server configuration reference, and the file name tells Docker owners which file holds the app login (`.env.example` names it too). ## Follow-ups - docs-i18n: the `docs/` changes from PR 2 (`TRUSTED_AUTH_PROXY`) and this PR need a `[docs-i18n]` follow-up for the translated language packs. Linked issue: #7912 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:10:16 +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#8088
No description provided.