[PR #3967] [MERGED] Block DNS rebinding and require Agent update consent #6177

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/3967
Author: @SpicyMarinara
Created: 7/23/2026
Status: ✅ Merged
Merged: 7/23/2026
Merged by: @SpicyMarinara

Base: staging ← Head: security/dns-rebinding-agent-update-consent


📝 Commits (2)

  • 5844af0 Harden request hosts and require Agent update consent
  • 6072097 Apply CodeRabbit review fixes for host and consent hardening

📊 Changes

25 files changed (+827 additions, -82 deletions)

View changed files

📝 .env.example (+4 -0)
📝 CHANGELOG.md (+6 -0)
📝 README.md (+1 -1)
📝 docs/CONFIGURATION.md (+5 -2)
📝 docs/FAQ.md (+1 -1)
📝 docs/REMOTE_ACCESS.md (+8 -0)
📝 docs/TROUBLESHOOTING.md (+3 -2)
📝 e2e/core-flows.e2e.ts (+133 -0)
📝 package.json (+2 -1)
📝 packages/client/src/App.tsx (+16 -1)
📝 packages/client/src/components/agents/AgentCatalogView.tsx (+3 -2)
➕ packages/client/src/components/agents/AgentUpdatePrompter.tsx (+61 -0)
📝 packages/client/src/components/modals/WhatsNewModal.tsx (+21 -7)
📝 packages/client/src/hooks/use-capability-packages.ts (+30 -1)
📝 packages/server/src/app.ts (+8 -29)
📝 packages/server/src/config/cors-config.ts (+2 -1)
📝 packages/server/src/config/runtime-config.ts (+4 -0)
➕ packages/server/src/middleware/host-validation.ts (+148 -0)
📝 packages/server/src/middleware/privileged-gate.ts (+9 -0)
📝 packages/server/src/routes/capability-packages.routes.ts (+43 -13)

...and 5 more files

📄 Description

Linked issue

None. This is maintainer-requested security hardening; a public issue was intentionally not opened before the fixes were ready for review.

Why this change

Two trust boundaries needed correction:

  • Safe-method API reads were reachable through an attacker-controlled DNS name rebound to loopback. Because the browser then considered the attacker origin same-origin with that Host, CORS and loopback privilege assumptions could expose chats, galleries, backups, and other private reads.
  • Installed downloadable Agent packages were upgraded from a mutable catalog automatically during server startup, allowing new executable package code to run without per-version user consent.

The hardcoded X-Marinara-CSRF: 1 value is deliberately retained as a public presence marker. A randomized browser-bundled value would not be a secret and would not stop DNS rebinding.

What changed

  • Validate the HTTP Host before CORS, authentication bypasses, privileged gates, or API routes run.
  • Continue accepting direct IPv4/IPv6, LAN, Tailscale, localhost, .local, .home.arpa, and single-label local hostnames.
  • Add hot-reloadable TRUSTED_HOSTS support for intentional public and reverse-proxy hostnames, while accepting existing trusted Origin configuration for compatibility.
  • Remove silent startup replacement of installed Agent packages.
  • Discover compatible updates through a read-only endpoint and show the existing responsive confirmation UI for each new Agent version.
  • Persist No for the exact offered version without changing the installed package; a later version may prompt again.
  • Preserve the existing manual Update action in Agents → Download Agents.
  • Restrict official catalog packages to canonical Marinara-Agents artifact URLs while preserving explicit custom-catalog overrides.
  • Add focused request-boundary, package-lifecycle, and desktop/mobile UI regressions, plus aligned configuration and user documentation.

Security and compatibility impact

  • DNS rebinding requests receive HTTP 421 before protected data can be read or reflected through CORS.
  • Connecting from another device by LAN/Tailscale/IP address continues to work without TRUSTED_HOSTS changes.
  • Public and reverse-proxy FQDN deployments may set TRUSTED_HOSTS=chat.example.com; existing matching CSRF_TRUSTED_ORIGINS and CORS_ORIGINS entries remain compatible.
  • Installed packages remain usable offline and are no longer replaced at process startup.
  • Applying an Agent update remains a privileged action and retains existing restart/readiness handling.

Automated validation evidence

  • pnpm check
  • pnpm version:check
  • pnpm regression:request-security
  • capability package lifecycle and readiness regression
  • focused Playwright consent flow on desktop and Pixel-sized mobile
  • git diff --check

The broad UI smoke run completed 81 tests with 52 intentional viewport skips and one unrelated Tracker reload flake. That Tracker test and the new Agent consent test both passed on an isolated rerun. The existing unrelated HomeProfessorMariChat.tsx lint warning remains unchanged.

Human test plan

  • Manually connect to Marinara from another physical LAN device using the host machine's IPv4 address.
  • Manually verify a configured public/reverse-proxy hostname works with TRUSTED_HOSTS.
  • Manually reproduce a rebound-style Host request against /api/chats and /api/backup/export-profile and confirm HTTP 421.
  • Manually accept a real official Agent update and verify activation or restart-required behavior.
  • Manually decline an Agent update, restart/reopen the client, and verify the same version does not prompt again.
  • Manually verify the declined Agent still shows Update in Download Agents on desktop and mobile.

Summary by CodeRabbit

  • New Features
    • Agent package updates now prompt for confirmation. Choosing No keeps the update available for later.
    • Added TRUSTED_HOSTS support for public and reverse-proxy hostnames.
  • Security
    • Untrusted hostnames are rejected to help prevent DNS rebinding and unauthorized access.
    • Official catalog artifacts are restricted to approved sources, while custom catalogs remain supported.
  • Bug Fixes
    • Improved update messaging, offline behavior, rollback handling, and reverse-proxy access guidance.
  • Documentation
    • Updated configuration, remote access, troubleshooting, FAQ, README, and changelog guidance.

🔄 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/3967 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 7/23/2026 **Status:** ✅ Merged **Merged:** 7/23/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `security/dns-rebinding-agent-update-consent` --- ### 📝 Commits (2) - [`5844af0`](https://github.com/Pasta-Devs/Marinara-Engine/commit/5844af0e8cac73c4ead32f2ea1d0d3d8ca3f39f9) Harden request hosts and require Agent update consent - [`6072097`](https://github.com/Pasta-Devs/Marinara-Engine/commit/60720972840a0b34f086eef0327946de892b650c) Apply CodeRabbit review fixes for host and consent hardening ### 📊 Changes **25 files changed** (+827 additions, -82 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+4 -0) 📝 `CHANGELOG.md` (+6 -0) 📝 `README.md` (+1 -1) 📝 `docs/CONFIGURATION.md` (+5 -2) 📝 `docs/FAQ.md` (+1 -1) 📝 `docs/REMOTE_ACCESS.md` (+8 -0) 📝 `docs/TROUBLESHOOTING.md` (+3 -2) 📝 `e2e/core-flows.e2e.ts` (+133 -0) 📝 `package.json` (+2 -1) 📝 `packages/client/src/App.tsx` (+16 -1) 📝 `packages/client/src/components/agents/AgentCatalogView.tsx` (+3 -2) ➕ `packages/client/src/components/agents/AgentUpdatePrompter.tsx` (+61 -0) 📝 `packages/client/src/components/modals/WhatsNewModal.tsx` (+21 -7) 📝 `packages/client/src/hooks/use-capability-packages.ts` (+30 -1) 📝 `packages/server/src/app.ts` (+8 -29) 📝 `packages/server/src/config/cors-config.ts` (+2 -1) 📝 `packages/server/src/config/runtime-config.ts` (+4 -0) ➕ `packages/server/src/middleware/host-validation.ts` (+148 -0) 📝 `packages/server/src/middleware/privileged-gate.ts` (+9 -0) 📝 `packages/server/src/routes/capability-packages.routes.ts` (+43 -13) _...and 5 more files_ </details> ### 📄 Description ## Linked issue None. This is maintainer-requested security hardening; a public issue was intentionally not opened before the fixes were ready for review. ## Why this change Two trust boundaries needed correction: - Safe-method API reads were reachable through an attacker-controlled DNS name rebound to loopback. Because the browser then considered the attacker origin same-origin with that Host, CORS and loopback privilege assumptions could expose chats, galleries, backups, and other private reads. - Installed downloadable Agent packages were upgraded from a mutable catalog automatically during server startup, allowing new executable package code to run without per-version user consent. The hardcoded `X-Marinara-CSRF: 1` value is deliberately retained as a public presence marker. A randomized browser-bundled value would not be a secret and would not stop DNS rebinding. ## What changed - Validate the HTTP Host before CORS, authentication bypasses, privileged gates, or API routes run. - Continue accepting direct IPv4/IPv6, LAN, Tailscale, localhost, `.local`, `.home.arpa`, and single-label local hostnames. - Add hot-reloadable `TRUSTED_HOSTS` support for intentional public and reverse-proxy hostnames, while accepting existing trusted Origin configuration for compatibility. - Remove silent startup replacement of installed Agent packages. - Discover compatible updates through a read-only endpoint and show the existing responsive confirmation UI for each new Agent version. - Persist **No** for the exact offered version without changing the installed package; a later version may prompt again. - Preserve the existing manual **Update** action in **Agents → Download Agents**. - Restrict official catalog packages to canonical Marinara-Agents artifact URLs while preserving explicit custom-catalog overrides. - Add focused request-boundary, package-lifecycle, and desktop/mobile UI regressions, plus aligned configuration and user documentation. ## Security and compatibility impact - DNS rebinding requests receive HTTP 421 before protected data can be read or reflected through CORS. - Connecting from another device by LAN/Tailscale/IP address continues to work without `TRUSTED_HOSTS` changes. - Public and reverse-proxy FQDN deployments may set `TRUSTED_HOSTS=chat.example.com`; existing matching `CSRF_TRUSTED_ORIGINS` and `CORS_ORIGINS` entries remain compatible. - Installed packages remain usable offline and are no longer replaced at process startup. - Applying an Agent update remains a privileged action and retains existing restart/readiness handling. ## Automated validation evidence - `pnpm check` - `pnpm version:check` - `pnpm regression:request-security` - capability package lifecycle and readiness regression - focused Playwright consent flow on desktop and Pixel-sized mobile - `git diff --check` The broad UI smoke run completed 81 tests with 52 intentional viewport skips and one unrelated Tracker reload flake. That Tracker test and the new Agent consent test both passed on an isolated rerun. The existing unrelated `HomeProfessorMariChat.tsx` lint warning remains unchanged. ## Human test plan - [ ] Manually connect to Marinara from another physical LAN device using the host machine's IPv4 address. - [ ] Manually verify a configured public/reverse-proxy hostname works with `TRUSTED_HOSTS`. - [ ] Manually reproduce a rebound-style Host request against `/api/chats` and `/api/backup/export-profile` and confirm HTTP 421. - [ ] Manually accept a real official Agent update and verify activation or restart-required behavior. - [ ] Manually decline an Agent update, restart/reopen the client, and verify the same version does not prompt again. - [ ] Manually verify the declined Agent still shows **Update** in Download Agents on desktop and mobile. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Agent package updates now prompt for confirmation. Choosing **No** keeps the update available for later. * Added `TRUSTED_HOSTS` support for public and reverse-proxy hostnames. * **Security** * Untrusted hostnames are rejected to help prevent DNS rebinding and unauthorized access. * Official catalog artifacts are restricted to approved sources, while custom catalogs remain supported. * **Bug Fixes** * Improved update messaging, offline behavior, rollback handling, and reverse-proxy access guidance. * **Documentation** * Updated configuration, remote access, troubleshooting, FAQ, README, and changelog guidance. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-23 04:07:50 +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#6177
No description provided.