mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #7815] [MERGED] fix(security): harden web origin #7941
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#7941
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/7815
Author: @SpicyMarinara
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/harden-web-origin📝 Commits (3)
617c230fix(security): harden web origin checks for encoded API pathsad03575Merge branch 'staging' into fix/harden-web-origin4e6470atest(security): check API response headers on encoded paths at runtime📊 Changes
6 files changed (+230 additions, -5 deletions)
View changed files
📝
packages/server/src/app.ts(+3 -2)📝
packages/server/src/middleware/compress-json.ts(+2 -1)📝
packages/server/src/middleware/csrf-protection.ts(+3 -1)📝
packages/server/src/middleware/rate-limit.ts(+2 -1)➕
packages/server/src/utils/api-request.ts(+10 -0)➕
scripts/regressions/encoded-api-path-security.regression.ts(+210 -0)📄 Description
Linked issue
None. This is pre-release security hardening from an internal review, so there is no public issue.
Why this change
/api/. The router matches the percent-decoded path, so the raw prefix did not always describe the handler that would run.no-store/ JSON compression hooks should apply to every request that reaches an API handler, however its path is spelled.What changed
csrfProtectionHookchecks every unsafe-method request (POST, PUT, PATCH, DELETE), whatever its path. The existing exact-path exemptions for the Android self-authenticating routes stay the same. No non-API unsafe routes exist, so the app's own requests behave as before.New
isApiRequest()helper (packages/server/src/utils/api-request.ts). It treats a request as an API request when either the raw URL or the matched route pattern (request.routeOptions.url) starts with/api/. The rate-limit hook, the APIno-storeonSendhook inapp.tsandcompressJsonHookuse it instead of their raw-URL checks.New regression
scripts/regressions/encoded-api-path-security.regression.ts, which runs inpnpm regression:security. It covers:Cache-Control: no-storeand compressed JSON.It fails on current
stagingand passes with this change.Validation
pnpm checkpasses locallyCONTRIBUTING.mdCommands the agent ran locally (please re-verify):
pnpm check: exit 0. The only lint warning is an existingreact-hooks/exhaustive-depswarning inHomeProfessorMariChat.tsx, unrelated to this change.pnpm regression:security: 20/20 passed, including the new regression.encoded-api-path-securityregression: fails against thestagingversions of the changed files and passes with the fix.compress-json,route-rate-limits,issue-sweep-sep5,static-cache-headers,capability-package-cache,experience-state,experience-generation,update-channel-metadata.app.injectscript against the realbuildApp()with a temporary data folder showed:Cache-Control: no-storeand rate-limit headers.GET /still serves the client.Manual verification notes
http://127.0.0.1:7860: import a character card, upload a background or gallery image, save settings and run a backup.CSRF_TRUSTED_ORIGINScan still save and upload.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)No user-facing docs change: the documented CSRF behaviour already describes unsafe API routes, and that is unchanged.
UI evidence (if applicable)
Not applicable (server-only change).
Summary by CodeRabbit
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.