mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[GH-ISSUE #2705] [Issue]: Import hardening — avatar magic-byte/CharX validation, unbounded avatar proxies, legacy persona profile field loss #1350
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#1350
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @kolacheee on GitHub (Jun 21, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2705
Originally assigned to: @SpicyMarinara on GitHub.
Summary
A few hardening gaps in the import paths: avatars are written to disk trusting an attacker-controlled data-URL MIME for content and file extension (no magic-byte validation), CharX zip assets are decoded into avatars with no image-content validation, the DataCat/Janny avatar proxies have no response-size cap or content-type check (large-image/decompression memory bomb), and a legacy JSON profile import drops persona
tags/savedStatusOptions/avatarCrop.Expected behavior
Imported images should be validated as actual images (by content, not a self-declared MIME), remote image proxies should bound response size and check content-type, and profile import should preserve persona fields.
Actual behavior
ext = avatarDataUrl.match(/^data:image\/([\w+]+);/)), with no magic-byte check. A card can declaredata:image/png;...while carrying arbitrary bytes, written verbatim under that extension.resolveCharXAsset/ the fallback paths decode zip-entry bytes into adata:image/...URL with an extension/MIME taken from the asset metadata, with no image-content validation.tags,savedStatusOptions, andavatarCrop.How it breaks the pipeline
Code trace (staging @
b826f8f4):packages/server/src/services/import/st-character.importer.ts:220-232(ext from MIME:222, base64 write:229).resolveCharXAsset(st-character.importer.ts:585-610) + fallback (:424-438).bot-browser-datacat.routes.ts/bot-browser-janny.routes.ts) — fetch with no size cap / content-type check.tags/savedStatusOptions/avatarCrop).Steps to reproduce
_avatarDataUrldeclaresimage/pngbut carries non-image bytes → written to disk as a.pngunchecked.Suggested fix
sharpmetadata) and derive the extension from the detected format, not the declared MIME; apply the same to CharX assets.tags/savedStatusOptions/avatarCropon legacy profile import.Environment
b826f8f4)Additional context
Found via a systematic multi-agent audit of import/export round-trips. Low-to-medium severity hardening + a minor persona field loss. Part of a set of import/export fidelity issues filed together.
Template check
Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:
@kolacheee commented on GitHub (Jun 21, 2026):
Two scope clarifications and one fix refinement for actionability:
Avatar-proxy scope — the same unbounded-fetch defect also affects two proxies not listed in this issue: Chartavern (
packages/server/src/routes/bot-browser-chartavern.routes.ts:257-281, rawarrayBuffer()at :272/:275) and Chub (packages/server/src/routes/bot-browser.routes.ts:159-183, rawarrayBuffer()at :175/:178). Both use plainfetchwith only a 15s timeout — no size cap, no content-type check. Any fix should cover all four (DataCat, Janny, Chartavern, Chub). For reference, Pygmalion (bot-browser-pygmalion.routes.ts:254) and Wyvern (bot-browser-wyvern.routes.ts:121) are ALREADY hardened viasafeFetch({ maxResponseBytes: 10*1024*1024, allowedContentTypes: ["image/"] })+isAllowedImageBuffer— replicate that exact pattern (note the established avatar-proxy cap is 10 MB, not the 50 MB LLM cap mentioned in the Suggested fix).Persona field-loss location — the offending path is
packages/server/src/routes/backup.routes.ts:1971-1994(the legacy profile-import fallbackcreatePersonacall; it runs in theelsebranch whenisProfileStorageSnapshot(data.fileStorage)is false at :1887, not the modern snapshot path). Addtags,savedStatusOptions, andavatarCropto thatextraobject —createPersonaalready accepts them (packages/server/src/services/storage/characters.storage.ts:374, fields at :392-394). Do NOT "fix" the other two persona-import paths:ImportPersonaModal.tsx:115-117andmarinara.importer.ts:370-378already map all three correctly.Image-validation fix — prefer the existing synchronous
isAllowedImageBuffer()helper inpackages/server/src/utils/security.ts:82(already used across ~10 image-write paths) over a newsharpcall: decode the base64, reject whenisAllowedImageBuffer(buf)returns null, and derive the file extension from its.ext. Apply the same helper to the CharX asset paths (resolveCharXAsset:607-609 and the fallback :432-434). The st-character importer does not currently import this helper at all.@SpicyMarinara commented on GitHub (Jun 21, 2026):
Fixed on the issue sweep branch. Character-card avatar writes now validate decoded image bytes with isAllowedImageBuffer and derive the stored extension from the detected image type; CharX asset and fallback avatar paths also validate zip bytes before building data URLs. Chub, CharacterTavern, DataCat, and Janny avatar proxies now use safeFetch with a 10 MB cap plus content-type/magic-byte validation before returning images. The legacy backup profile persona fallback now preserves tags, savedStatusOptions, and avatarCrop. Pygmalion/Wyvern and the newer persona import paths were already hardened/mapped, so I left those unchanged. Final pnpm validation is deferred until the full sweep is complete.