[GH-ISSUE #2530] [Issue]: Marinara lorebook importer writes entry role with no allowlist (ST sibling normalizes) #1257

Closed
opened 2026-10-21 05:30:04 +07:00 by bsakaguchi · 0 comments
Owner

Originally created by @Romuromylus on GitHub (Jun 9, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2530

Originally assigned to: @Romuromylus on GitHub.

Summary

Severity: Low — correctness (missing input normalization). The Marinara lorebook importer writes an imported entry's role straight to the DB with no allowlist, while the SillyTavern sibling importer normalizes the same field through resolveRole(). A hand-crafted .marinara.json lorebook can persist an arbitrary string as an entry's prompt-injection role.

Expected behavior

The imported lorebook role should be clamped to the system | user | assistant union, matching the ST importer and the manual entry-create routes.

Actual behavior

packages/server/src/services/import/marinara.importer.ts:458:

role: (e.role as any) ?? "system",   // no allowlist

The storage layer inserts it raw (lorebooks.storage.ts createEntry: role: input.role ?? "system"), with no zod parse on the bulk-import path. By contrast, the ST importer normalizes via resolveRole() (st-lorebook.importer.ts:223-231, applied at :391), and the manual entry-create routes run createLorebookEntrySchema.parse(), which clamps role to z.enum(["system","user","assistant"]) (lorebook.schema.ts:164). The import path is the one call site that skips this. The raw role propagates into a provider PromptMessage role (prompt-injector.ts:117).

Steps to reproduce

  1. Hand-edit a .marinara.json lorebook export so an entry's role is a non-enum string.
  2. Import it.
  3. The out-of-enum role is persisted and later used as injection metadata, where the provider chat API will reject or coerce it.

Environment

  • Marinara Engine version: 1.6.1 (staging @ a9fdae8)
  • Install type: source
  • OS + version: n/a — static source audit
  • Browser or app shell: n/a

Logs, screenshots, or video

Static source audit, cited to file:line above.

Additional context

This is a normalization/data-integrity inconsistency, not a security exploit — role is prompt-injection metadata, not a dangerous sink, and an out-of-enum value is non-standard injection metadata rather than RCE/XSS/SSRF/data-loss. Hence Low.

Fix: reuse the resolveRole() pattern from st-lorebook.importer.ts (or a shared helper) in importLorebook so the imported role is clamped to the union, matching the ST importer. selectiveLogic/position deserve the same treatment if not already validated downstream.

Regression notes: found via static audit; main (65a0395, marinara.importer.ts:447) has the byte-identical unclamped assignment, so this is a long-standing shared bug, not a main→staging regression.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @Romuromylus on GitHub (Jun 9, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2530 Originally assigned to: @Romuromylus on GitHub. ## Summary **Severity: Low — correctness (missing input normalization).** The Marinara lorebook importer writes an imported entry's `role` straight to the DB with no allowlist, while the SillyTavern sibling importer normalizes the same field through `resolveRole()`. A hand-crafted `.marinara.json` lorebook can persist an arbitrary string as an entry's prompt-injection role. ## Expected behavior The imported lorebook `role` should be clamped to the `system | user | assistant` union, matching the ST importer and the manual entry-create routes. ## Actual behavior `packages/server/src/services/import/marinara.importer.ts:458`: ```ts role: (e.role as any) ?? "system", // no allowlist ``` The storage layer inserts it raw (`lorebooks.storage.ts` `createEntry`: `role: input.role ?? "system"`), with no zod parse on the bulk-import path. By contrast, the ST importer normalizes via `resolveRole()` (`st-lorebook.importer.ts:223-231`, applied at `:391`), and the manual entry-create routes run `createLorebookEntrySchema.parse()`, which clamps `role` to `z.enum(["system","user","assistant"])` (`lorebook.schema.ts:164`). The import path is the one call site that skips this. The raw role propagates into a provider `PromptMessage` role (`prompt-injector.ts:117`). ## Steps to reproduce 1. Hand-edit a `.marinara.json` lorebook export so an entry's `role` is a non-enum string. 2. Import it. 3. The out-of-enum role is persisted and later used as injection metadata, where the provider chat API will reject or coerce it. ## Environment - Marinara Engine version: 1.6.1 (`staging @ a9fdae8`) - Install type: source - OS + version: n/a — static source audit - Browser or app shell: n/a ## Logs, screenshots, or video Static source audit, cited to file:line above. ## Additional context This is a normalization/data-integrity inconsistency, not a security exploit — `role` is prompt-injection metadata, not a dangerous sink, and an out-of-enum value is non-standard injection metadata rather than RCE/XSS/SSRF/data-loss. Hence Low. Fix: reuse the `resolveRole()` pattern from `st-lorebook.importer.ts` (or a shared helper) in `importLorebook` so the imported role is clamped to the union, matching the ST importer. `selectiveLogic`/`position` deserve the same treatment if not already validated downstream. Regression notes: found via static audit; `main` (`65a0395`, `marinara.importer.ts:447`) has the byte-identical unclamped assignment, so this is a long-standing shared bug, not a `main`→`staging` regression. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-21 05:30:04 +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#1257
No description provided.