[GH-ISSUE #5647] Import hardening, preview-token transport, and lastMessageAt on createMessageWithSwipe #3128

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

Originally created by @Gunterlie on GitHub (Aug 29, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5647

Originally assigned to: @Gunterlie on GitHub.

Context

CodeRabbit's review of PR #5583 reported six "outside diff range" findings. Two were in that PR's scope and are fixed there. The remaining four are pre-existing on staging and unrelated to the character-identity feature, so they were deliberately left out of that PR.

Findings to address

1. Unbounded import upload size — packages/server/src/routes/import.routes.ts:35

UNBOUNDED_IMPORT_BYTES is Number.MAX_SAFE_INTEGER, and the import endpoints buffer uploads with toBuffer(). Uncontrolled resource consumption (CWE-400). Replace with a finite, configurable limit and enforce a total batch budget before buffering.

2. Unbounded zTXt decompression — packages/server/src/routes/import.routes.ts:243

inflateSync expands attacker-controlled zTXt data from uploaded PNGs before JSON parsing (CWE-409, decompression bomb). Use bounded decompression and return a controlled import error when the limit is exceeded.

3. Preview token sent over cleartext — packages/client/src/components/panels/SettingsPanel.tsx:6853

api.raw uses relative URLs, so the profile-import previewToken travels over plain HTTP when the app is served over HTTP (CWE-319). Require HTTPS for production and reverse-proxy deployments before sending this bearer-like token.

4. createMessageWithSwipe() does not update lastMessageAt — packages/server/src/routes/chats.routes.ts:750

CapabilityPersistenceSession.createMessageWithSwipe() inserts messages without touching chats.lastMessageAt. If the one-time storage.list() backfill runs before this write, /autonomous-candidates can skip a non-empty Roleplay DM with a null timestamp. Update the chat timestamp in the same transaction, matching createMessage.

Notes

  • 1 and 2 are the same file and likely one change.
  • 4 is the only functional bug; 1–3 are hardening.
  • Each needs manual verification; no automated coverage exists for these paths today.
Originally created by @Gunterlie on GitHub (Aug 29, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/5647 Originally assigned to: @Gunterlie on GitHub. ## Context CodeRabbit's review of PR #5583 reported six "outside diff range" findings. Two were in that PR's scope and are fixed there. The remaining four are pre-existing on `staging` and unrelated to the character-identity feature, so they were deliberately left out of that PR. ## Findings to address ### 1. Unbounded import upload size — `packages/server/src/routes/import.routes.ts:35` `UNBOUNDED_IMPORT_BYTES` is `Number.MAX_SAFE_INTEGER`, and the import endpoints buffer uploads with `toBuffer()`. Uncontrolled resource consumption (CWE-400). Replace with a finite, configurable limit and enforce a total batch budget before buffering. ### 2. Unbounded zTXt decompression — `packages/server/src/routes/import.routes.ts:243` `inflateSync` expands attacker-controlled zTXt data from uploaded PNGs before JSON parsing (CWE-409, decompression bomb). Use bounded decompression and return a controlled import error when the limit is exceeded. ### 3. Preview token sent over cleartext — `packages/client/src/components/panels/SettingsPanel.tsx:6853` `api.raw` uses relative URLs, so the profile-import `previewToken` travels over plain HTTP when the app is served over HTTP (CWE-319). Require HTTPS for production and reverse-proxy deployments before sending this bearer-like token. ### 4. `createMessageWithSwipe()` does not update `lastMessageAt` — `packages/server/src/routes/chats.routes.ts:750` `CapabilityPersistenceSession.createMessageWithSwipe()` inserts messages without touching `chats.lastMessageAt`. If the one-time `storage.list()` backfill runs before this write, `/autonomous-candidates` can skip a non-empty Roleplay DM with a null timestamp. Update the chat timestamp in the same transaction, matching `createMessage`. ## Notes - 1 and 2 are the same file and likely one change. - 4 is the only functional bug; 1–3 are hardening. - Each needs manual verification; no automated coverage exists for these paths today.
bsakaguchi 2026-10-21 05:59:50 +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#3128
No description provided.