[GH-ISSUE #3859] [Issue]: Native character import persists invalid cards without schema validation #2087

Closed
opened 2026-10-21 05:45:15 +07:00 by bsakaguchi · 3 comments
Owner

Originally created by @Xelvanis on GitHub (Jul 20, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3859

Originally assigned to: @SpicyMarinara on GitHub.

Summary

Marinara native character imports accept any nested data object and persist it as CharacterData without runtime schema validation. A malformed native envelope can therefore create a durable character row missing required contract fields such as name.

Expected behavior

A file claiming to be a version-1 marinara_character export should have its character payload validated against Marinara's canonical character schema before persistence. Missing optional legacy fields may receive schema defaults, while structurally invalid cards should return a normal import failure and create no row.

Actual behavior

importCharacter() in packages/server/src/services/import/marinara.importer.ts:

  • checks only that the nested character data value is an object;
  • casts and modifies it as Record<string, unknown>;
  • passes it to storage.create(... as any).

createCharactersStorage().create() trusts its TypeScript CharacterData parameter and serializes it directly. TypeScript types do not validate uploaded JSON at runtime, and the any cast suppresses the boundary mismatch.

Steps to reproduce

  1. Create a .marinara.json file containing:
{
  "type": "marinara_character",
  "version": 1,
  "exportedAt": "2026-07-20T00:00:00.000Z",
  "data": {
    "spec": "chara_card_v2",
    "spec_version": "2.0",
    "data": {}
  }
}
  1. Import it as a Marinara native character.
  2. Observe that the import reports success using the fallback name Imported character and creates a character whose stored data lacks the required name field and other canonical fields.

Environment

  • Marinara Engine version: 2.3.3 staging
  • Install type: source
  • OS + version: Environment-independent server code path; verified from a Windows source checkout
  • Browser or app shell: Not live-reproduced end-to-end; confirmed by static import/storage trace

Logs, screenshots, or video

No runtime logs or screenshots. Direct schema proof:

characterDataSchema.safeParse({})
→ failure: name is required

characterDataSchema.safeParse({ name: "Legacy" })
→ success: optional fields receive canonical defaults

Relevant code:

  • packages/server/src/services/import/marinara.importer.ts: unchecked object clone and storage.create(charData as any, ...).
  • packages/server/src/services/storage/characters.storage.ts: direct JSON.stringify(data) insertion.
  • packages/shared/src/schemas/character.schema.ts: canonical characterDataSchema contract.

Additional context

This laxity is not needed for ordinary third-party character-card compatibility. SillyTavern/Chara Card JSON, PNG, and CharX inputs use the separate /api/import/st-character path and its normalizer. /api/import/marinara handles files explicitly claiming Marinara's native envelope type and version.

The character schema is already compatibility-friendly: only name is required, missing optional fields receive defaults, and unknown top-level character and extension properties are preserved with passthrough behavior.

Suggested direction: call characterDataSchema.safeParse() at the native import boundary, return the existing structured Invalid character data result when it fails, and persist the validated/normalized value. Compatibility note: characterBookSchema is not currently passthrough, so persisting parsed.data could strip unknown top-level embedded-lorebook properties. Consider making that schema passthrough or explicitly preserving those properties before adopting normalization.

Related but separate: #3858 covers partial character PATCH requests overwriting nested data.

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 @Xelvanis on GitHub (Jul 20, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/3859 Originally assigned to: @SpicyMarinara on GitHub. ## Summary Marinara native character imports accept any nested `data` object and persist it as `CharacterData` without runtime schema validation. A malformed native envelope can therefore create a durable character row missing required contract fields such as `name`. ## Expected behavior A file claiming to be a version-1 `marinara_character` export should have its character payload validated against Marinara's canonical character schema before persistence. Missing optional legacy fields may receive schema defaults, while structurally invalid cards should return a normal import failure and create no row. ## Actual behavior `importCharacter()` in `packages/server/src/services/import/marinara.importer.ts`: - checks only that the nested character `data` value is an object; - casts and modifies it as `Record<string, unknown>`; - passes it to `storage.create(... as any)`. `createCharactersStorage().create()` trusts its TypeScript `CharacterData` parameter and serializes it directly. TypeScript types do not validate uploaded JSON at runtime, and the `any` cast suppresses the boundary mismatch. ## Steps to reproduce 1. Create a `.marinara.json` file containing: ```json { "type": "marinara_character", "version": 1, "exportedAt": "2026-07-20T00:00:00.000Z", "data": { "spec": "chara_card_v2", "spec_version": "2.0", "data": {} } } ``` 2. Import it as a Marinara native character. 3. Observe that the import reports success using the fallback name `Imported character` and creates a character whose stored data lacks the required `name` field and other canonical fields. ## Environment - Marinara Engine version: 2.3.3 staging - Install type: source - OS + version: Environment-independent server code path; verified from a Windows source checkout - Browser or app shell: Not live-reproduced end-to-end; confirmed by static import/storage trace ## Logs, screenshots, or video No runtime logs or screenshots. Direct schema proof: ```text characterDataSchema.safeParse({}) → failure: name is required characterDataSchema.safeParse({ name: "Legacy" }) → success: optional fields receive canonical defaults ``` Relevant code: - `packages/server/src/services/import/marinara.importer.ts`: unchecked object clone and `storage.create(charData as any, ...)`. - `packages/server/src/services/storage/characters.storage.ts`: direct `JSON.stringify(data)` insertion. - `packages/shared/src/schemas/character.schema.ts`: canonical `characterDataSchema` contract. ## Additional context This laxity is not needed for ordinary third-party character-card compatibility. SillyTavern/Chara Card JSON, PNG, and CharX inputs use the separate `/api/import/st-character` path and its normalizer. `/api/import/marinara` handles files explicitly claiming Marinara's native envelope type and version. The character schema is already compatibility-friendly: only `name` is required, missing optional fields receive defaults, and unknown top-level character and extension properties are preserved with passthrough behavior. Suggested direction: call `characterDataSchema.safeParse()` at the native import boundary, return the existing structured `Invalid character data` result when it fails, and persist the validated/normalized value. Compatibility note: `characterBookSchema` is not currently passthrough, so persisting `parsed.data` could strip unknown top-level embedded-lorebook properties. Consider making that schema passthrough or explicitly preserving those properties before adopting normalization. Related but separate: #3858 covers partial character PATCH requests overwriting nested data. ## 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:45:15 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

SpicyMarinara is taking this issue in the current assigned-issue sweep. I’m tracing the reported boundary, adding focused regression coverage, and will link the draft PR here as soon as the proof commit is pushed.

<!-- gh-comment-id:5022368075 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): SpicyMarinara is taking this issue in the current assigned-issue sweep. I’m tracing the reported boundary, adding focused regression coverage, and will link the draft PR here as soon as the proof commit is pushed.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

Implementation is now tracked in draft PR #3862 against staging.

<!-- gh-comment-id:5022408371 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): Implementation is now tracked in draft PR #3862 against `staging`.
Author
Owner

@SpicyMarinara commented on GitHub (Jul 20, 2026):

Addressed in #3862 and merged to staging as ca6d0c15be.

<!-- gh-comment-id:5022915088 --> @SpicyMarinara commented on GitHub (Jul 20, 2026): Addressed in #3862 and merged to staging as ca6d0c15bee712686203483621028050ed0239a9.
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#2087
No description provided.