[PR #5720] [MERGED] fix(updates): harden update-apply against dev instances and PowerShell (#5645, #5646) #6899

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

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5720
Author: @kolacheee
Created: 9/1/2026
Status: ✅ Merged
Merged: 9/1/2026
Merged by: @kolacheee

Base: staging ← Head: fix/5645-5646-update-apply-hardening


📝 Commits (2)

  • d3518ea fix(updates): harden update-apply against dev instances and PowerShell (#5645, #5646)
  • 2456748 fix(updates): close the review gaps in the update-apply hardening

📊 Changes

10 files changed (+293 additions, -14 deletions)

View changed files

📝 .env.example (+4 -0)
📝 CHANGELOG.md (+2 -0)
📝 docs/CONFIGURATION.md (+1 -0)
📝 e2e/start-servers.mjs (+3 -0)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+14 -4)
📝 packages/server/src/config/runtime-config.ts (+16 -0)
📝 packages/server/src/routes/updates.routes.ts (+80 -9)
📝 packages/server/src/services/updates/update-apply-policy.ts (+16 -1)
📝 scripts/dev.mjs (+7 -0)
➕ scripts/regressions/update-apply-hardening.regression.ts (+150 -0)

📄 Description

Linked issue

Closes #5645, closes #5646.

Why this change

Two failure modes on the update-apply surface, both hit by real people this week. #5646: the loopback channel-switch bypass is right for real installs, but dev and e2e servers boot from the developer's working repo — so one click of the channel selector in any local tab could stash uncommitted work, move HEAD to staging, and force-rebuild the checkout underneath running Playwright sessions (this actually happened, wedging two e2e boots and silently switching the branch mid-development). #5645: the manual-update fallback those refusals point at was one long &&/|| chain — Windows PowerShell 5.1, the default shell for exactly the testers the staging channel targets, rejects it with parser errors and runs nothing; the command also assumed the terminal was already sitting in the repo checkout, which many users can't find.

What changed

#5646 — two independent guards, both refusing before the ordinary gate:

  • UPDATES_APPLY_DISABLED — a hard refusal checked ahead of UPDATES_APPLY_ENABLED and the loopback channel-switch bypass. scripts/dev.mjs sets it (covering pnpm dev and, transitively, the e2e servers, which spawn dev.mjs), and e2e/start-servers.mjs sets it belt-and-braces. Documented in docs/CONFIGURATION.md and .env.example.
  • A development-branch guard in the apply route: a checkout on anything other than main/master/staging refuses to apply, protecting contributors who boot the server by other means. Detached checkouts stay allowed — the stable launcher pins them deliberately, and git branch --show-current yields empty → null there, verified.
  • Both surface as distinct applyUnavailableReason values (hard-disabled, dev-branch) with honest Settings-panel copy — no more "enable it with UPDATES_APPLY_ENABLED=true" advice for an instance that must never apply — and the check route previews the branch refusal so the panel never offers an Apply that would 403.

#5645 — the manual command is now a complete recipe:

  • It leads with cd into the server-detected repo root (cd /d "…" on Windows so it crosses drive letters; cd "…" elsewhere) — the server runs from the checkout, so it always knows the path the user may not.
  • The hint names shells that can actually run it ("Command Prompt (cmd) or Git Bash — the default Windows PowerShell rejects && chains") on Windows, for both the staging apply command and the stable launcher command.

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

  • pnpm lint and the production build are green locally; format:check fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly).
  • New regression scripts/regressions/update-apply-hardening.regression.ts passes: the policy matrix (hard-disable beats the enabled flag and the channel-switch bypass; both legacy paths preserved), branch classification (incl. detached-null staying allowed), the cd-prefixed recipe on Windows and POSIX, the shell hint, and source pins on the launcher envs, the refuse-before-gate ordering, and the client copy.
  • Safety self-checks verified against the code: getCurrentBranch returns null on detached HEAD (git branch --show-current prints empty), so stable pinned installs are unaffected; the early 403 returns sit inside the route's try, so the updateApplyInProgress flag is released by the existing finally.
  • A two-lens adversarial review confirmed six findings on the first cut, all fixed in the second commit — most notably that the staging recipe's unparenthesized || let a failed leading cd fall through into git checkout -b + install + build executed in whatever directory the user was standing in (pre-existing in shape; the new cd prefix made it urgent), and that the .env hot-reloader could lift the launcher-set hard-disable after boot (now latched at boot). Residual exposure recorded, not fixed, by design: a server booted directly (pnpm --filter server dev, node dist) from a checkout sitting on main/staging is indistinguishable from a legitimate tester install — the env flag covers the launchers and the branch guard covers named feature branches.
  • Please verify manually: run pnpm dev from a feature branch with uncommitted changes, open the app at localhost, and switch the update channel — it should refuse with the dev-instance message and git status/git stash list should be untouched (the issue's own repro).

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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)

CHANGELOG updated under [Unreleased] → Fixed; docs/CONFIGURATION.md gained the UPDATES_APPLY_DISABLED row — it rides the pending batched [docs-i18n] catch-up together with #5604 (planned as the closing PR of this issue arc).

UI evidence (if applicable)

The two new refusal messages in Settings → Advanced → Updates are the visible change.

Summary by CodeRabbit

  • Bug Fixes

    • Prevented development and end-to-end servers from applying updates to local development checkouts.
    • Added safeguards for development branches and loopback update requests.
    • Improved update availability messages with specific guidance for blocked environments.
    • Updated manual update instructions with complete Windows and POSIX commands.
  • Documentation

    • Documented the hard-disable configuration option and its precedence over other update settings.

🔄 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/5720 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/1/2026 **Status:** ✅ Merged **Merged:** 9/1/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5645-5646-update-apply-hardening` --- ### 📝 Commits (2) - [`d3518ea`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d3518ea83aa35d61840e839aa76c5382ad233637) fix(updates): harden update-apply against dev instances and PowerShell (#5645, #5646) - [`2456748`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2456748258439be0bc5cf482bce724e4d317fee6) fix(updates): close the review gaps in the update-apply hardening ### 📊 Changes **10 files changed** (+293 additions, -14 deletions) <details> <summary>View changed files</summary> 📝 `.env.example` (+4 -0) 📝 `CHANGELOG.md` (+2 -0) 📝 `docs/CONFIGURATION.md` (+1 -0) 📝 `e2e/start-servers.mjs` (+3 -0) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+14 -4) 📝 `packages/server/src/config/runtime-config.ts` (+16 -0) 📝 `packages/server/src/routes/updates.routes.ts` (+80 -9) 📝 `packages/server/src/services/updates/update-apply-policy.ts` (+16 -1) 📝 `scripts/dev.mjs` (+7 -0) ➕ `scripts/regressions/update-apply-hardening.regression.ts` (+150 -0) </details> ### 📄 Description ## Linked issue Closes #5645, closes #5646. ## Why this change Two failure modes on the update-apply surface, both hit by real people this week. **#5646:** the loopback channel-switch bypass is right for real installs, but dev and e2e servers boot from the developer's *working repo* — so one click of the channel selector in any local tab could stash uncommitted work, move HEAD to `staging`, and force-rebuild the checkout underneath running Playwright sessions (this actually happened, wedging two e2e boots and silently switching the branch mid-development). **#5645:** the manual-update fallback those refusals point at was one long `&&`/`||` chain — Windows PowerShell 5.1, the default shell for exactly the testers the staging channel targets, rejects it with parser errors and runs nothing; the command also assumed the terminal was already sitting in the repo checkout, which many users can't find. ## What changed **#5646 — two independent guards, both refusing *before* the ordinary gate:** - `UPDATES_APPLY_DISABLED` — a hard refusal checked ahead of `UPDATES_APPLY_ENABLED` *and* the loopback channel-switch bypass. `scripts/dev.mjs` sets it (covering `pnpm dev` and, transitively, the e2e servers, which spawn `dev.mjs`), and `e2e/start-servers.mjs` sets it belt-and-braces. Documented in `docs/CONFIGURATION.md` and `.env.example`. - A development-branch guard in the apply route: a checkout on anything other than `main`/`master`/`staging` refuses to apply, protecting contributors who boot the server by other means. Detached checkouts stay allowed — the stable launcher pins them deliberately, and `git branch --show-current` yields empty → `null` there, verified. - Both surface as distinct `applyUnavailableReason` values (`hard-disabled`, `dev-branch`) with honest Settings-panel copy — no more "enable it with `UPDATES_APPLY_ENABLED=true`" advice for an instance that must never apply — and the check route previews the branch refusal so the panel never offers an Apply that would 403. **#5645 — the manual command is now a complete recipe:** - It leads with `cd` into the server-detected repo root (`cd /d "…"` on Windows so it crosses drive letters; `cd "…"` elsewhere) — the server runs from the checkout, so it always knows the path the user may not. - The hint names shells that can actually run it ("Command Prompt (cmd) or Git Bash — the default Windows PowerShell rejects `&&` chains") on Windows, for both the staging apply command and the stable launcher command. ## 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 - `pnpm lint` and the production build are green locally; `format:check` fails repo-wide on this Windows checkout (pre-existing autocrlf CRLF; touched files were run through Prettier directly). - New regression `scripts/regressions/update-apply-hardening.regression.ts` passes: the policy matrix (hard-disable beats the enabled flag *and* the channel-switch bypass; both legacy paths preserved), branch classification (incl. detached-`null` staying allowed), the `cd`-prefixed recipe on Windows and POSIX, the shell hint, and source pins on the launcher envs, the refuse-before-gate ordering, and the client copy. - Safety self-checks verified against the code: `getCurrentBranch` returns `null` on detached HEAD (`git branch --show-current` prints empty), so stable pinned installs are unaffected; the early 403 returns sit inside the route's `try`, so the `updateApplyInProgress` flag is released by the existing `finally`. - A two-lens adversarial review confirmed six findings on the first cut, all fixed in the second commit — most notably that the staging recipe's unparenthesized `||` let a failed leading `cd` fall through into `git checkout -b` + install + build executed in whatever directory the user was standing in (pre-existing in shape; the new `cd` prefix made it urgent), and that the `.env` hot-reloader could lift the launcher-set hard-disable after boot (now latched at boot). Residual exposure recorded, not fixed, by design: a server booted directly (`pnpm --filter server dev`, `node dist`) from a checkout sitting on `main`/`staging` is indistinguishable from a legitimate tester install — the env flag covers the launchers and the branch guard covers named feature branches. - **Please verify manually:** run `pnpm dev` from a feature branch with uncommitted changes, open the app at localhost, and switch the update channel — it should refuse with the dev-instance message and `git status`/`git stash list` should be untouched (the issue's own repro). ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) 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) CHANGELOG updated under **[Unreleased] → Fixed**; `docs/CONFIGURATION.md` gained the `UPDATES_APPLY_DISABLED` row — it rides the pending batched `[docs-i18n]` catch-up together with #5604 (planned as the closing PR of this issue arc). ## UI evidence (if applicable) The two new refusal messages in Settings → Advanced → Updates are the visible change. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Prevented development and end-to-end servers from applying updates to local development checkouts. * Added safeguards for development branches and loopback update requests. * Improved update availability messages with specific guidance for blocked environments. * Updated manual update instructions with complete Windows and POSIX commands. * **Documentation** * Documented the hard-disable configuration option and its precedence over other update settings. <!-- 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:14:43 +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#6899
No description provided.