[GH-ISSUE #2697] [Issue]: Full backup omits the encryption key (restored API keys become empty) and custom emoji/sticker images #1342

Closed
opened 2026-10-21 05:31:50 +07:00 by bsakaguchi · 1 comment
Owner

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

Originally assigned to: @SpicyMarinara on GitHub.

Summary

The full backup/restore drops two categories of critical files, so a restored backup is silently lossy: (1) it omits DATA_DIR/.encryption-key, so on restore every stored API key becomes undecryptable (blank); (2) it omits the custom-emojis and custom-stickers image directories, so every custom emoji/sticker renders broken after restore even though their DB rows are restored.

Expected behavior

A full (same-user) backup should restore to a working state — all connections keep their API keys, and all custom emoji/sticker images render.

Actual behavior

  1. Encryption key not backed up. The folder backup and download backup copy the DB, RESTORE.txt, a redacted profile, and every BACKUP_DIRS subdir (including storage, which holds apiKeyEncrypted ciphertext) — but never copy DATA_DIR/.encryption-key. On restore to a new machine/wiped data dir, a fresh .encryption-key is auto-generated, so decryptApiKey fails the GCM auth-tag check for every connection and returns "". All keys are silently lost even though the ciphertext was faithfully restored.
  2. Emoji/sticker images not backed up. BACKUP_DIRS/PROFILE_ASSET_DIRS list storage/avatars/sprites/backgrounds/gallery/fonts/knowledge-sources/game-assets/lorebooks-images/agents-images/connections-images — but not custom-emojis or custom-stickers. The custom_emojis/custom_stickers rows export in the storage snapshot, but their image files (under DATA_DIR/custom-emojis/ and custom-stickers/) are never collected, and normalizeProfileAssetPath would reject them even if hand-added. On restore the rows point at files that were never backed up → every :emoji:/sticker: token 404s.

How it breaks the pipeline

Code trace (staging @ b826f8f4):

  • (1) packages/server/src/routes/backup.routes.ts — folder backup (POST /, ~:1631-1658) and download backup (POST /download, ~:1681-1719) copy BACKUP_DIRS (:34-46) but not .encryption-key. Key read/auto-gen at packages/server/src/utils/crypto.ts:34-46; decrypt-fail returns "" at crypto.ts:78-82.
  • (2) BACKUP_DIRS/PROFILE_ASSET_DIRS (backup.routes.ts:34-47) omit custom-emojis/custom-stickers; collectProfileAssetFiles (:488-524) and the cp loops (:1653-1658, :1702-1719) only walk those dirs; normalizeProfileAssetPath (~:419-431) allowlists only PROFILE_ASSET_DIRS. Image files live at custom-emojis.routes.ts:17 / custom-stickers.routes.ts:21.

Steps to reproduce

  1. Keys: configure a connection with an API key → POST /api/backup/download → extract the zip onto a fresh data dir → start the app → a new .encryption-key is generated → the key is blank, chat fails with auth errors.
  2. Emoji/sticker: add a custom emoji (writes DATA_DIR/custom-emojis/<file> + a row) → Profile Export / POST /api/backup/download → restore into a clean install → the row exists but the image 404s.

Suggested fix

  • (1) Include .encryption-key in the full folder + download backups (explicitly copy/add it), with a clear warning in RESTORE.txt that the archive contains secret-key material. Do not add it to the redacting profile export meant for sharing; or document that ENCRYPTION_KEY must be exported separately.
  • (2) Add custom-emojis and custom-stickers to BACKUP_DIRS (so PROFILE_ASSET_DIRS derives them and normalizeProfileAssetPath accepts them); verify the round-trip restores image files alongside rows.

Environment

  • Marinara Engine version: 2.0.0 (staging @ b826f8f4)
  • Install type: source
  • OS + version: All (code-level defect, platform-independent)
  • Browser or app shell: All

Additional context

Found via a systematic multi-agent audit of import/export round-trips for 2.0.0. (1) makes a same-user backup non-restorable for connections; (2) is silent image 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:

  • I DID NOT read this template and provide the requested details.
Originally created by @kolacheee on GitHub (Jun 21, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/2697 Originally assigned to: @SpicyMarinara on GitHub. ## Summary The full backup/restore drops two categories of critical files, so a restored backup is silently lossy: **(1)** it omits `DATA_DIR/.encryption-key`, so on restore every stored API key becomes undecryptable (blank); **(2)** it omits the `custom-emojis` and `custom-stickers` image directories, so every custom emoji/sticker renders broken after restore even though their DB rows are restored. ## Expected behavior A full (same-user) backup should restore to a working state — all connections keep their API keys, and all custom emoji/sticker images render. ## Actual behavior 1. **Encryption key not backed up.** The folder backup and download backup copy the DB, RESTORE.txt, a redacted profile, and every `BACKUP_DIRS` subdir (including `storage`, which holds `apiKeyEncrypted` ciphertext) — but never copy `DATA_DIR/.encryption-key`. On restore to a new machine/wiped data dir, a fresh `.encryption-key` is auto-generated, so `decryptApiKey` fails the GCM auth-tag check for every connection and returns `""`. All keys are silently lost even though the ciphertext was faithfully restored. 2. **Emoji/sticker images not backed up.** `BACKUP_DIRS`/`PROFILE_ASSET_DIRS` list storage/avatars/sprites/backgrounds/gallery/fonts/knowledge-sources/game-assets/lorebooks-images/agents-images/connections-images — but **not** `custom-emojis` or `custom-stickers`. The `custom_emojis`/`custom_stickers` rows export in the storage snapshot, but their image files (under `DATA_DIR/custom-emojis/` and `custom-stickers/`) are never collected, and `normalizeProfileAssetPath` would reject them even if hand-added. On restore the rows point at files that were never backed up → every `:emoji:`/`sticker:` token 404s. ## How it breaks the pipeline Code trace (staging @ `b826f8f4`): - (1) `packages/server/src/routes/backup.routes.ts` — folder backup (POST `/`, ~`:1631-1658`) and download backup (POST `/download`, ~`:1681-1719`) copy `BACKUP_DIRS` (`:34-46`) but not `.encryption-key`. Key read/auto-gen at `packages/server/src/utils/crypto.ts:34-46`; decrypt-fail returns `""` at `crypto.ts:78-82`. - (2) `BACKUP_DIRS`/`PROFILE_ASSET_DIRS` (`backup.routes.ts:34-47`) omit `custom-emojis`/`custom-stickers`; `collectProfileAssetFiles` (~`:488-524`) and the cp loops (~`:1653-1658`, `:1702-1719`) only walk those dirs; `normalizeProfileAssetPath` (~`:419-431`) allowlists only `PROFILE_ASSET_DIRS`. Image files live at `custom-emojis.routes.ts:17` / `custom-stickers.routes.ts:21`. ## Steps to reproduce 1. **Keys:** configure a connection with an API key → `POST /api/backup/download` → extract the zip onto a fresh data dir → start the app → a new `.encryption-key` is generated → the key is blank, chat fails with auth errors. 2. **Emoji/sticker:** add a custom emoji (writes `DATA_DIR/custom-emojis/<file>` + a row) → Profile Export / `POST /api/backup/download` → restore into a clean install → the row exists but the image 404s. ## Suggested fix - (1) Include `.encryption-key` in the full folder + download backups (explicitly copy/add it), with a clear warning in `RESTORE.txt` that the archive contains secret-key material. Do **not** add it to the redacting profile export meant for sharing; or document that `ENCRYPTION_KEY` must be exported separately. - (2) Add `custom-emojis` and `custom-stickers` to `BACKUP_DIRS` (so `PROFILE_ASSET_DIRS` derives them and `normalizeProfileAssetPath` accepts them); verify the round-trip restores image files alongside rows. ## Environment - Marinara Engine version: 2.0.0 (staging @ `b826f8f4`) - Install type: source - OS + version: All (code-level defect, platform-independent) - Browser or app shell: All ## Additional context Found via a systematic multi-agent audit of import/export round-trips for 2.0.0. (1) makes a same-user backup non-restorable for connections; (2) is silent image 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: - [ ] I DID NOT read this template and provide the requested details.
Author
Owner

@SpicyMarinara commented on GitHub (Jun 21, 2026):

Fixed in branch codex/spicy-issue-sweep-2026-06-21.

What changed:

  • Full folder backups copy .encryption-key when the persisted key file exists.
  • Downloadable full backup zips include .encryption-key when present.
  • Restore notes now warn that full backups can contain secret material and that env-provided ENCRYPTION_KEY must be restored separately.
  • Added custom-emojis and custom-stickers to the backup/profile asset allowlist so their image files round-trip with their storage rows.

Final repo checks will run after the full issue sweep.

<!-- gh-comment-id:4761544719 --> @SpicyMarinara commented on GitHub (Jun 21, 2026): Fixed in branch `codex/spicy-issue-sweep-2026-06-21`. What changed: - Full folder backups copy `.encryption-key` when the persisted key file exists. - Downloadable full backup zips include `.encryption-key` when present. - Restore notes now warn that full backups can contain secret material and that env-provided `ENCRYPTION_KEY` must be restored separately. - Added `custom-emojis` and `custom-stickers` to the backup/profile asset allowlist so their image files round-trip with their storage rows. Final repo checks will run after the full issue sweep.
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#1342
No description provided.