[PR #8798] [MERGED] fix(server): hold Professor Mari's mari images sources to her read rule and their app folders #8812

Closed
opened 2026-11-07 17:39:53 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/8798
Author: @SpicyMarinara
Created: 11/3/2026
Status: ✅ Merged
Merged: 11/3/2026
Merged by: @SpicyMarinara

Base: staging ← Head: fix/hardening-mari-images-source


📝 Commits (2)

  • 8ece0c9 fix(server): hold Professor Mari's mari images file sources to her read rule
  • a5b66e6 fix(server): read mari images app and asset sources only inside their folder

📊 Changes

4 files changed (+125 additions, -23 deletions)

View changed files

📝 packages/server/src/services/mari-db/mari-db.service.ts (+8 -1)
📝 packages/server/src/services/mari-db/mari-images.service.ts (+44 -17)
📝 packages/server/src/services/professor-mari/workspace-commands.ts (+3 -1)
📝 scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts (+70 -4)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.

Linked issue

Closes #8797

Why this change

This follows up CodeRabbit's minor finding on #8771. Simple mari commands run in the server process, outside the shell sandbox. #8771 held the --json-file, --file and --css-file paths to the read tool's rule. mari images also reads a file in two cases, and neither read was held to a boundary:

  • When a --source, --source-image or --from value (or an --asset value matching no asset, or a target's stored image) is not an asset id, app URL or data URL, it is treated as a file path. That path got no workspace check: files outside the workspace were read, and secret files were read before the image type check rejected them.
  • Asset ids and app URLs name a file inside an app folder, but that path was only checked as written and the read followed links. With the data dir inside the workspace, Professor Mari's shell can write into those folders, so a link placed there could still reach a file outside.

These flags also take non-file forms, so an argv scan can't check them. Each form is checked where its file is actually read.

What changed

  • Professor Mari can no longer use an image file outside the workspace (for example one in Downloads), or a .env, encryption-key or Git file, as a mari images source. This covers --source, --source-image and --from, and an --asset value that matches no preview asset. To use such an image, upload it in the app or put it in the workspace, then point Mari at it.
  • mari images no longer reads an app image (an /api/... URL) or a preview asset whose file is a link pointing out of its app folder, or that sits in an app folder that is itself a link. This applies to Professor Mari and to your own mari CLI. To use such an image, replace the link with the real image file.
  • Real app images, data URLs and preview asset ids work as before, including when the data folder itself sits behind a link. A target's existing image goes through the same checks.
  • Behind the scenes, Professor Mari's direct mari runtime passes the read tool's rule to executeCli as resolveReadPath, and the file form is checked before anything is opened. App and asset forms read the real path only when it stays inside the real app folder. The HTTP CLI route never sets resolveReadPath.
  • The professor-mari/direct-mari-file-flags regression now covers refused and allowed file sources, plus linked backgrounds, a linked non-image, a linked sprite folder and a linked preview asset, with DATA_DIR reached through a link.

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

  • Manually verify in Professor Mari that mari images assign --target background --source <workspace image> still shows a dry-run with that file as its source.
  • Manually verify that mari images edit with an asset id from mari images generate, or with a target's existing avatar or background, still finds its source image.
  • Manually verify that a mari images source pointing outside the workspace, or at .env, is refused with the read tool's message.
  • Manually verify, on an install where the data folder is a link (Docker volume, or macOS /tmp), that mari images assign --source /api/backgrounds/file/<existing>.png still works.
  • Manually verify on Windows that app-URL sources such as /api/avatars/file/ still resolve. The regression was run on macOS only.

Agent-run checks (for reference; the regression was shown to fail without the fix):

  • node ./scripts/pnpm-runner.mjs build:shared: passed
  • node ./scripts/run-regressions.mjs --filter direct-mari-file-flags (new rows, before the source edit, and again with the HEAD mari-images.service.ts swapped in): failed as expected, 0/1: AssertionError on --source /api/backgrounds/file/linked.png, which returned a successful dry-run
  • temporary per-row probe (deleted afterwards) against the old and fixed service: old code: all 4 new rows were read or rejected only after reading; fixed code: all 8 refused rows refused
  • node ./scripts/run-regressions.mjs --filter direct-mari-file-flags (with fix): 1/1 passed
  • node ./scripts/run-regressions.mjs --filter professor-mari/: 26/26 passed
  • node ./scripts/run-regressions.mjs --filter regressions/mari/: 39/39 passed
  • node ./scripts/run-regressions.mjs --filter sprite-list-security / sprite-generated-save / mari-guard-sibling-paths / mari-write-readback: each 1/1 passed
  • cd packages/server && node ../../scripts/pnpm-runner.mjs run lint: passed (tsc -b shared, tsc --noEmit, regressions tsconfig)
  • npx prettier --check on the 4 changed files: All matched files use Prettier code style

Independent adversarial review, then a fix-up pass for its findings.

Known limits and risks:

Low to moderate. The main risk is the intended behaviour change: images Mari could take from outside the workspace are now refused. It is listed first under What changed, with a way back.

  1. App-folder rule. It is slightly stricter than the app's own media routes. Those accept a link anywhere inside the data dir; mari images accepts only a file inside the form's own folder. A hand-made link from one app folder to another (for example backgrounds to gallery) still displays in the app but is now refused by mari images. The rule also applies to the user's own mari CLI over the HTTP route, because app-URL and asset sources mean app images there too. The file-form rule (resolveReadPath) is still set only by Professor Mari's direct runtime.

  2. Check-then-read window. The real path is checked and then read by that checked path. A folder swapped for a link in between is not caught. This is marked with a ponytail: comment, and the upgrade path is opening each path part with O_NOFOLLOW.

  3. How the regression differs from the reviewer's request. It places the links with fs directly and keeps DATA_DIR outside the workspace, reached through a link. The reviewer asked for a row with DATA_DIR inside the workspace. The check never looks at the workspace, only at the real data dir and the form's folder, so where DATA_DIR sits does not change the result. The reviewer already reproduced the sandboxed shell placing the link under seatbelt; I did not rerun that.

  4. Known remaining paths, outside this finding, not fixed and not tested. mari images also writes through links in the same folders: the preview manifest, background meta.json, and assigned avatar, background, sprite and lorebook files. It also reads the manifest and meta.json JSON through them. A follow-up issue should be filed to give those reads and writes the same real-folder check.

  5. Other existing ceilings. The text-file flags still use #8771's argv scan; the ponytail comment names resolveReadPath as their upgrade path. A target's stored image that is a bare filesystem path (none found in current flows) is now held to the workspace rule.

Docs and release impact

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

🤖 Generated with Claude Code


🔄 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/8798 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 11/3/2026 **Status:** ✅ Merged **Merged:** 11/3/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/hardening-mari-images-source` --- ### 📝 Commits (2) - [`8ece0c9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/8ece0c9cb3b0677a3af25f14a671f10fece62ce8) fix(server): hold Professor Mari's mari images file sources to her read rule - [`a5b66e6`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a5b66e6542fdedeb55be7877349bb1d1a644dbbb) fix(server): read mari images app and asset sources only inside their folder ### 📊 Changes **4 files changed** (+125 additions, -23 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+8 -1) 📝 `packages/server/src/services/mari-db/mari-images.service.ts` (+44 -17) 📝 `packages/server/src/services/professor-mari/workspace-commands.ts` (+3 -1) 📝 `scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts` (+70 -4) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. ## Linked issue Closes #8797 ## Why this change This follows up CodeRabbit's minor finding on #8771. Simple `mari` commands run in the server process, outside the shell sandbox. #8771 held the --json-file, --file and --css-file paths to the read tool's rule. `mari images` also reads a file in two cases, and neither read was held to a boundary: - When a --source, --source-image or --from value (or an --asset value matching no asset, or a target's stored image) is not an asset id, app URL or data URL, it is treated as a file path. That path got no workspace check: files outside the workspace were read, and secret files were read before the image type check rejected them. - Asset ids and app URLs name a file inside an app folder, but that path was only checked as written and the read followed links. With the data dir inside the workspace, Professor Mari's shell can write into those folders, so a link placed there could still reach a file outside. These flags also take non-file forms, so an argv scan can't check them. Each form is checked where its file is actually read. ## What changed - Professor Mari can no longer use an image file outside the workspace (for example one in Downloads), or a .env, encryption-key or Git file, as a `mari images` source. This covers --source, --source-image and --from, and an --asset value that matches no preview asset. To use such an image, upload it in the app or put it in the workspace, then point Mari at it. - `mari images` no longer reads an app image (an /api/... URL) or a preview asset whose file is a link pointing out of its app folder, or that sits in an app folder that is itself a link. This applies to Professor Mari and to your own mari CLI. To use such an image, replace the link with the real image file. - Real app images, data URLs and preview asset ids work as before, including when the data folder itself sits behind a link. A target's existing image goes through the same checks. - Behind the scenes, Professor Mari's direct mari runtime passes the read tool's rule to executeCli as resolveReadPath, and the file form is checked before anything is opened. App and asset forms read the real path only when it stays inside the real app folder. The HTTP CLI route never sets resolveReadPath. - The professor-mari/direct-mari-file-flags regression now covers refused and allowed file sources, plus linked backgrounds, a linked non-image, a linked sprite folder and a linked preview asset, with DATA_DIR reached through a link. ## Validation <!-- These are human tasks. Never tick a box for a check that was not actually performed. --> - [ ] `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 - Manually verify in Professor Mari that `mari images assign --target background --source <workspace image>` still shows a dry-run with that file as its source. - Manually verify that `mari images edit` with an asset id from `mari images generate`, or with a target's existing avatar or background, still finds its source image. - Manually verify that a `mari images` source pointing outside the workspace, or at .env, is refused with the read tool's message. - Manually verify, on an install where the data folder is a link (Docker volume, or macOS /tmp), that `mari images assign --source /api/backgrounds/file/<existing>.png` still works. - Manually verify on Windows that app-URL sources such as /api/avatars/file/<name> still resolve. The regression was run on macOS only. Agent-run checks (for reference; the regression was shown to fail without the fix): - `node ./scripts/pnpm-runner.mjs build:shared`: passed - `node ./scripts/run-regressions.mjs --filter direct-mari-file-flags (new rows, before the source edit, and again with the HEAD mari-images.service.ts swapped in)`: failed as expected, 0/1: AssertionError on --source /api/backgrounds/file/linked.png, which returned a successful dry-run - `temporary per-row probe (deleted afterwards) against the old and fixed service`: old code: all 4 new rows were read or rejected only after reading; fixed code: all 8 refused rows refused - `node ./scripts/run-regressions.mjs --filter direct-mari-file-flags (with fix)`: 1/1 passed - `node ./scripts/run-regressions.mjs --filter professor-mari/`: 26/26 passed - `node ./scripts/run-regressions.mjs --filter regressions/mari/`: 39/39 passed - `node ./scripts/run-regressions.mjs --filter sprite-list-security / sprite-generated-save / mari-guard-sibling-paths / mari-write-readback`: each 1/1 passed - `cd packages/server && node ../../scripts/pnpm-runner.mjs run lint`: passed (tsc -b shared, tsc --noEmit, regressions tsconfig) - `npx prettier --check on the 4 changed files`: All matched files use Prettier code style Independent adversarial review, then a fix-up pass for its findings. Known limits and risks: Low to moderate. The main risk is the intended behaviour change: images Mari could take from outside the workspace are now refused. It is listed first under What changed, with a way back. 1. App-folder rule. It is slightly stricter than the app's own media routes. Those accept a link anywhere inside the data dir; mari images accepts only a file inside the form's own folder. A hand-made link from one app folder to another (for example backgrounds to gallery) still displays in the app but is now refused by mari images. The rule also applies to the user's own mari CLI over the HTTP route, because app-URL and asset sources mean app images there too. The file-form rule (resolveReadPath) is still set only by Professor Mari's direct runtime. 2. Check-then-read window. The real path is checked and then read by that checked path. A folder swapped for a link in between is not caught. This is marked with a `ponytail:` comment, and the upgrade path is opening each path part with O_NOFOLLOW. 3. How the regression differs from the reviewer's request. It places the links with fs directly and keeps DATA_DIR outside the workspace, reached through a link. The reviewer asked for a row with DATA_DIR inside the workspace. The check never looks at the workspace, only at the real data dir and the form's folder, so where DATA_DIR sits does not change the result. The reviewer already reproduced the sandboxed shell placing the link under seatbelt; I did not rerun that. 4. Known remaining paths, outside this finding, not fixed and not tested. mari images also writes through links in the same folders: the preview manifest, background meta.json, and assigned avatar, background, sprite and lorebook files. It also reads the manifest and meta.json JSON through them. A follow-up issue should be filed to give those reads and writes the same real-folder check. 5. Other existing ceilings. The text-file flags still use #8771's argv scan; the ponytail comment names resolveReadPath as their upgrade path. A target's stored image that is a bare filesystem path (none found in current flows) is now held to the workspace rule. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 17:39:53 +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#8812
No description provided.