mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #387] [MERGED] Harden security defaults and privileged flows #4600
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#4600
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/387
Author: @TheLonelyDevil9
Created: 5/4/2026
Status: ✅ Merged
Merged: 5/4/2026
Merged by: @SpicyMarinara
Base:
main← Head:codex/security-hardening-v1.5.7📝 Commits (4)
f35f8a4Harden security defaults and privileged flows389b756Address security review feedbackd3c9430Address CodeRabbit security reviewe122951Address CodeRabbit hardening follow-ups📊 Changes
72 files changed (+2793 additions, -1119 deletions)
View changed files
📝
.env.example(+25 -6)📝
.github/workflows/build-apk.yml(+5 -5)📝
.github/workflows/build-container-lite.yml(+12 -12)📝
.github/workflows/build-container.yml(+12 -12)📝
.github/workflows/publish-github-release.yml(+4 -4)📝
.github/workflows/pull-request-checks.yml(+6 -6)📝
.github/workflows/pull-request-triage.yml(+2 -2)📝
CHANGELOG.md(+12 -0)📝
Dockerfile(+4 -1)📝
Dockerfile.lite(+4 -1)📝
README.md(+2 -0)📝
android/README.md(+1 -0)📝
android/app/src/main/AndroidManifest.xml(+2 -1)📝
android/app/src/main/java/com/marinara/engine/MainActivity.java(+5 -2)📝
docker-compose.yml(+2 -1)📝
docs/CONFIGURATION.md(+39 -10)📝
docs/FAQ.md(+10 -3)📝
docs/TROUBLESHOOTING.md(+5 -0)📝
docs/installation/containers.md(+7 -5)📝
package.json(+5 -2)...and 52 more files
📄 Description
Linked issue
No linked issue is attached yet. Per
CONTRIBUTING.md § Before You Open a Pull Request, please open or link a security hardening issue before this PR is submitted for final review/merge.Why this change
This PR implements the security remediation plan saved at
D:\AIStuff\Marinara-Engine-security-remediation-plan.mdfor thev1.5.7codebase.The primary security problem is that Marinara exposes powerful local-server capabilities: model/provider calls, custom tools, backups, imports, sidecar runtime management, update application, haptics, profile export, image/audio fetching, and static file handling. Several of those capabilities are acceptable for a trusted loopback desktop app but become dangerous when reachable from a LAN, Docker bridge, Tailscale-like network, misconfigured public bind, malicious browser origin, or attacker-controlled URL/file payload.
The remediation goal is to keep local convenience for loopback users while making non-loopback and privileged behavior fail closed by default. Risky features remain available, but only with explicit configuration, auth, CSRF/origin checks, admin confirmation, path containment, and SSRF controls appropriate to the feature.
Security posture changed by this PR
Default behavior now intentionally favors safety over old convenience:
ADMIN_SECRETinstead of silently failing open when unset.This is expected to be a compatibility-impacting hardening change for users who intentionally expose Marinara on LAN/Tailscale/Docker/public interfaces without auth. The docs now describe the explicit escape hatches and warnings.
Threat model addressed
This PR is intended to reduce risk from:
What changed
Security foundations:
Access control and browser request protection:
IP_ALLOWLIST,ALLOW_UNAUTHENTICATED_PRIVATE_NETWORK, orALLOW_UNAUTHENTICATED_REMOTEis intentionally configured.ADMIN_SECRETand reject unset or wrong secrets with explicit403responses.Privileged feature gates:
IMPORT_ALLOWED_ROOTS.SSRF and network hardening:
Filesystem and upload hardening:
assertInsideDircontainment checks to avoid sibling-prefix bypasses and drive/separator confusion.Secrets and data protection:
Client/XSS hardening:
dompurify.Supply-chain and platform hardening:
127.0.0.1:${PORT:-7860}:7860.npx --yesstyle execution and pinned repo install/update behavior tov1.5.7commit159f5a2017ae958b737a7b618f5cd1a283603073.CHANGELOG.mdso the security defaults are visible in release publication.Compatibility and migration notes
Expected user-visible changes:
IP_ALLOWLIST, or an explicit unsafe opt-in.ADMIN_SECRET; destructive/admin operations will fail with403until configured.UPDATES_APPLY_ENABLED=falsebehavior.Docs updated:
.env.exampleREADME.mddocs/CONFIGURATION.mddocs/FAQ.mddocs/TROUBLESHOOTING.mddocs/installation/containers.mdandroid/README.mdCHANGELOG.mdCodeRabbit follow-up in
d3c9430The latest review pass addresses the CodeRabbit comments that remained after the first hardening commit:
>=20.19 || >=22.12for Vite 7 compatibility.Request/initsemantics and does not force multipartContent-Typeheaders forFormDatauploads.api.rawrouting for sidecar downloads and kept admin/CSRF handling on that path, including surfaced status/body errors.Hostself-whitelisting from CSRF origin checks and added explicit configured-origin coverage.script-src 'unsafe-inline'from CSP while retaining inline styles for compatibility.api_key/api-key, arrays, nested settings, and malformed legacy string settings.assertInsideDirfor import root checks, including Windows cross-drive containment.IMPORT_ALLOWED_ROOTSwhen roots are configured, while preserving picker behavior when no roots are configured./historyand/viewtimeout coverage.WEBHOOK_LOCAL_URLS_ENABLED=trueexplicitly opts into local HTTP support.avif/avisftyp brands.safeFetchcontent-type gate is configured and the response omitsContent-Type.Validation
These checkboxes are intentionally left unchecked for human contributors, per repo policy. Treat them as the manual verification checklist before final submission.
pnpm checkpasses locallyCONTRIBUTING.mdCommands and checks run by Codex during implementation/testing:
pnpm --filter @marinara-engine/server lintpnpm --filter @marinara-engine/client lintpnpm --filter @marinara-engine/client buildpnpm --filter @marinara-engine/server exec tsx --test test/security-utils.test.ts test/security-middleware.test.tspnpm --filter @marinara-engine/server exec tsx --test test/security-utils.test.ts test/security-middleware.test.ts test/file-backed-store.test.tspnpm --filter @marinara-engine/server exec tsx --test test/file-backed-store.test.tspnpm --filter @marinara-engine/server testpnpm checkpnpm testpnpm version:checkpnpm guard:installer-artifactspnpm audit --prod --jsonpnpm release:notes -- 1.5.7node ./scripts/check-windows-installer-layout.mjsgit diff --checkC:\\Program Files (x86)\\NSIS\\makensis.exe installer.nsifromwin/installernodeimporting./packages/server/dist/app.js, creating a production-mode app with tempDATA_DIR, and asserting:GET /api/healthreturns200with version1.5.7GET /returns200POST /api/admin/clear-allwith wrongX-Admin-Secretreturns403Observed validation results:
125/125tests.0advisories (pnpm audit --prod --json).1.5.7.v3.12fromwin/installerand the generated installer artifact was removed after validation.uses:references are SHA-pinned.console.*usage in server source except the logger guidance comment.ANTHROPIC_API_KEYenv override name in the Claude subscription provider code.Additional stability testing recommended before merge/release
Automated/local checks still worth running in CI or on a reviewer machine:
docker build -t marinara-engine:security .docker build -f Dockerfile.lite -t marinara-engine-lite:security .DATA_DIR:IP_ALLOWLISTsucceeds only for intended addresses.ALLOW_UNAUTHENTICATED_PRIVATE_NETWORKrestores old behavior only when explicitly configured.Origin/Sec-Fetch-SitePOST fails.CSRF_TRUSTED_ORIGINSsucceeds only when intended.ADMIN_SECRETfails.ADMIN_SECRETfails.ADMIN_SECRETplus CSRF succeeds for intended privileged operation.127.0.0.1,localhost,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,169.254.169.254, IPv6 loopback/ULA, malformed protocols, and redirect-to-private...traversal in uploaded filenames, zip entries, avatar/background import, and static asset reads.Manual verification notes
Codex did not perform real browser, Docker, Android device/emulator, or live external-provider manual verification in this environment.
Manual review should focus on:
fetchcall is intentionally fixed-host/public-only or should be migrated tosafeFetchin a follow-up.Known residual risk and follow-ups
fetchcalls because they target hard-coded public services rather than arbitrary user-provided URLs. Reviewers should confirm each remaining raw fetch is intentionally fixed-host or add another follow-up to migrate more of them tosafeFetch.https://astral.sh/uv/install.shflow, but runtime install is disabled/gated by default. A future PR should pin and verify that installer or replace it with a checksumed packaged dependency.v1.5.7is not GPG-signed. Windows installer/update hardening pins the expected commit rather than claiming signed-tag verification.Docs and release impact
Docs and release notes were updated by this PR because auth defaults, privileged APIs, Docker binding, Android behavior, installer verification, and dependency posture changed. The version remains
1.5.7; no version bump is included in this PR.UI evidence (if applicable)
No screenshots are attached. UI changes are limited to security/admin-secret and bulk-import controls rather than a visual redesign. A reviewer should still manually verify the settings and bulk import flows in-browser before merge.
Summary by CodeRabbit
New Features
Documentation
Other
Chores
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.