mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7824] [MERGED] fix(security): harden regex scripts and password checks #7950
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#7950
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/7824
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/harden-server-hardening📝 Commits (4)
10e51aefix(security): harden regex scripts and password checks6e948edfix(security): keep signed-in browsers working during a password locka369732fix(security): key the signed-in cookie by a server secret935f2dcfix(security): count signed-in health checks against their tries📊 Changes
9 files changed (+605 additions, -30 deletions)
View changed files
📝
docs/REMOTE_ACCESS.md(+2 -0)📝
docs/TROUBLESHOOTING.md(+1 -0)📝
packages/server/src/middleware/android-local-auth.ts(+1 -1)📝
packages/server/src/middleware/basic-auth.ts(+166 -10)📝
packages/server/src/services/lorebook/regex-timeout.ts(+27 -14)📝
packages/server/src/services/regex/regex-application.ts(+3 -4)📝
packages/server/src/utils/crypto.ts(+6 -1)➕
scripts/regressions/basic-auth-throttle-security.regression.ts(+296 -0)➕
scripts/regressions/regex-script-timeout-security.regression.ts(+103 -0)📄 Description
Linked issue
No linked issue: this comes from an internal security review. @SpicyMarinara
Why this change
/apirate limit. Requests for the page and static files had no limit and no log line, so password guesses there were never slowed down or noticed.What changed
/64counts as one) on every path,/api/healthincluded, separately from the/apirate limits. After 10 different wrong passwords within 15 minutes, that address gets429withRetry-Afteruntil the window ends, even with the right password. The first wrong password from an address and reaching the limit are both logged at warn. A correct password clears the count. A browser that keeps resending one old saved password counts once, and a request without a password does not count. During the block,/api/healthstill answers but gives only the public reply.marinara_signed_in). Its value is an HMAC of the credentials keyed by a key derived from the persisted server encryption key, so it survives restarts and changes with the password, but cannot be worked out from the password alone. While an address is blocked, a browser with that cookie gets 10 more tries, so it still gets in with the correct password and other visitors' wrong passwords cannot lock the owner out of a device they already use, including behind a tunnel where every visitor shares one address. The cookie does nothing without the password, and a signed-in browser getting past a lock leaves the lock in place. It is markedSecureon HTTPS, including HTTPS reported by a local proxy. New browsers on a blocked address still wait for the window to end.IP_ALLOWLISTand trusted Tailscale/Docker peers still skip the password and are never counted. Visitors forwarded by a local reverse proxy or tunnel still have to sign in (the rules from #7816), and they share one count because they all arrive from loopback. One of them signing in does not clear that shared count.docs/REMOTE_ACCESS.mdanddocs/TROUBLESHOOTING.mdexplain the wrong-password limit.scripts/regressions/regex-script-timeout-security.regression.tsandscripts/regressions/basic-auth-throttle-security.regression.ts. Both fail onstagingand pass with this change. The regex one stops at its time budget, whichstagingexceeds by about 60 s on a 31-character message. The auth one gets200where429is expected, and (added after review) gets no signed-in cookie where one is expected.Regex timing
applyRegexScriptsToPromptMessages, 4 prompt scripts (the built-in Clean HTML plus three common ones), median over 100 runs. The machine was under heavy load, so treat these as relative. Output was the same byte for byte in every case.A single guarded call now costs about 0.07–0.14 ms, down from about 0.7 ms.
Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands the agent ran (results are in the PR conversation, not ticked above):
pnpm check: passed.pnpm regression:security: 23 of 25 passed.multiplayer-control-securityandencoded-api-path-securityhit the runner's 30 s limit while the machine was very busy (load average 45–70). Run again on their own,encoded-api-path-securitypassed in 15 s andmultiplayer-control-securitypassed in 29 s without the limit. Neither sends a wrong password.loopback-proxy-auth-security,docker-gateway-auth-security,docker-proxy-auth,android-local-auth,multiplayer-peer-server-security,route-rate-limits,prompt,group-prompt-regex,preset-regex-defaultsand everylorebookregression (23 files): passed.stagingcode: both fail there.6e948eded):pnpm checkpassed;pnpm regression:securitypassed (25/25 plus the extra suites);basic-auth-throttle-securityfails on the previous head and passes now;loopback-proxy-auth-security,route-rate-limitsandmultiplayer-peer-server-securitypassed.Securebehind a local HTTPS proxy,a36973201):pnpm checkpassed;basic-auth-throttle-securityfails on6e948ededand passes now;loopback-proxy-auth-security,docker-gateway-auth-security,docker-proxy-auth,android-local-authandroute-rate-limitspassed. The results of a fullpnpm regression:securityrerun are in a PR comment./api/healthcounts a signed-in browser's passwords against its extra tries,935f2dce8):pnpm format:checkand the server lint (tsc) passed;basic-auth-throttle-securityfails ona36973201and passes now.Manual verification notes
BASIC_AUTH_USERandBASIC_AUTH_PASSset, open the app from another device and enter 10 different wrong passwords: manually verify that the next try shows "Too many wrong passwords" (429) and that the server log has one warn line for the first wrong password and one for the limit.BASIC_AUTH_PASSis asked again and is not blocked.marinara_signed_inas HttpOnly after signing in (and Secure when opened over HTTPS, for example through a tunnel), and that after changingBASIC_AUTH_PASSthat browser is asked for the new password..encryption-keyin the data folder if it is not there yet, and that remembered browsers keep working after a server restart.127.0.0.1) stays passwordless, and that a reverse proxy or tunnel on the host still asks its visitors to sign in.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)English docs changed:
docs/REMOTE_ACCESS.md,docs/TROUBLESHOOTING.md(the release translation sweep picks these up).UI evidence (if applicable)
No UI changes.
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.