[PR #8771] [MERGED] fix(server): hold Professor Mari's direct mari CLI and raw DB writes to her file and key boundaries #8794

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

📋 Pull Request Information

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

Base: staging ← Head: fix/hardening-mari-db-cli


📝 Commits (2)

  • b0060d4 fix(server): hold Professor Mari's direct mari CLI to her file and key boundaries
  • b3fd0c9 fix(server): keep chat text destinations out of raw Mari DB writes

📊 Changes

4 files changed (+355 additions, -1 deletions)

View changed files

📝 packages/server/src/services/mari-db/mari-db.service.ts (+55 -0)
📝 packages/server/src/services/professor-mari/workspace-commands.ts (+14 -0)
📝 scripts/regressions/mari/db-execution-security.regression.ts (+204 -1)
➕ scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts (+82 -0)

📄 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 #8769

Why this change

Professor Mari's read tool and both shell sandboxes already refuse paths outside the workspace, as well as .env, the encryption key and Git internals. Simple mari ... commands run in the server process, outside the sandbox, and their text-file flags did not follow that rule. Raw mari db writes are also applied before the Keep/Restore review. For Models, Connections and the speech server settings, which keep a stored key next to the address it is sent to, that skipped the checks the Connections editor and profile import make. The same was true for the chat settings that send chat text to an outside address or hold its key (Discord mirror, DeepLX address, DeepL key, haptics server), which profile import strips. This change applies the same rules the app already enforces elsewhere to the direct CLI and to raw DB writes.

What changed

  • Behavior change: Professor Mari can no longer change Models, Connections, or the Text to Speech and speech-to-text server settings through raw mari db commands or transforms. These writes are refused with a message pointing the user to Connections and Settings. This also blocks harmless edits she could make before, for example a connection's prompt preset override. Like the other Mari DB floors, it also applies to the loopback mari CLI.
  • Behavior change: raw mari db writes and transforms can no longer set or change a chat's Discord mirror webhook, DeepLX address, DeepL key or haptics server address, in a chat, a chat settings profile, or the translator defaults for new chats. This includes copying them into a new row. The refusal points the user to Chat Settings. Her other chat-settings edits still apply, and clearing one of these values is still allowed.
  • Behavior change: direct mari commands now refuse --json-file, --file and --css-file paths that are outside the workspace or point at .env, the encryption key or Git internals, with the same message the read tool gives. A missing file now reports the read tool's 'Path not found' text instead of a raw ENOENT.
  • Payload files inside the workspace (the documented temp-file workflow) keep working unchanged.
  • New regression scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts. scripts/regressions/mari/db-execution-security.regression.ts is extended with the Models/Connections/speech-settings floor and the chat-destination floor.

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 the Professor Mari panel (Auto mode) that asking her to create a theme from a CSS file she wrote inside the workspace still works and shows the change card.
  • Manually verify that asking Professor Mari to change a Model's or Connection's address, or the Text to Speech server, is refused with the 'The user edits them in Connections and Settings' message and that nothing changes in Connections.
  • Manually verify that asking Professor Mari to set a chat's Discord mirror webhook or DeepLX address is refused with the 'The user enters them in Chat Settings' message, and that asking her to change another chat setting (for example turning auto-translate on) still produces a normal change card.
  • Manually verify that you can still edit Models, Connections, Text to Speech and speech-to-text settings, the Discord mirror, the translator address and key, and the haptics server yourself in the UI and that they save normally (those paths do not go through Mari DB).

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

  • node ./scripts/pnpm-runner.mjs build:shared: succeeded
  • node ./scripts/run-regressions.mjs --filter mari/db-execution-security (this round's mari-db.service.ts change stashed): FAILED as expected: the chats translationDeeplxUrl patch returned ok:true, mode apply
  • scratch probe (temp FILE_STORAGE_DIR) running each new destination write with and without the floor: without the floor all 5 writes applied (ok:true); with it all 5 were refused with only the new message; clearing translationDeeplxUrl applied in both
  • node ./scripts/run-regressions.mjs --filter mari/db-execution-security (with fix): 1/1 passed (macos-seatbelt)
  • node ./scripts/run-regressions.mjs --filter direct-mari-file-flags: 1/1 passed
  • node ./scripts/run-regressions.mjs --filter mari: 87/87 passed
  • node ./scripts/run-regressions.mjs --filter <name> for chat-local-destination-security, extension-security, open-issues, chat-diagnose, package-table-registrati: each 1/1 passed
  • cd packages/server && node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activ: exit 0
  • npx prettier --write on the 2 files changed this round; npx prettier --check on all 4 branch files: All matched files use Prettier code style
  • eslint: not run: ESLint is configured only for packages/client; no client files changed, so pnpm localization:check was not needed and was not run
  • full pnpm check / full regression suite: not run (server type-check, prettier and the targeted regressions above only)

Independent adversarial review: changes, 1 issue(s), all addressed in a fix-up pass.

Known limits and risks:

  • The flag scan copies mari-db's parseArgs rule for these three flags. It over-approximates, because it also checks tokens after --, so it can only refuse more than the CLI would read. A future mari flag that reads files must be added to DIRECT_MARI_TEXT_FILE_FLAGS, which is marked with a ponytail: comment.
  • The connection floor denies whole tables and rows, not individual fields. Mari loses every raw edit to api_connections, connection_accounts and the tts and speech-to-text settings rows, including harmless ones. The floor also applies to the loopback human mari CLI, as the existing permissions and runtime floors do.
  • The chat-destination floor works per key. It refuses a change when the new value is non-empty and differs from the stored one. Clearing is allowed on purpose, because it sends nothing. A raw copy of a chat or profile that carries one of these values into a new row is refused. It checks the same three places profile import strips (chats.metadata, chat_presets settings.metadata, app_settings translator-defaults). A future place that stores these keys would need adding here and in backup.routes.ts.
  • Still out of scope, worth a follow-up decision: redacting encrypted keys and local-destination values from raw mari db reads. Also, the verifier noted a pre-existing gap in the shared workspace path guard: Windows 8.3 short names are not resolved. That affects the read tool too and was not introduced here.
  • No docs were changed. docs/home/professor-mari.md already says .env and the key file are not available to her. A line saying she cannot change Models, Connections, speech settings or chat text destinations could be added, which would also need the docs-i18n follow-up.
  • Only the server type-check part of pnpm check, prettier on the changed files and the targeted regressions above were run. The full pnpm check and the full regression suite were not run. Nothing was pushed and no PR was opened.
  • The relayed user request to change Otome Hearth's outfit show-off affection from +20 to +5 is outside this hardening step and was not touched in this worktree. It needs its own task in the repository that owns Otome Hearth.

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/8771 **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-db-cli` --- ### 📝 Commits (2) - [`b0060d4`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b0060d4e0efdad641672b98b00f0d1e46ff21a22) fix(server): hold Professor Mari's direct mari CLI to her file and key boundaries - [`b3fd0c9`](https://github.com/Pasta-Devs/Marinara-Engine/commit/b3fd0c9935b4afba86deb807c28c902a0435b4b7) fix(server): keep chat text destinations out of raw Mari DB writes ### 📊 Changes **4 files changed** (+355 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `packages/server/src/services/mari-db/mari-db.service.ts` (+55 -0) 📝 `packages/server/src/services/professor-mari/workspace-commands.ts` (+14 -0) 📝 `scripts/regressions/mari/db-execution-security.regression.ts` (+204 -1) ➕ `scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts` (+82 -0) </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 #8769 ## Why this change Professor Mari's read tool and both shell sandboxes already refuse paths outside the workspace, as well as .env, the encryption key and Git internals. Simple `mari ...` commands run in the server process, outside the sandbox, and their text-file flags did not follow that rule. Raw `mari db` writes are also applied before the Keep/Restore review. For Models, Connections and the speech server settings, which keep a stored key next to the address it is sent to, that skipped the checks the Connections editor and profile import make. The same was true for the chat settings that send chat text to an outside address or hold its key (Discord mirror, DeepLX address, DeepL key, haptics server), which profile import strips. This change applies the same rules the app already enforces elsewhere to the direct CLI and to raw DB writes. ## What changed - Behavior change: Professor Mari can no longer change Models, Connections, or the Text to Speech and speech-to-text server settings through raw `mari db` commands or transforms. These writes are refused with a message pointing the user to Connections and Settings. This also blocks harmless edits she could make before, for example a connection's prompt preset override. Like the other Mari DB floors, it also applies to the loopback `mari` CLI. - Behavior change: raw `mari db` writes and transforms can no longer set or change a chat's Discord mirror webhook, DeepLX address, DeepL key or haptics server address, in a chat, a chat settings profile, or the translator defaults for new chats. This includes copying them into a new row. The refusal points the user to Chat Settings. Her other chat-settings edits still apply, and clearing one of these values is still allowed. - Behavior change: direct `mari` commands now refuse --json-file, --file and --css-file paths that are outside the workspace or point at .env, the encryption key or Git internals, with the same message the read tool gives. A missing file now reports the read tool's 'Path not found' text instead of a raw ENOENT. - Payload files inside the workspace (the documented temp-file workflow) keep working unchanged. - New regression scripts/regressions/professor-mari/direct-mari-file-flags.regression.ts. scripts/regressions/mari/db-execution-security.regression.ts is extended with the Models/Connections/speech-settings floor and the chat-destination floor. ## 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 the Professor Mari panel (Auto mode) that asking her to create a theme from a CSS file she wrote inside the workspace still works and shows the change card. - Manually verify that asking Professor Mari to change a Model's or Connection's address, or the Text to Speech server, is refused with the 'The user edits them in Connections and Settings' message and that nothing changes in Connections. - Manually verify that asking Professor Mari to set a chat's Discord mirror webhook or DeepLX address is refused with the 'The user enters them in Chat Settings' message, and that asking her to change another chat setting (for example turning auto-translate on) still produces a normal change card. - Manually verify that you can still edit Models, Connections, Text to Speech and speech-to-text settings, the Discord mirror, the translator address and key, and the haptics server yourself in the UI and that they save normally (those paths do not go through Mari DB). Agent-run checks (for reference; each regression was shown to fail without its fix): - `node ./scripts/pnpm-runner.mjs build:shared`: succeeded - `node ./scripts/run-regressions.mjs --filter mari/db-execution-security (this round's mari-db.service.ts change stashed)`: FAILED as expected: the chats translationDeeplxUrl patch returned ok:true, mode apply - `scratch probe (temp FILE_STORAGE_DIR) running each new destination write with and without the floor`: without the floor all 5 writes applied (ok:true); with it all 5 were refused with only the new message; clearing translationDeeplxUrl applied in both - `node ./scripts/run-regressions.mjs --filter mari/db-execution-security (with fix)`: 1/1 passed (macos-seatbelt) - `node ./scripts/run-regressions.mjs --filter direct-mari-file-flags`: 1/1 passed - `node ./scripts/run-regressions.mjs --filter mari`: 87/87 passed - `node ./scripts/run-regressions.mjs --filter <name> for chat-local-destination-security, extension-security, open-issues, chat-diagnose, package-table-registrati`: each 1/1 passed - `cd packages/server && node ../../scripts/pnpm-runner.mjs run lint (tsc -b ../shared && tsc --noEmit && tsc -p ../../scripts/regressions/tsconfig.character-activ`: exit 0 - `npx prettier --write on the 2 files changed this round; npx prettier --check on all 4 branch files`: All matched files use Prettier code style - `eslint`: not run: ESLint is configured only for packages/client; no client files changed, so pnpm localization:check was not needed and was not run - `full pnpm check / full regression suite`: not run (server type-check, prettier and the targeted regressions above only) Independent adversarial review: changes, 1 issue(s), all addressed in a fix-up pass. Known limits and risks: - The flag scan copies mari-db's parseArgs rule for these three flags. It over-approximates, because it also checks tokens after `--`, so it can only refuse more than the CLI would read. A future mari flag that reads files must be added to DIRECT_MARI_TEXT_FILE_FLAGS, which is marked with a ponytail: comment. - The connection floor denies whole tables and rows, not individual fields. Mari loses every raw edit to api_connections, connection_accounts and the tts and speech-to-text settings rows, including harmless ones. The floor also applies to the loopback human `mari` CLI, as the existing permissions and runtime floors do. - The chat-destination floor works per key. It refuses a change when the new value is non-empty and differs from the stored one. Clearing is allowed on purpose, because it sends nothing. A raw copy of a chat or profile that carries one of these values into a new row is refused. It checks the same three places profile import strips (chats.metadata, chat_presets settings.metadata, app_settings translator-defaults). A future place that stores these keys would need adding here and in backup.routes.ts. - Still out of scope, worth a follow-up decision: redacting encrypted keys and local-destination values from raw `mari db` reads. Also, the verifier noted a pre-existing gap in the shared workspace path guard: Windows 8.3 short names are not resolved. That affects the read tool too and was not introduced here. - No docs were changed. docs/home/professor-mari.md already says .env and the key file are not available to her. A line saying she cannot change Models, Connections, speech settings or chat text destinations could be added, which would also need the docs-i18n follow-up. - Only the server type-check part of `pnpm check`, prettier on the changed files and the targeted regressions above were run. The full `pnpm check` and the full regression suite were not run. Nothing was pushed and no PR was opened. - The relayed user request to change Otome Hearth's outfit show-off affection from +20 to +5 is outside this hardening step and was not touched in this worktree. It needs its own task in the repository that owns Otome Hearth. ## 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:44 +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#8794
No description provided.