[PR #7346] [MERGED] feat(characters): save greeting web images to the gallery on request #7693

Closed
opened 2026-10-24 04:06:35 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/7346
Author: @SpicyMarinara
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/9/2026
Merged by: @SpicyMarinara

Base: staging ← Head: feat/7221-bake-greeting-images


📝 Commits (8)

  • d5b3a50 feat(characters): save greeting web images to the gallery on request
  • 421ac44 Merge origin/staging into feat/7221-bake-greeting-images
  • a6b3254 fix(characters): keep server paths out of greeting bake errors
  • 378001f fix(characters): declare the bake route's rate limit and build gallery paths from the stored id
  • fb55e4e Merge origin/staging into feat/7221-bake-greeting-images
  • 3138003 fix(characters): restore baked greeting links in compatible profile exports
  • c817bd1 Merge origin/staging into feat/7221-bake-greeting-images
  • 7fae8dd Move the CHANGELOG entry away from other open PRs

📊 Changes

17 files changed (+705 additions, -12 deletions)

View changed files

📝 CHANGELOG.md (+1 -0)
📝 docs/characters/creating-and-editing-characters.md (+2 -0)
📝 docs/characters/galleries.md (+8 -0)
📝 packages/client/src/components/characters/CharacterEditor.tsx (+100 -3)
📝 packages/client/src/components/characters/CharacterLibraryView.tsx (+5 -1)
📝 packages/client/src/components/chat/ChatMessage.tsx (+4 -4)
📝 packages/client/src/hooks/use-characters.ts (+30 -0)
📝 packages/client/src/lib/card-asset-links.ts (+13 -0)
📝 packages/client/src/localization/locales/en.json (+10 -0)
📝 packages/server/src/middleware/rate-limit.ts (+14 -0)
📝 packages/server/src/routes/backup.routes.ts (+4 -1)
📝 packages/server/src/routes/characters.routes.ts (+57 -0)
➕ packages/server/src/services/image/greeting-image-bake.ts (+60 -0)
📝 packages/server/src/utils/security.ts (+6 -3)
📝 packages/shared/src/index.ts (+1 -0)
➕ packages/shared/src/utils/greeting-image-bake.ts (+122 -0)
➕ scripts/regressions/greeting-image-bake.regression.ts (+268 -0)

📄 Description

Important

Contributions target staging. Only SpicyMarinara may promote this repository's staging branch or a same-repository hotfix/* branch to main.
Outside and first-time contributors also require an approving review from SpicyMarinara.

Linked issue

Closes #7221

Why this change

  • Many character cards show images hosted on other websites in their greetings (first message and alternate greetings). Those links break when the host deletes the file, change when the host replaces it, and fail offline. Users asked for an explicit way to keep a local copy ("bake" the images) instead of depending on the remote link.
  • The download has to be safe: it fetches URLs that came from downloaded cards, so it must not reach the user's own machine or network, must not accept non-images, and must only happen when the user asks.

What changed

  • Character Editor → Dialogue & Greetings: when the greetings show web images (markdown ![](https://…) or HTML <img src="https://…">), a Save images locally button appears. It downloads them into the character's Gallery and rewrites each reference to the portable card://self/gallery/<file> form, recording the original link in extensions.bakedGreetingImages. The form becomes dirty; the user saves as usual. Restore web links puts the original links back. Nothing is fetched automatically.
  • Server POST /api/characters/:id/gallery/bake (same plugin and auth as the other character gallery routes; own rate-limit bucket of 20/min; at most 10 URLs per request, the client batches): downloads through the existing safeFetch guard — http/https only, every redirect hop re-validated (max 3), the checked DNS answer pinned for the connection, private/loopback/link-local/CGNAT/ULA/mapped/reserved addresses refused, no cookies or auth forwarded, 15 s timeout, 10 MB response cap. Only PNG/JPEG/GIF/WebP by magic bytes are kept (SVG, HTML and AVIF rejected), with a 40-megapixel cap. Files get app-generated names (<nanoid>.<ext>) in the character's gallery folder and a gallery row, so character delete and native export already handle them.
  • Export: native .marinara.json exports carry the gallery with filenames, so the card://self refs survive import. Compatible JSON / PNG cards carry no gallery, so buildCompatibleCharacterExport now restores the original web links for baked images.
  • Chat renderer: <img src="card://…"> in HTML greetings/messages now resolves before DOMPurify drops the unknown card: scheme (markdown images already did).
  • Shared outbound guard (safeFetch): the built-in private ranges stay blocked when TRUSTED_PRIVATE_NETWORKS narrows the sign-in trust list (before, e.g. TRUSTED_PRIVATE_NETWORKS=192.168.1.0/24 let outbound fetches reach 10.x and 169.254.169.254), and IPv6 multicast (ff00::/8) and IPv4-compatible (::/96, e.g. ::7f00:1) addresses are refused. This only blocks more; callers that need local hosts keep their explicit allowLocal flags.
  • Docs: docs/characters/galleries.md (new "Save web images from greetings" subsection) and a pointer in docs/characters/creating-and-editing-characters.md. Translations tracked in #7345.
  • Lorebook image baking is out of scope for this PR.

Validation

  • pnpm check passes locally
  • Container (Docker / Podman) built and ran without issue
  • Ran the app, clicked through the changes manually
  • Checked edge cases (light + dark mode, mobile viewport, empty states, error paths)
  • Above manual verification completed (describe below)
  • Read and followed CONTRIBUTING.md

Manual verification notes

  • Manually verify that a character whose First Message has ![x](https://<some public host>/image.png) shows Save images locally under Dialogue & Greetings, and that a character without web images shows no button.
  • Manually verify that pressing it shows "Saving images…", then a success toast; the First Message now reads card://self/gallery/<id>.png, the image appears in the Gallery tab, and the greeting preview and a new chat's greeting still show the image after saving the character.
  • Manually verify an HTML greeting (<img width="300" src="https://…">) keeps its attributes after baking and renders in a new chat.
  • Manually verify a failing link (404 host, an .svg image, http://127.0.0.1/…) leaves that link unchanged and shows an error toast with the reason.
  • Manually verify Restore web links puts the original URLs back and the button disappears after saving.
  • Manually verify a compatible JSON or PNG export of a baked character contains the original web links, and a native export → import keeps the baked images working.
  • Manually verify the buttons wrap correctly at mobile width and look right in light and dark mode.

Agent-run checks: pnpm check (via the shared slot limiter) passed; node ./scripts/run-regressions.mjs --filter scripts/regressions/greeting-image-bake passed (shared helpers, image validation, network guard incl. TRUSTED_PRIVATE_NETWORKS narrowing, redirect to loopback, route with a stubbed public host, 10-URL cap, 404, compatible export, HTML card:// resolution, hostile-input regex timing); confirmed the new regression fails against the unhardened security.ts. Also re-ran the existing image-result-url-security, provider-compat, extension-security, swarmui-video-origin, opencode-session, open-issues, code-scanning-content-parsing, all *security*, request-timeouts, docker-proxy-auth, capability-package-cache, experience-*, best-effort, decision-local-models, sidecar-local-gguf, logging-failure-lines and mari-edit-flow-revert regressions: all passed. pnpm localization:check passed. Local CodeRabbit (committed changes against staging) reported 1 finding: per-URL errors could echo filesystem/storage error messages (server paths) to the client. Fixed in a6b32546a: storage failures now return a plain message and only download errors reach the client; pnpm check re-run and passed afterwards. No browser click-through was done.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed
  • Translated docs on the docs-i18n branch updated to match, or a [docs-i18n] follow-up issue opened (see CONTRIBUTING.md § Translated documentation)
  • Version/release files updated (only if this PR includes a version bump)

CHANGELOG [Unreleased] entry added; English docs updated; translation follow-up: #7345.

UI evidence (if applicable)

Not captured by the agent.

Summary by CodeRabbit

  • New Features
    • Save supported greeting images from websites to a character’s Gallery, then restore their original web links if needed. Downloads happen only when requested.
    • Compatible JSON and PNG exports retain the original web links. Lorebook images are not included.
  • Security
    • Images must meet size and format limits. Links to local computers and home networks are refused; images that cannot be saved retain their web links.
  • Documentation
    • Added instructions for saving greeting images locally and managing them in the Gallery.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Pasta-Devs/Marinara-Engine/pull/7346 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `feat/7221-bake-greeting-images` --- ### 📝 Commits (8) - [`d5b3a50`](https://github.com/Pasta-Devs/Marinara-Engine/commit/d5b3a50a73947a05ef765c45d5bdc9886e0b633d) feat(characters): save greeting web images to the gallery on request - [`421ac44`](https://github.com/Pasta-Devs/Marinara-Engine/commit/421ac44fd52185946d12e2a27a6d34cf4182ab03) Merge origin/staging into feat/7221-bake-greeting-images - [`a6b3254`](https://github.com/Pasta-Devs/Marinara-Engine/commit/a6b32546a5074145606c321517f4c9127497e42f) fix(characters): keep server paths out of greeting bake errors - [`378001f`](https://github.com/Pasta-Devs/Marinara-Engine/commit/378001ff1843f22a2343489fe7e91c4469fcd1a4) fix(characters): declare the bake route's rate limit and build gallery paths from the stored id - [`fb55e4e`](https://github.com/Pasta-Devs/Marinara-Engine/commit/fb55e4e8f06f53e0a17af8797368c6628fd70aa8) Merge origin/staging into feat/7221-bake-greeting-images - [`3138003`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3138003dc16beedd868c53c97502122ee9f3954d) fix(characters): restore baked greeting links in compatible profile exports - [`c817bd1`](https://github.com/Pasta-Devs/Marinara-Engine/commit/c817bd1941f9cf72817c78bd25017dce619c88fc) Merge origin/staging into feat/7221-bake-greeting-images - [`7fae8dd`](https://github.com/Pasta-Devs/Marinara-Engine/commit/7fae8dd7b607fa45774ce637d24c6c21e5b9f580) Move the CHANGELOG entry away from other open PRs ### 📊 Changes **17 files changed** (+705 additions, -12 deletions) <details> <summary>View changed files</summary> 📝 `CHANGELOG.md` (+1 -0) 📝 `docs/characters/creating-and-editing-characters.md` (+2 -0) 📝 `docs/characters/galleries.md` (+8 -0) 📝 `packages/client/src/components/characters/CharacterEditor.tsx` (+100 -3) 📝 `packages/client/src/components/characters/CharacterLibraryView.tsx` (+5 -1) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+4 -4) 📝 `packages/client/src/hooks/use-characters.ts` (+30 -0) 📝 `packages/client/src/lib/card-asset-links.ts` (+13 -0) 📝 `packages/client/src/localization/locales/en.json` (+10 -0) 📝 `packages/server/src/middleware/rate-limit.ts` (+14 -0) 📝 `packages/server/src/routes/backup.routes.ts` (+4 -1) 📝 `packages/server/src/routes/characters.routes.ts` (+57 -0) ➕ `packages/server/src/services/image/greeting-image-bake.ts` (+60 -0) 📝 `packages/server/src/utils/security.ts` (+6 -3) 📝 `packages/shared/src/index.ts` (+1 -0) ➕ `packages/shared/src/utils/greeting-image-bake.ts` (+122 -0) ➕ `scripts/regressions/greeting-image-bake.regression.ts` (+268 -0) </details> ### 📄 Description > [!IMPORTANT] > Contributions target `staging`. Only `SpicyMarinara` may promote this repository's `staging` branch or a same-repository `hotfix/*` branch to `main`. > Outside and first-time contributors also require an approving review from `SpicyMarinara`. <!-- See CONTRIBUTING.md § Branches. --> ## Linked issue Closes #7221 ## Why this change - Many character cards show images hosted on other websites in their greetings (first message and alternate greetings). Those links break when the host deletes the file, change when the host replaces it, and fail offline. Users asked for an explicit way to keep a local copy ("bake" the images) instead of depending on the remote link. - The download has to be safe: it fetches URLs that came from downloaded cards, so it must not reach the user's own machine or network, must not accept non-images, and must only happen when the user asks. ## What changed - **Character Editor → Dialogue & Greetings**: when the greetings show web images (markdown `![](https://…)` or HTML `<img src="https://…">`), a **Save images locally** button appears. It downloads them into the character's Gallery and rewrites each reference to the portable `card://self/gallery/<file>` form, recording the original link in `extensions.bakedGreetingImages`. The form becomes dirty; the user saves as usual. **Restore web links** puts the original links back. Nothing is fetched automatically. - **Server** `POST /api/characters/:id/gallery/bake` (same plugin and auth as the other character gallery routes; own rate-limit bucket of 20/min; at most 10 URLs per request, the client batches): downloads through the existing `safeFetch` guard — http/https only, every redirect hop re-validated (max 3), the checked DNS answer pinned for the connection, private/loopback/link-local/CGNAT/ULA/mapped/reserved addresses refused, no cookies or auth forwarded, 15 s timeout, 10 MB response cap. Only PNG/JPEG/GIF/WebP by magic bytes are kept (SVG, HTML and AVIF rejected), with a 40-megapixel cap. Files get app-generated names (`<nanoid>.<ext>`) in the character's gallery folder and a gallery row, so character delete and native export already handle them. - **Export**: native `.marinara.json` exports carry the gallery with filenames, so the `card://self` refs survive import. Compatible JSON / PNG cards carry no gallery, so `buildCompatibleCharacterExport` now restores the original web links for baked images. - **Chat renderer**: `<img src="card://…">` in HTML greetings/messages now resolves before DOMPurify drops the unknown `card:` scheme (markdown images already did). - **Shared outbound guard (`safeFetch`)**: the built-in private ranges stay blocked when `TRUSTED_PRIVATE_NETWORKS` narrows the sign-in trust list (before, e.g. `TRUSTED_PRIVATE_NETWORKS=192.168.1.0/24` let outbound fetches reach `10.x` and `169.254.169.254`), and IPv6 multicast (`ff00::/8`) and IPv4-compatible (`::/96`, e.g. `::7f00:1`) addresses are refused. This only blocks more; callers that need local hosts keep their explicit `allowLocal` flags. - Docs: `docs/characters/galleries.md` (new "Save web images from greetings" subsection) and a pointer in `docs/characters/creating-and-editing-characters.md`. Translations tracked in #7345. - Lorebook image baking is out of scope for this PR. ## Validation - [ ] `pnpm check` passes locally - [ ] Container (Docker / Podman) built and ran without issue - [ ] Ran the app, clicked through the changes manually - [ ] Checked edge cases (light + dark mode, mobile viewport, empty states, error paths) - [ ] Above manual verification completed (describe below) - [ ] Read and followed `CONTRIBUTING.md` ### Manual verification notes - Manually verify that a character whose First Message has `![x](https://<some public host>/image.png)` shows **Save images locally** under Dialogue & Greetings, and that a character without web images shows no button. - Manually verify that pressing it shows "Saving images…", then a success toast; the First Message now reads `card://self/gallery/<id>.png`, the image appears in the Gallery tab, and the greeting preview and a new chat's greeting still show the image after saving the character. - Manually verify an HTML greeting (`<img width="300" src="https://…">`) keeps its attributes after baking and renders in a new chat. - Manually verify a failing link (404 host, an `.svg` image, `http://127.0.0.1/…`) leaves that link unchanged and shows an error toast with the reason. - Manually verify **Restore web links** puts the original URLs back and the button disappears after saving. - Manually verify a compatible JSON or PNG export of a baked character contains the original web links, and a native export → import keeps the baked images working. - Manually verify the buttons wrap correctly at mobile width and look right in light and dark mode. Agent-run checks: `pnpm check` (via the shared slot limiter) passed; `node ./scripts/run-regressions.mjs --filter scripts/regressions/greeting-image-bake` passed (shared helpers, image validation, network guard incl. `TRUSTED_PRIVATE_NETWORKS` narrowing, redirect to loopback, route with a stubbed public host, 10-URL cap, 404, compatible export, HTML `card://` resolution, hostile-input regex timing); confirmed the new regression fails against the unhardened `security.ts`. Also re-ran the existing `image-result-url-security`, `provider-compat`, `extension-security`, `swarmui-video-origin`, `opencode-session`, `open-issues`, `code-scanning-content-parsing`, all `*security*`, `request-timeouts`, `docker-proxy-auth`, `capability-package-cache`, `experience-*`, `best-effort`, `decision-local-models`, `sidecar-local-gguf`, `logging-failure-lines` and `mari-edit-flow-revert` regressions: all passed. `pnpm localization:check` passed. Local CodeRabbit (committed changes against staging) reported 1 finding: per-URL errors could echo filesystem/storage error messages (server paths) to the client. Fixed in a6b32546a: storage failures now return a plain message and only download errors reach the client; `pnpm check` re-run and passed afterwards. No browser click-through was done. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README / CHANGELOG) as needed - [ ] Translated docs on the `docs-i18n` branch updated to match, or a `[docs-i18n]` follow-up issue opened (see CONTRIBUTING.md § Translated documentation) - [ ] Version/release files updated (only if this PR includes a version bump) CHANGELOG `[Unreleased]` entry added; English docs updated; translation follow-up: #7345. ## UI evidence (if applicable) Not captured by the agent. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Save supported greeting images from websites to a character’s Gallery, then restore their original web links if needed. Downloads happen only when requested. * Compatible JSON and PNG exports retain the original web links. Lorebook images are not included. * **Security** * Images must meet size and format limits. Links to local computers and home networks are refused; images that cannot be saved retain their web links. * **Documentation** * Added instructions for saving greeting images locally and managing them in the Gallery. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-24 04:06:35 +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#7693
No description provided.