[PR #5894] [MERGED] fix(mari): read-only package stores and group-scoped sandbox teardown #6985

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

📋 Pull Request Information

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

Base: staging ← Head: fix/5892-store-robind-groupkill


📝 Commits (7)

  • fe8b8ff fix(mari): read-only package stores and group-scoped teardown (#5892)
  • 0c1a208 fix(mari): idempotent teardown and symlinked-store binds (CodeRabbit)
  • d03f894 fix(mari): cache carve-outs follow the logical store name (CodeRabbit)
  • 29b82e3 fix(mari): symlink-proof cache carve-outs and canonical store exemption (CodeRabbit)
  • 578b6cb fix(mari): contain store discovery failures to the scan side (CI)
  • dce58a7 fix(mari): post-run store-link integrity and a live group-teardown case (CodeRabbit)
  • 1c74c33 fix(mari): canonical workspace root and unguessable quarantine names (CodeRabbit)

📊 Changes

4 files changed (+705 additions, -26 deletions)

View changed files

📝 CHANGELOG.md (+2 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+26 -6)
📝 packages/server/src/services/professor-mari/workspace-shell-sandbox.ts (+283 -14)
📝 scripts/regressions/mari-guard-sibling-paths.regression.ts (+394 -6)

📄 Description

Linked issue

Closes #5892

Why this change

#5892 tracked the two residuals consciously left open by the #5786 post-execution scan (PR #5891): package-store trees stayed outside the scan for cost — so a command could plant ready-made node_modules/<pkg>/ code that executes on the server's next require — and on macOS a process surviving seatbelt teardown could write after the scan walked.

What changed

Residual 1 closes at the mount layer, not the scan. Package-store trees (node_modules, .pnpm, .pnpm-store — nested included, enumerated by the existing policy walk at zero extra I/O since it already sees each store while skipping into it) are now read-only inside the sandbox on both backends. The justification is structural: sandboxed bash has no legitimate install path (package-manager mutations are refused pre-execution; approved dependency installs run outside the sandbox). Build-tool caches stay writable via carve-outs (.cache, .vite, and .vite-temp — the review probed this repo's actual vite@7 and found TS-config builds bundle there before anything else runs), pre-created when absent so a first build isn't broken by its own missing cache dir. The workspace root is canonicalized before any rules derive — the review traced a Linux fail-open where a symlinked workspace path put the writable bind and the realpath'd read-only binds on different mount points.

Residual 2 narrows to the theoretical. Both backend spawns are detached: true and teardown signals the process group (SIGTERM, then SIGKILL escalation, timer cleared on settle so a stale group-kill can never hit a recycled pid). Backgrounded grandchildren die with the tree; what remains — setsid escapees, and trees orphaned by a hard server crash on macOS — is documented at the helper.

Plus a regression the verification round caught in #5786's own revision: the descent into run-created skip-named stores had been silently lost, leaving a fresh node_modules invisible to the scan and unbound. Restored, with a lane case pinning it.

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

  • The mari-guard-sibling-paths lane asserts both backends' generated rules functionally: bwrap args ro-bind all stores (nested included) with the cache --bind stacking after its parent's ro-bind; the seatbelt profile places the cache allow after the store deny (last-match-wins), order-agnostically. A real detached leader is spawned and group-killed on POSIX; the ESRCH fallback is platform-gated honestly; the run-created-store descent and pre-existing-store skip are both pinned.
  • The verification review (two agents, this repo's real Vite probed) produced 9 findings; all are folded in or documented: .vite-temp carve-out, workspace canonicalization, the lost-descent regression, the escalation-timer clear, macOS-crash-orphan and symlink-store residuals documented at the helper, lane realpath wrap and honest test gating.
  • All Mari lanes pass; server lint clean; zero-error build. Not exercised against live bwrap/seatbelt — rule generation is covered functionally; the mount/precedence semantics are cited platform behavior.

Docs and release impact

  • No docs changes needed (CHANGELOG entry included)
  • 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)

UI evidence (if applicable)

Not applicable — sandbox policy and process teardown only.

Summary by CodeRabbit

  • Bug Fixes
    • Installed-package stores, including nested and pnpm directories, are now read-only in the sandbox.
    • Build-tool cache folders remain writable for supported workflows.
    • Stopping a sandboxed command now terminates background processes as well.
    • Improved protection for workspace paths and package-store symbolic links.
    • Newly created package stores are fully checked after sandboxed execution.
    • Sandbox teardown is more reliable across supported platforms, including process cleanup and link restoration.

🔄 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/5894 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/6/2026 **Status:** ✅ Merged **Merged:** 9/6/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5892-store-robind-groupkill` --- ### 📝 Commits (7) - [`fe8b8ff`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fe8b8ffa38c03f8727d203db09d538dff97a138f) fix(mari): read-only package stores and group-scoped teardown (#5892) - [`0c1a208`](https://github.com/Pasta-Devs/Marinara-Engine/commit/0c1a2089099f74983a49a4764a619cc722f396f7) fix(mari): idempotent teardown and symlinked-store binds (CodeRabbit) - [`d03f894`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d03f894724ba8d8d693248883b3dfbef011a0583) fix(mari): cache carve-outs follow the logical store name (CodeRabbit) - [`29b82e3`](https://github.com/Pasta-Devs/Marinara-Engine/commit/29b82e3227407c8ebfd91efc33927637f85d6624) fix(mari): symlink-proof cache carve-outs and canonical store exemption (CodeRabbit) - [`578b6cb`](https://github.com/Pasta-Devs/Marinara-Engine/commit/578b6cbac0552675f1bf4c6ac882f9bb974823db) fix(mari): contain store discovery failures to the scan side (CI) - [`dce58a7`](https://github.com/Pasta-Devs/Marinara-Engine/commit/dce58a7d6050b1b10ab4636a18a812d87b6f7cc4) fix(mari): post-run store-link integrity and a live group-teardown case (CodeRabbit) - [`1c74c33`](https://github.com/Pasta-Devs/Marinara-Engine/commit/1c74c330390a2cb7bd98ed83fe893c35504ede7c) fix(mari): canonical workspace root and unguessable quarantine names (CodeRabbit) ### 📊 Changes **4 files changed** (+705 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+2 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+26 -6) 📝 `packages/server/src/services/professor-mari/workspace-shell-sandbox.ts` (+283 -14) 📝 `scripts/regressions/mari-guard-sibling-paths.regression.ts` (+394 -6) </details> ### 📄 Description ## Linked issue Closes #5892 ## Why this change #5892 tracked the two residuals consciously left open by the #5786 post-execution scan (PR #5891): package-store trees stayed outside the scan for cost — so a command could plant ready-made `node_modules/<pkg>/` code that executes on the server's next `require` — and on macOS a process surviving seatbelt teardown could write *after* the scan walked. ## What changed **Residual 1 closes at the mount layer, not the scan.** Package-store trees (`node_modules`, `.pnpm`, `.pnpm-store` — *nested included*, enumerated by the existing policy walk at zero extra I/O since it already sees each store while skipping into it) are now **read-only** inside the sandbox on both backends. The justification is structural: sandboxed bash has no legitimate install path (package-manager mutations are refused pre-execution; approved dependency installs run outside the sandbox). Build-tool caches stay writable via carve-outs (`.cache`, `.vite`, and `.vite-temp` — the review probed this repo's actual vite@7 and found TS-config builds bundle there before anything else runs), pre-created when absent so a first build isn't broken by its own missing cache dir. The workspace root is canonicalized before any rules derive — the review traced a Linux fail-open where a symlinked workspace path put the writable bind and the realpath'd read-only binds on different mount points. **Residual 2 narrows to the theoretical.** Both backend spawns are `detached: true` and teardown signals the process **group** (SIGTERM, then SIGKILL escalation, timer cleared on settle so a stale group-kill can never hit a recycled pid). Backgrounded grandchildren die with the tree; what remains — `setsid` escapees, and trees orphaned by a hard *server* crash on macOS — is documented at the helper. **Plus a regression the verification round caught in #5786's own revision**: the descent into *run-created* skip-named stores had been silently lost, leaving a fresh `node_modules` invisible to the scan *and* unbound. Restored, with a lane case pinning it. ## 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 - The `mari-guard-sibling-paths` lane asserts both backends' **generated rules** functionally: bwrap args ro-bind all stores (nested included) with the cache `--bind` stacking after its parent's ro-bind; the seatbelt profile places the cache allow after the store deny (last-match-wins), order-agnostically. A real detached leader is spawned and group-killed on POSIX; the ESRCH fallback is platform-gated honestly; the run-created-store descent and pre-existing-store skip are both pinned. - The verification review (two agents, this repo's real Vite probed) produced 9 findings; all are folded in or documented: `.vite-temp` carve-out, workspace canonicalization, the lost-descent regression, the escalation-timer clear, macOS-crash-orphan and symlink-store residuals documented at the helper, lane realpath wrap and honest test gating. - All Mari lanes pass; server lint clean; zero-error build. **Not exercised against live bwrap/seatbelt** — rule generation is covered functionally; the mount/precedence semantics are cited platform behavior. ## Docs and release impact - [x] No docs changes needed (CHANGELOG entry included) - [ ] 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) ## UI evidence (if applicable) Not applicable — sandbox policy and process teardown only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Installed-package stores, including nested and pnpm directories, are now read-only in the sandbox. * Build-tool cache folders remain writable for supported workflows. * Stopping a sandboxed command now terminates background processes as well. * Improved protection for workspace paths and package-store symbolic links. * Newly created package stores are fully checked after sandboxed execution. * Sandbox teardown is more reliable across supported platforms, including process cleanup and link restoration. <!-- 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:15:28 +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#6985
No description provided.