[PR #5787] [MERGED] fix(mari): close the verification guard's bash and symlink sibling paths #6931

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

📋 Pull Request Information

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

Base: staging ← Head: fix/5776-5778-guard-sibling-paths


📝 Commits (4)

  • 96c26fc fix(mari): close the guard's bash and symlink sibling paths (#5776-#5778)
  • 84c9df4 fix(mari): harden the sibling-path fixes per the adversarial review
  • fcb75ed fix(mari): left-anchor the sensitive-path pattern (CodeRabbit)
  • 2c7c0a6 fix(mari): root-scope launcher names in the sensitive-path gate (CodeRabbit)

📊 Changes

4 files changed (+509 additions, -49 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 packages/server/src/services/professor-mari/workspace-agent.service.ts (+164 -49)
📝 packages/server/src/services/professor-mari/workspace-change-review.service.ts (+55 -0)
➕ scripts/regressions/mari-guard-sibling-paths.regression.ts (+289 -0)

📄 Description

Linked issue

Closes #5776
Closes #5777
Closes #5778

Why this change

  • All three issues are pre-existing siblings of the #5756 bug class fixed in #5775: a workspace command can succeed without its effect actually persisting, the verification guard counts it as an applied mutation anyway, and Mari can then "verify" and claim a change that never happened — the silent-persistent-failure shape the guard exists to prevent. They were found by the adversarial review run for #5775 and deliberately split out to keep that PR focused.

What changed

  • #5776 — mari CLI dry-runs through bash counted as applied. mari db insert … (or any mari mutation) without --apply is a dry-run that persists nothing but exits successfully. commandMariDirect now emits an engine sentinel at position zero of the output for dry-run results, and isAppliedWorkspaceMutation excludes bash results that start with it. Position zero is trustworthy because a sandboxed script's output always begins with the engine-written Command: header — script stdout, or sentinel text embedded in the command string, can never occupy it (same anchoring principle as #5775's staging marker).
  • #5777 — sandbox-denied sensitive writes counted as applied. The shell sandbox blocks writes to supply-chain-sensitive paths silently (read-only binds on Linux, deny file-write* on macOS), so an error-tolerant compound command like sed -i … package.json; echo done exits 0 and looked like a successful mutation. commandBash now refuses the common write shapes targeting sensitive names (cp/mv/rm/touch/truncate/tee, in-place sed/perl, redirection) before execution, with guidance to the write/edit staging flow. It's a best-effort heuristic by design — the sandbox stays the hard floor; the gate turns the common silent failures into loud, actionable ones. It runs after direct-mari routing, so mari CLI commands whose content mentions these names are unaffected.
  • #5778 — symlinks bypassed sensitive-file staging. write/edit decided whether to stage from the requested path only, so link.json → package.json classified "normal" and the write followed the link into the sensitive file with no approval. Path resolution (extracted to workspaceMutationTargetForPath, exported for the lane) now chases the leaf's symlink chain — dangling links included, which previously skipped canonicalization entirely — enforces the workspace-escape and forbidden checks on the effective target, and returns the sensitive target for staging. Bonus hardening: a dangling symlink pointing outside the workspace is now refused instead of silently followed by writeFile.
  • Adversarial-review hardening round (a 36-agent find-and-refute pass ran over the diff before opening; every confirmed finding is folded in): the redirect gate now catches quoted targets (> "package.json" — the shape LLMs actually write) plus interpreter one-liners, dd of=, and git checkout/restore of sensitive files; the symlink chase now fails closed at its hop cap and re-canonicalizes every hop through existing ancestors, so deep chains and dangling leaves routed through symlinked directories can't evade the policy checks; and a mari CLI mutation embedded in a compound command is refused up front (the sandbox denies the network the CLI needs, so those always failed silently while counting as applied — refusing has no false-positive case). One review finding is a pre-existing sandbox-layer gap out of this PR's scope, filed as #5786: the write-deny list only covers sensitive files that exist at spawn, so the heuristic gate here is the primary guard for newly created sensitive files — the doc comment says so honestly now.
  • New mari-guard-sibling-paths regression lane: functional dry-run/forgery cases, a blocked/allowed command matrix for the sensitive-path gate, real-filesystem symlink cases (auto-skipped where symlink creation needs elevation, e.g. Windows without Developer Mode — they run on Linux CI), and source pins on the sentinel emission, refusal ordering, and staging call sites.
  • CHANGELOG entry under [Unreleased] → Fixed.

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

  • Commands run locally (all passing): node ./scripts/run-regressions.mjs --filter mari-guard-sibling-paths (new lane), plus the prompt, mari-polish, mari-understood-request, and mari-ask-latch lanes; pnpm --filter @marinara-engine/server lint; pnpm build.
  • A multi-agent adversarial review (find → per-finding refutation) ran over the diff before opening; its confirmed findings were folded in.
  • Honest caveat: the lane's symlink cases need symlink-creation rights, which this Windows machine lacks (they log a skip locally) — their first real execution is this PR's own Linux CI run. The non-symlink cases and all source pins ran locally.
  • Server-side guard logic only — no UI surface. Manual verification that would still be valuable: in a Mari chat, ask her to run a mari CLI command in the terminal without --apply and confirm she reports it as a preview rather than a saved change.

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)

UI evidence (if applicable)

Not applicable — server-side guard behavior only.

Summary by CodeRabbit

  • Bug Fixes
    • Terminal previews are now clearly identified and cannot be mistaken for saved changes.
    • Writes to protected files are refused upfront with guidance to use the approval flow.
    • Shortcut files pointing to protected or out-of-workspace locations are handled safely and require approval when appropriate, including links to files that do not yet exist.
    • Shell commands attempting protected-file mutations are blocked more reliably, including compound commands and writes to files that do not yet exist.

🔄 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/5787 **Author:** [@kolacheee](https://github.com/kolacheee) **Created:** 9/2/2026 **Status:** ✅ Merged **Merged:** 9/2/2026 **Merged by:** [@kolacheee](https://github.com/kolacheee) **Base:** `staging` ← **Head:** `fix/5776-5778-guard-sibling-paths` --- ### 📝 Commits (4) - [`96c26fc`](https://github.com/Pasta-Devs/Marinara-Engine/commit/96c26fccd6e60bfc0389c2430071242317bfb05c) fix(mari): close the guard's bash and symlink sibling paths (#5776-#5778) - [`84c9df4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/84c9df4bf4dcf203eb7c58d9d94ad04772a97576) fix(mari): harden the sibling-path fixes per the adversarial review - [`fcb75ed`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fcb75ed7039d17d06352ee30c6a5ea9063f074f7) fix(mari): left-anchor the sensitive-path pattern (CodeRabbit) - [`2c7c0a6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/2c7c0a607a55737d6b2e2b12d5b989ec0c87a7d7) fix(mari): root-scope launcher names in the sensitive-path gate (CodeRabbit) ### 📊 Changes **4 files changed** (+509 additions, -49 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `packages/server/src/services/professor-mari/workspace-agent.service.ts` (+164 -49) 📝 `packages/server/src/services/professor-mari/workspace-change-review.service.ts` (+55 -0) ➕ `scripts/regressions/mari-guard-sibling-paths.regression.ts` (+289 -0) </details> ### 📄 Description ## Linked issue Closes #5776 Closes #5777 Closes #5778 ## Why this change - All three issues are pre-existing siblings of the #5756 bug class fixed in #5775: a workspace command can succeed without its effect actually persisting, the verification guard counts it as an applied mutation anyway, and Mari can then "verify" and claim a change that never happened — the silent-persistent-failure shape the guard exists to prevent. They were found by the adversarial review run for #5775 and deliberately split out to keep that PR focused. ## What changed - **#5776 — mari CLI dry-runs through bash counted as applied.** `mari db insert …` (or any mari mutation) without `--apply` is a dry-run that persists nothing but exits successfully. `commandMariDirect` now emits an engine sentinel at **position zero** of the output for dry-run results, and `isAppliedWorkspaceMutation` excludes bash results that start with it. Position zero is trustworthy because a sandboxed script's output always begins with the engine-written `Command:` header — script stdout, or sentinel text embedded in the command string, can never occupy it (same anchoring principle as #5775's staging marker). - **#5777 — sandbox-denied sensitive writes counted as applied.** The shell sandbox blocks writes to supply-chain-sensitive paths silently (read-only binds on Linux, `deny file-write*` on macOS), so an error-tolerant compound command like `sed -i … package.json; echo done` exits 0 and looked like a successful mutation. `commandBash` now refuses the common write shapes targeting sensitive names (`cp/mv/rm/touch/truncate/tee`, in-place `sed`/`perl`, redirection) **before** execution, with guidance to the write/edit staging flow. It's a best-effort heuristic by design — the sandbox stays the hard floor; the gate turns the common silent failures into loud, actionable ones. It runs after direct-mari routing, so mari CLI commands whose *content* mentions these names are unaffected. - **#5778 — symlinks bypassed sensitive-file staging.** `write`/`edit` decided whether to stage from the requested path only, so `link.json → package.json` classified "normal" and the write followed the link into the sensitive file with no approval. Path resolution (extracted to `workspaceMutationTargetForPath`, exported for the lane) now chases the leaf's symlink chain — dangling links included, which previously skipped canonicalization entirely — enforces the workspace-escape and forbidden checks on the *effective* target, and returns the sensitive target for staging. Bonus hardening: a dangling symlink pointing outside the workspace is now refused instead of silently followed by `writeFile`. - **Adversarial-review hardening round** (a 36-agent find-and-refute pass ran over the diff before opening; every confirmed finding is folded in): the redirect gate now catches quoted targets (`> "package.json"` — the shape LLMs actually write) plus interpreter one-liners, `dd of=`, and `git checkout/restore` of sensitive files; the symlink chase now fails **closed** at its hop cap and re-canonicalizes every hop through existing ancestors, so deep chains and dangling leaves routed through symlinked *directories* can't evade the policy checks; and a mari CLI mutation embedded in a compound command is refused up front (the sandbox denies the network the CLI needs, so those always failed silently while counting as applied — refusing has no false-positive case). One review finding is a pre-existing sandbox-layer gap out of this PR's scope, filed as #5786: the write-deny list only covers sensitive files that exist at spawn, so the heuristic gate here is the primary guard for newly created sensitive files — the doc comment says so honestly now. - New `mari-guard-sibling-paths` regression lane: functional dry-run/forgery cases, a blocked/allowed command matrix for the sensitive-path gate, real-filesystem symlink cases (auto-skipped where symlink creation needs elevation, e.g. Windows without Developer Mode — they run on Linux CI), and source pins on the sentinel emission, refusal ordering, and staging call sites. - CHANGELOG entry under [Unreleased] → Fixed. ## 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 - Commands run locally (all passing): `node ./scripts/run-regressions.mjs --filter mari-guard-sibling-paths` (new lane), plus the `prompt`, `mari-polish`, `mari-understood-request`, and `mari-ask-latch` lanes; `pnpm --filter @marinara-engine/server lint`; `pnpm build`. - A multi-agent adversarial review (find → per-finding refutation) ran over the diff before opening; its confirmed findings were folded in. - Honest caveat: the lane's symlink cases need symlink-creation rights, which this Windows machine lacks (they log a skip locally) — their first real execution is this PR's own Linux CI run. The non-symlink cases and all source pins ran locally. - Server-side guard logic only — no UI surface. Manual verification that would still be valuable: in a Mari chat, ask her to run a `mari` CLI command in the terminal without `--apply` and confirm she reports it as a preview rather than a saved change. ## Docs and release impact - [ ] No docs changes needed - [x] 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 — server-side guard behavior only. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Terminal previews are now clearly identified and cannot be mistaken for saved changes. * Writes to protected files are refused upfront with guidance to use the approval flow. * Shortcut files pointing to protected or out-of-workspace locations are handled safely and require approval when appropriate, including links to files that do not yet exist. * Shell commands attempting protected-file mutations are blocked more reliably, including compound commands and writes to files that do not yet exist. <!-- 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:00 +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#6931
No description provided.