[PR #8775] [MERGED] fix(server): keep sign-in lockouts when the count table is full #8798

Closed
opened 2026-11-07 17:39:46 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8775
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/hardening-login-lockout


📝 Commits (1)

  • e609dce fix(server): keep sign-in lockouts when the count table is full

📊 Changes

2 files changed (+91 additions, -10 deletions)

View changed files

📝 packages/server/src/middleware/basic-auth.ts (+35 -9)
📝 scripts/regressions/basic-auth-throttle-security.regression.ts (+56 -1)

📄 Description

Important

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

Linked issue

Closes #8769

Why this change

The sign-in throttle counts wrong passwords and codes per client address. After 10 different wrong ones it refuses that address for 15 minutes, as docs/REMOTE_ACCESS.md describes. Two gaps let a password be checked outside that count. First, the counts live in a table capped at 4096 clients. When it was full of live entries, the oldest entry was dropped to make room, even if that client was still locked, so its lockout could end early. Second, the sign-in page compared a Basic Authorization header, and the throttle does not count that path. This change keeps every running count when the table is full. It refuses clients the table cannot count before any password or code is compared. It also stops the sign-in page from comparing headers. Every password or code the server compares is now counted.

What changed

  • Stops working: a Basic Authorization header sent to the sign-in page (GET /login) no longer skips it. The page sends you on only when the request comes from this computer, IP_ALLOWLIST or a trusted Tailscale/Docker peer, or from a browser that is signed in. Everyone else sees the sign-in form. Basic headers on every other path work as before.
  • Stops working while the count table is full (4096 client addresses with a running wrong-password count): a client with no count yet cannot sign in with a password or code, even the right one. A password gets the existing 429 "Too many sign-ins at once. Try again in a moment." on every path, including changing the login from a remote browser. The pairing-code form gets a 429 page with the same text. A setup code gets the existing 429 "Too many wrong codes" reply. The health probe gives only its public reply. Previously the oldest count was dropped to make room.
  • A locked-out client stays locked out for its full 15 minutes, however many other clients are being counted.
  • Not affected by a full table: browsers that are signed in, clients that already have a running count, and this computer, IP_ALLOWLIST and trusted Tailscale/Docker peers. Room frees up as soon as earlier counts reach the end of their window.
  • The Basic Auth throttle regression now checks that a full table keeps a lock. It checks that a client without room gets the same reply for the right password as for a wrong one on a page, the API and the health probe. It checks that pairing and setup codes wait, and that counted clients, signed-in browsers and this computer still get in. It also checks that the sign-in page shows the form when a request carries a right Basic header.

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

Manual verification notes

  • Manually verify that on a remote install with a login, 10 different wrong passwords from one device give 429 for 15 minutes, and that the right password before the limit signs in.
  • Manually verify in a browser that opening /login while signed in sends you on to the app, and that opening /login on the host computer (localhost) does too.
  • Manually verify that a script using Basic auth (for example curl -u user:password against an /api path on a remote install) still works, and that opening /login with such a header now shows the sign-in form instead of redirecting.
  • Manually verify that signing in with a pairing code (Settings > Advanced > Access > Add a device) and with the lockdown setup code still works normally.
  • Manually verify that changing or removing the remote login from a signed-in remote browser (Settings > Advanced > Access) still asks for and accepts the current password.

Agent-run checks (for reference; each regression was shown to fail without its fix):

  • git fetch origin staging; git log -1 origin/staging: aed5e3578d, unchanged since the fixer's check; the finding still applies
  • node ./scripts/pnpm-runner.mjs build:shared: succeeded
  • node ./scripts/run-regressions.mjs --filter basic-auth-throttle-security (final fix): PASSED 1/1
  • Same regression against origin/staging basic-auth.ts, and against the previous branch commit a84564d7bf: Both FAILED at 'the right password gets the page' (actual 302, expected 200)
  • Same regression against origin/staging basic-auth.ts with only the GET /login change applied: FAILED at 'the lock outlasts a full table' (actual 200, expected 429), so the eviction is still caught
  • Same regression with each guard removed on its own: the checkCredentials room check, the isBasicAuthSatisfied room check, the GET /login change (file copied asi: FAILED as expected: actual 200 vs 429; actual {status:'ok',sidecars:{}} vs {status:'ok'}; actual 302 vs 200. PASSED again once restored
  • node ./scripts/run-regressions.mjs --filter scripts/regressions/<name>.regression.ts for remote-login, loopback-proxy-auth-security, docker-proxy-auth, lockdown: All 12 passed (1/1 each). These cover every regression that imports basic-auth, privileged-gate or notices, or calls /api/health
  • cd packages/server && node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activ: exit 0
  • node_modules/.bin/prettier --write and --check on both changed files: unchanged; check passed
  • ESLint: Not run: ESLint is configured only for packages/client. The server 'lint' script is tsc, which passed. No client copy changed, so localization:check was not needed

Independent adversarial review: changes, 3 issue(s), all addressed in a fix-up pass.

Known limits and risks:

All three review issues held up against the code, so none were rejected.

Trade-off, now stated in the ponytail comment: someone who controls more than 4096 IPv4 addresses or IPv6 /64s can fill the table. While it stays full, any client that has no count yet cannot sign in with a password, pairing code or setup code for up to 15 minutes at a time, and the table can be refilled as counts end. That includes the owner's new devices and Basic-auth scripts from addresses with no count, even with the right .env or app password. A signed-in remote browser that changes or removes the login during that time also gets 429. Signed-in browsers, clients that already have a count, and trusted peers (this computer, IP_ALLOWLIST, trusted Tailscale/Docker) are unaffected. The owner can still change settings from the host computer. This fails closed on purpose. Before, a full table handed guesses back. With the first-pass fix, a client without room could have unlimited uncounted checks.

I chose the reviewer's option (a) over a shared overflow bucket. An attacker who fills the table can exhaust a 50-guess overflow budget almost for free, so the owner lockout would be the same, with more code. The ponytail comment keeps that bucket as the upgrade path. As both verifiers advised, I added no global or /48 budget, because the existing regression pins per-/64 independence.

GET /login no longer redirects on a valid Basic header. Nothing in the repo relied on that. The only client navigation to /login is the sign-out in RemoteLoginSettings.tsx, which sends no header. A browser with cached native-prompt credentials now sees the form on /login and can sign in there.

When the table is full, hasRoomFor sweeps all 4096 entries on each check from a client without a count. This is the same sweep the old countGuess did. It now also runs in isBasicAuthSatisfied, but only while the table is full, and it stays cheap.

Cosmetic, carried over: with no room, the setup code returns 1 second, so the UI says "Too many wrong codes. Try again in 1 minute." No new copy was added.

Docs: unchanged. docs/REMOTE_ACCESS.md's per-address 15-minute claim is now accurate. The full-table refusal is not documented. A TROUBLESHOOTING note on "Too many sign-ins at once" would need a docs-i18n follow-up, so I left it out of this neutral hardening PR.

Git: the unpushed commit a84564d7bf was amended into e609dcef82 so its message matches the diff. Nothing was pushed, no PR was opened, and CHANGELOG.md and version files are untouched.

NOT FOR THE PR BODY, for the user: your relayed request to change Otome Hearth so showing off an outfit to a love interest gives +5 affection instead of +20 was not done here. It is outside this login-throttle worktree, and no outfit-affection logic exists under this repo's packages/. The Otome Hearth (otome-forge) package lives outside Marinara Engine, so it needs its own change in the repository and branch that own that package.

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)

🤖 Generated with Claude Code


🔄 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/8775 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/3/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/hardening-login-lockout` --- ### 📝 Commits (1) - [`e609dce`](https://github.com/Pasta-Devs/Marinara-Engine/commit/e609dcef82048fd36830ec4e8c93b0bc292bcc95) fix(server): keep sign-in lockouts when the count table is full ### 📊 Changes **2 files changed** (+91 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/middleware/basic-auth.ts` (+35 -9) 📝 `scripts/regressions/basic-auth-throttle-security.regression.ts` (+56 -1) </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 Closes #8769 ## Why this change The sign-in throttle counts wrong passwords and codes per client address. After 10 different wrong ones it refuses that address for 15 minutes, as docs/REMOTE_ACCESS.md describes. Two gaps let a password be checked outside that count. First, the counts live in a table capped at 4096 clients. When it was full of live entries, the oldest entry was dropped to make room, even if that client was still locked, so its lockout could end early. Second, the sign-in page compared a Basic Authorization header, and the throttle does not count that path. This change keeps every running count when the table is full. It refuses clients the table cannot count before any password or code is compared. It also stops the sign-in page from comparing headers. Every password or code the server compares is now counted. ## What changed - Stops working: a Basic Authorization header sent to the sign-in page (GET /login) no longer skips it. The page sends you on only when the request comes from this computer, IP_ALLOWLIST or a trusted Tailscale/Docker peer, or from a browser that is signed in. Everyone else sees the sign-in form. Basic headers on every other path work as before. - Stops working while the count table is full (4096 client addresses with a running wrong-password count): a client with no count yet cannot sign in with a password or code, even the right one. A password gets the existing 429 "Too many sign-ins at once. Try again in a moment." on every path, including changing the login from a remote browser. The pairing-code form gets a 429 page with the same text. A setup code gets the existing 429 "Too many wrong codes" reply. The health probe gives only its public reply. Previously the oldest count was dropped to make room. - A locked-out client stays locked out for its full 15 minutes, however many other clients are being counted. - Not affected by a full table: browsers that are signed in, clients that already have a running count, and this computer, IP_ALLOWLIST and trusted Tailscale/Docker peers. Room frees up as soon as earlier counts reach the end of their window. - The Basic Auth throttle regression now checks that a full table keeps a lock. It checks that a client without room gets the same reply for the right password as for a wrong one on a page, the API and the health probe. It checks that pairing and setup codes wait, and that counted clients, signed-in browsers and this computer still get in. It also checks that the sign-in page shows the form when a request carries a right Basic header. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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 that on a remote install with a login, 10 different wrong passwords from one device give 429 for 15 minutes, and that the right password before the limit signs in. - Manually verify in a browser that opening /login while signed in sends you on to the app, and that opening /login on the host computer (localhost) does too. - Manually verify that a script using Basic auth (for example curl -u user:password against an /api path on a remote install) still works, and that opening /login with such a header now shows the sign-in form instead of redirecting. - Manually verify that signing in with a pairing code (Settings > Advanced > Access > Add a device) and with the lockdown setup code still works normally. - Manually verify that changing or removing the remote login from a signed-in remote browser (Settings > Advanced > Access) still asks for and accepts the current password. Agent-run checks (for reference; each regression was shown to fail without its fix): - `git fetch origin staging; git log -1 origin/staging`: aed5e3578d, unchanged since the fixer's check; the finding still applies - `node ./scripts/pnpm-runner.mjs build:shared`: succeeded - `node ./scripts/run-regressions.mjs --filter basic-auth-throttle-security (final fix)`: PASSED 1/1 - `Same regression against origin/staging basic-auth.ts, and against the previous branch commit a84564d7bf`: Both FAILED at 'the right password gets the page' (actual 302, expected 200) - `Same regression against origin/staging basic-auth.ts with only the GET /login change applied`: FAILED at 'the lock outlasts a full table' (actual 200, expected 429), so the eviction is still caught - `Same regression with each guard removed on its own: the checkCredentials room check, the isBasicAuthSatisfied room check, the GET /login change (file copied asi`: FAILED as expected: actual 200 vs 429; actual {status:'ok',sidecars:{}} vs {status:'ok'}; actual 302 vs 200. PASSED again once restored - `node ./scripts/run-regressions.mjs --filter scripts/regressions/<name>.regression.ts for remote-login, loopback-proxy-auth-security, docker-proxy-auth, lockdown`: All 12 passed (1/1 each). These cover every regression that imports basic-auth, privileged-gate or notices, or calls /api/health - `cd packages/server && node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activ`: exit 0 - `node_modules/.bin/prettier --write and --check on both changed files`: unchanged; check passed - `ESLint`: Not run: ESLint is configured only for packages/client. The server 'lint' script is tsc, which passed. No client copy changed, so localization:check was not needed Independent adversarial review: changes, 3 issue(s), all addressed in a fix-up pass. Known limits and risks: All three review issues held up against the code, so none were rejected. Trade-off, now stated in the ponytail comment: someone who controls more than 4096 IPv4 addresses or IPv6 /64s can fill the table. While it stays full, any client that has no count yet cannot sign in with a password, pairing code or setup code for up to 15 minutes at a time, and the table can be refilled as counts end. That includes the owner's new devices and Basic-auth scripts from addresses with no count, even with the right .env or app password. A signed-in remote browser that changes or removes the login during that time also gets 429. Signed-in browsers, clients that already have a count, and trusted peers (this computer, IP_ALLOWLIST, trusted Tailscale/Docker) are unaffected. The owner can still change settings from the host computer. This fails closed on purpose. Before, a full table handed guesses back. With the first-pass fix, a client without room could have unlimited uncounted checks. I chose the reviewer's option (a) over a shared overflow bucket. An attacker who fills the table can exhaust a 50-guess overflow budget almost for free, so the owner lockout would be the same, with more code. The ponytail comment keeps that bucket as the upgrade path. As both verifiers advised, I added no global or /48 budget, because the existing regression pins per-/64 independence. GET /login no longer redirects on a valid Basic header. Nothing in the repo relied on that. The only client navigation to /login is the sign-out in RemoteLoginSettings.tsx, which sends no header. A browser with cached native-prompt credentials now sees the form on /login and can sign in there. When the table is full, hasRoomFor sweeps all 4096 entries on each check from a client without a count. This is the same sweep the old countGuess did. It now also runs in isBasicAuthSatisfied, but only while the table is full, and it stays cheap. Cosmetic, carried over: with no room, the setup code returns 1 second, so the UI says "Too many wrong codes. Try again in 1 minute." No new copy was added. Docs: unchanged. docs/REMOTE_ACCESS.md's per-address 15-minute claim is now accurate. The full-table refusal is not documented. A TROUBLESHOOTING note on "Too many sign-ins at once" would need a docs-i18n follow-up, so I left it out of this neutral hardening PR. Git: the unpushed commit a84564d7bf was amended into e609dcef82 so its message matches the diff. Nothing was pushed, no PR was opened, and CHANGELOG.md and version files are untouched. NOT FOR THE PR BODY, for the user: your relayed request to change Otome Hearth so showing off an outfit to a love interest gives +5 affection instead of +20 was not done here. It is outside this login-throttle worktree, and no outfit-affection logic exists under this repo's packages/. The Otome Hearth (otome-forge) package lives outside Marinara Engine, so it needs its own change in the repository and branch that own that package. ## 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) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:46 +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#8798
No description provided.