mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #8770] [MERGED] fix(server): harden Professor Mari's shell sandbox and code-check routing #8792
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#8792
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/8770
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @SpicyMarinara
Base:
staging← Head:fix/hardening-mari-shell-sandbox📝 Commits (5)
c20411cfix(server): harden Professor Mari's macOS shell sandbox and code-check routingee75e99fix(server): pin the shell sandbox's workspace and move aside new root .git/.env1401784fix(server): report a moved-aside root .git or .env even when the post-run scan fails539512btest(server): a positive control for the code check's build-output rule560f01atest(server): the sibling-paths source pin allows the new log line before the rethrow📊 Changes
6 files changed (+251 additions, -48 deletions)
View changed files
📝
packages/server/src/services/mari-db/mari-db.service.ts(+11 -3)📝
packages/server/src/services/professor-mari/workspace-agent.service.ts(+4 -3)📝
packages/server/src/services/professor-mari/workspace-commands.ts(+14 -4)📝
packages/server/src/services/professor-mari/workspace-shell-sandbox.ts(+91 -21)📝
scripts/regressions/mari-guard-sibling-paths.regression.ts(+7 -2)📝
scripts/regressions/professor-mari/sandbox-secrets.regression.ts(+124 -15)📄 Description
Linked issue
Closes #8769
Why this change
Professor Mari's shell commands are model-driven, so they run inside an OS sandbox. SECURITY.md lists sandbox escape, unintended host command execution and secret exposure as trust boundaries, and docs/home/professor-mari.md says
.env, the key file and Git's internal files are not available to her.On macOS, the sandbox only blocked reads of those paths. A sandboxed command could still change, rename, delete or create them, or move the workspace folder out from under the rules. Git config,
.envand the encryption key are all used later outside the sandbox.On Linux, the sandbox already blocks writes to these paths when they exist as a command starts. A root
.gitor.envthat a command created had no rule, and host git and the server's.envloader read exactly those two.Separately, the shell decided whether
mari code checkgoes to the sandbox by reading its arguments differently from the CLI that runs it. Some spellings therefore ran pnpm check outside the sandbox, with the server's environment.This PR closes these gaps.
What changed
.git,.envor.env.*files, or.encryption-key, in the workspace. The same applies if it renames the workspace folder or a folder that holds one of those files..env.example,.env.sampleand.env.templatestay writable. On Linux, a root.gitor.envthat a command creates is now renamed to<name>.unreviewed-<random>once the command ends, and the command output says so..git,.envand.env.*files and.encryption-key. It refuses these names where they do not exist yet, and it pins the workspace folder and the folders holding these files so they cannot be renamed. Ordinary files and folders in the workspace stay writable..gitor.envcreated during a command is moved aside after the run, the same way a replaced package-store link already is.mari code checknow runs in the shell sandbox exactly when the CLI would run pnpm check.mari code check -- --helpruns sandboxed, or is refused where no sandbox exists. A real help flag still shows the help text without running anything.Validation
pnpm checkpasses locallyCONTRIBUTING.mdManual verification notes
mari code checkfrom Mari's shell still completes a realpnpm checkin a checkout that haspackages/server/data/.encryption-key. The workspace folder and the folders holding the key are now pinned.mari code check --helpfrom Mari's shell still shows the code help text.node ./scripts/run-regressions.mjs --filter scripts/regressions/professor-mari/sandbox-secrets.regression.tsand manually verify that it passes. It was only run with macos-seatbelt..git, have Mari run a shell command that creates one. Manually verify that afterwards it has been renamed to.git.unreviewed-<random>and that the command output reports this.Agent-run checks (for reference; each regression was shown to fail without its fix):
node ./scripts/pnpm-runner.mjs build:shared: exit 0node ./scripts/run-regressions.mjs --filter scripts/regressions/professor-mari/sandbox-secrets.regression.ts (round 2 fix): PASSED with macos-seatbeltsame regression with only the round-2 source files stashed (git stash push -- workspace-shell-sandbox.ts workspace-commands.ts): FAILED: 'so is the workspace itself'. Source restored with git stash pop.scratch copy of the regression without the static root-pin assertion, on unfixed source: FAILED: 'the moved workspace never shows the key' (the key was printed). Copy deleted.scratch copy with the live sandbox section skipped, on unfixed source: FAILED: 'TypeError: quarantineNewRootSecrets is not a function'. Copy deleted.node ./scripts/run-regressions.mjs --filter scripts/regressions/professor-mari: 27/27 passednode ./scripts/run-regressions.mjs --filter scripts/regressions/mari-guard-sibling-paths.regression.ts: PASSED (includes the aftermath-order source assertion)node ./scripts/run-regressions.mjs --filter scripts/regressions/mari/: 39/39 passednode ./scripts/run-regressions.mjs --filter shell-sandbox: 1/1 passednode ./scripts/run-regressions.mjs --filter security: 32/32 passednode ./scripts/pnpm-runner.mjs --filter @marinara-engine/server lint (tsc -b shared, tsc --noEmit, character-activity tsconfig): exit 0npx tsc --noEmit -p tsconfig.json (root check:e2e-types): exit 0Independent adversarial review: changes, 3 issue(s), all addressed in a fix-up pass.
Known limits and risks:
.gitor.envthat a command creates exists on the host until the command ends. Host tools running at that same moment could still read it. Forbidden names created below the root are not caught on Linux. Theponytail:comment inlinuxBubblewrapArgsrecords this limit and the upgrade path: mount placeholders over a missing root.gitand.env, then remove the empty mount points afterwards..envloader read only the root's..gitor.envfrom one another process creates at the root during the run, for example a user runninggit initat that moment. Such a file is renamed, not deleted, and the output tells Mari to ask the user.packages/server/datainside the workspace, because the masking mounts move with the folder. The key stays masked. This behaviour is older than this PR and unchanged.-c core.fsmonitor=falseandcore.hooksPathflags on unsandboxed git calls were not added. The root cause is fixed in the sandbox, and those flags cannot stop all config-driven execution, such as filter drivers.pnpm checkwas not run inside the new sandbox.Docs and release impact
docs-i18nbranch updated to match, or a[docs-i18n]follow-up issue opened (see CONTRIBUTING.md § Translated documentation)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.