[GH-ISSUE #2173] [Issue]: Persona import paths accept unverified image bytes #1085

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

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

Originally assigned to: @Promansis on GitHub.

Summary

Several persona import/upload paths accept decoded image payloads or copied image files based on base64/extension alone instead of validating image bytes. Legacy native import and persona avatar upload used isAllowedImageBuffer to reject unsupported or invalid image content.

Expected behavior

Persona import/upload paths should reject invalid image payloads and skip malformed optional avatar/sprite entries without corrupting storage. Decoded bytes should be validated against allowed image signatures/MIME before writing managed avatar or sprite files.

Actual behavior

Refactor helpers such as decode_image_payload, decode_image_value, restore_persona_sprites, and persist_image_file_copy decode base64 or copy files without proving that the bytes are a valid supported image. This can preserve or write non-image bytes under image extensions during persona native import, sprite import/upload, or SillyTavern persona avatar import.

Steps to reproduce

  1. On refactor at 7d4f39f4, inspect src-tauri/src/commands/storage/media_uploads.rs, src-tauri/src/commands/storage/sprites.rs, and src-tauri/src/commands/storage/imports/marinara_assets.rs.
  2. Compare legacy main at 77a30fa4, where native import and persona avatar upload call isAllowedImageBuffer before accepting image bytes.
  3. Try importing or uploading a data URL with an allowed image/png header but base64 payload that is not a valid PNG.

Impact area

  • App shell, navigation, startup, or providers
  • Catalog resources
  • Chat mode
  • Roleplay mode
  • Game mode
  • Shared mode UI
  • Runtime systems: generation, world-state, visuals, tracker, or haptics
  • Professor Mari or shell tools
  • React-free engine behavior, contracts, agents, or capability ports
  • Shared API wrapper or remote runtime routing
  • Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime
  • Docs, contributor workflow, or templates

Environment

  • Branch or commit: refactor 7d4f39f4; legacy comparison main 77a30fa4
  • Run mode: Tauri desktop / remote runtime image import paths may both be affected
  • OS + version: not checked
  • Node + pnpm versions: not checked
  • Rust version, if relevant: not checked
  • Remote Runtime URL configured? not relevant to static trace
  • Provider, model, or integration, if relevant: not relevant

Logs, screenshots, or video

Static trace evidence:

  • Refactor: src-tauri/src/commands/storage/media_uploads.rs:214 decodes image payloads but does not verify image magic bytes.
  • Refactor: src-tauri/src/commands/storage/media_uploads.rs:43 copies image files to managed storage based on filename/extension.
  • Refactor: src-tauri/src/commands/storage/sprites.rs:1599 decodes sprite image data without image-byte validation; upload paths call it at :362 and :403.
  • Refactor: src-tauri/src/commands/storage/imports/marinara_assets.rs:86 restores imported persona sprites through decoded bytes without magic-byte validation.
  • Legacy: packages/server/src/services/import/marinara.importer.ts:21/:38 validate data URLs with isAllowedImageBuffer; legacy persona avatar upload also validates at packages/server/src/routes/characters.routes.ts:771.

Focused check run during parityscan: cargo test --manifest-path src-tauri/Cargo.toml persona passed 16 tests, but no invalid-image negative row covered this gap.

Regression notes

This is a parity gap against legacy image-import validation for native persona import and persona avatar upload. Refactor has path and base64 checks, but not equivalent content validation on these paths.

Additional context

Found while refreshing issue #2133 row 06-PER-ERROR-import-asset-validation. Related scan also touched 06-PER-COMPAT-native-import-avatar-sprites.

Template check

Please uncheck 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 @Promansis on GitHub (Jun 4, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2173 Originally assigned to: @Promansis on GitHub. ## Summary Several persona import/upload paths accept decoded image payloads or copied image files based on base64/extension alone instead of validating image bytes. Legacy native import and persona avatar upload used `isAllowedImageBuffer` to reject unsupported or invalid image content. ## Expected behavior Persona import/upload paths should reject invalid image payloads and skip malformed optional avatar/sprite entries without corrupting storage. Decoded bytes should be validated against allowed image signatures/MIME before writing managed avatar or sprite files. ## Actual behavior Refactor helpers such as `decode_image_payload`, `decode_image_value`, `restore_persona_sprites`, and `persist_image_file_copy` decode base64 or copy files without proving that the bytes are a valid supported image. This can preserve or write non-image bytes under image extensions during persona native import, sprite import/upload, or SillyTavern persona avatar import. ## Steps to reproduce 1. On `refactor` at `7d4f39f4`, inspect `src-tauri/src/commands/storage/media_uploads.rs`, `src-tauri/src/commands/storage/sprites.rs`, and `src-tauri/src/commands/storage/imports/marinara_assets.rs`. 2. Compare legacy `main` at `77a30fa4`, where native import and persona avatar upload call `isAllowedImageBuffer` before accepting image bytes. 3. Try importing or uploading a data URL with an allowed `image/png` header but base64 payload that is not a valid PNG. ## Impact area - [ ] App shell, navigation, startup, or providers - [x] Catalog resources - [ ] Chat mode - [ ] Roleplay mode - [ ] Game mode - [ ] Shared mode UI - [ ] Runtime systems: generation, world-state, visuals, tracker, or haptics - [ ] Professor Mari or shell tools - [ ] React-free engine behavior, contracts, agents, or capability ports - [ ] Shared API wrapper or remote runtime routing - [x] Tauri/Rust storage, assets, LLM, integrations, security, imports, or HTTP runtime - [ ] Docs, contributor workflow, or templates ## Environment - Branch or commit: `refactor` `7d4f39f4`; legacy comparison `main` `77a30fa4` - Run mode: Tauri desktop / remote runtime image import paths may both be affected - OS + version: not checked - Node + pnpm versions: not checked - Rust version, if relevant: not checked - Remote Runtime URL configured? not relevant to static trace - Provider, model, or integration, if relevant: not relevant ## Logs, screenshots, or video Static trace evidence: - Refactor: `src-tauri/src/commands/storage/media_uploads.rs:214` decodes image payloads but does not verify image magic bytes. - Refactor: `src-tauri/src/commands/storage/media_uploads.rs:43` copies image files to managed storage based on filename/extension. - Refactor: `src-tauri/src/commands/storage/sprites.rs:1599` decodes sprite image data without image-byte validation; upload paths call it at `:362` and `:403`. - Refactor: `src-tauri/src/commands/storage/imports/marinara_assets.rs:86` restores imported persona sprites through decoded bytes without magic-byte validation. - Legacy: `packages/server/src/services/import/marinara.importer.ts:21`/`:38` validate data URLs with `isAllowedImageBuffer`; legacy persona avatar upload also validates at `packages/server/src/routes/characters.routes.ts:771`. Focused check run during parityscan: `cargo test --manifest-path src-tauri/Cargo.toml persona` passed 16 tests, but no invalid-image negative row covered this gap. ## Regression notes This is a parity gap against legacy image-import validation for native persona import and persona avatar upload. Refactor has path and base64 checks, but not equivalent content validation on these paths. ## Additional context Found while refreshing issue #2133 row `06-PER-ERROR-import-asset-validation`. Related scan also touched `06-PER-COMPAT-native-import-avatar-sprites`. ## Template check Please uncheck 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:26:29 +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#1085
No description provided.