[PR #7829] [MERGED] feat(chat): load images from other websites on request #7956

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

📋 Pull Request Information

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

Base: staging ← Head: fix/harden-remote-images


📝 Commits (2)

  • 3358124 feat(chat): load images from other websites on request
  • 94b0639 fix(chat): approve a GIF only once it is sent, larger Load image tap target

📊 Changes

22 files changed (+1020 additions, -203 deletions)

View changed files

📝 docs/appearance/card-css-theming.md (+1 -0)
📝 docs/settings/settings-overview.md (+4 -0)
➕ e2e/remote-message-images.e2e.ts (+232 -0)
📝 packages/client/src/components/bot-browser/BotBrowserView.tsx (+6 -3)
📝 packages/client/src/components/chat/ChatMessage.tsx (+27 -4)
📝 packages/client/src/components/chat/ConversationInput.tsx (+2 -0)
📝 packages/client/src/components/chat/ConversationMessageShared.tsx (+19 -16)
📝 packages/client/src/components/panels/SettingsPanel.tsx (+9 -0)
📝 packages/client/src/hooks/use-settings-sync.ts (+11 -0)
📝 packages/client/src/lib/card-css.ts (+41 -151)
📝 packages/client/src/lib/chat-html.ts (+19 -2)
📝 packages/client/src/lib/chat-message-css.ts (+148 -19)
📝 packages/client/src/lib/markdown.tsx (+3 -8)
➕ packages/client/src/lib/remote-image-placeholder.tsx (+53 -0)
➕ packages/client/src/lib/remote-image-policy.ts (+106 -0)
➕ packages/client/src/lib/remote-images.ts (+66 -0)
📝 packages/client/src/lib/settings-registry.ts (+11 -0)
📝 packages/client/src/localization/locales/en.json (+7 -0)
📝 packages/client/src/stores/ui.store.ts (+18 -0)
📝 packages/client/src/styles/globals.css (+73 -0)

...and 2 more files

📄 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

No linked issue. This comes from a pre-release hardening pass of message rendering, following the maintainer's decision to make images from other websites click-to-load.

Why this change

Message content (model replies, greetings, card notes) can include images and CSS that point at any website. Until now the browser fetched those as soon as a message appeared, with nothing for the user to decide. A message could make Marinara contact a site the user never chose to visit, and whatever was in the image address went with it.

Now an image from another website waits behind a small Load image placeholder unless the user loads it or turns on a new setting. Once loaded, it stays loaded: the user is never asked again for that image, on any device.

The same pass tightens the CSS scoping for card creator notes and message styles, so their selectors can only match things inside their own box.

What changed

  • Click-to-load (lib/remote-images.ts, lib/remote-image-policy.ts, lib/remote-image-placeholder.tsx):
    • An image counts as "from another website" when it is http(s) on a different origin than the app. The app's own files (/api/... uploads, gallery, generated images, sprites, avatars), data: and blob: URLs are unaffected.
    • A held image shows the website's name and a Load image button, styled with the chat chrome theme colours. Its rules are !important so message or card CSS cannot hide, resize or relabel it.
    • Clicking loads exactly that image. Only an image that really loads is remembered; a failed load or a non-image shows "Couldn't load. Try again" and is not saved.
  • One shared path for every surface:
    • sanitizeChatHtml holds images in its final pass (HTML messages, swipes, translations, greeting previews, Bot Browser notes). renderContent passes the policy and handles the button click on the message box.
    • The Markdown image renderer (lib/markdown.tsx) uses the same placeholder, so Conversation messages, Professor Mari, the omnibar, Game journal and character library notes follow it too. A message that is just an image link (Conversation) does as well.
    • While the setting is off, CSS url(), image-set() and src() sources on other websites are dropped from inline styles and message <style> blocks.
  • Remembering approvals (ui.store.ts, use-settings-sync.ts): approved image addresses are stored with the synced UI settings (the server-side ui app setting) and in the browser copy, so they apply immediately after a reload and arrive on other devices. Startup sync merges this browser's and the server's approvals instead of letting one side overwrite the other. The list is capped (1000 addresses, 200k characters) to stay well inside the settings size limit.
    • Why the synced UI settings and not message extra: the same card image usually appears in many messages and in previews that have no message (greetings, Bot Browser), and the browser copy lets an approved image render on the first paint without a placeholder flash.
  • Setting: Settings > General > Text Rules > Load images from other websites in messages, off by default and searchable. Turning it on renders everything directly, as before.
  • GIFs: a GIF picked in Conversation is approved when it is sent, so the sender's own GIFs do not ask.
  • CSS scoping (lib/card-css.ts, lib/chat-message-css.ts):
    • Card creator-notes CSS now goes through the same postcss parse-and-walk scoping as message CSS (scopeCssRules), replacing the hand-written block splitter. The tokenizer now treats escaped characters the way browsers do.
    • In card and message CSS, selectors that would match siblings of the scope element (starting with ~, + or ||, or :root ~ …, body:not(…) + …, Exclusive-mode [data-card-css] ~ …) are dropped. Child selectors (> …) stay.
    • Card CSS keeps fonts, animations and conditional at-rules. It no longer keeps nested rules or @property. A block left open at the end is closed the way browsers do.
    • Spaced ! important is stripped like !important.
  • Docs: settings/settings-overview.md (new Text Rules entry) and appearance/card-css-theming.md (nested rules and sibling selectors).
  • Regressions:
    • remote-message-images-security: which addresses count as other websites, approval list limits, CSS sources held with the setting off and kept with it on.
    • chat-message-css-security (extended): leading combinators, escaped quotes in card CSS, card sibling selectors in Chat and Exclusive scope, card at-rules, spaced ! important.
    • Both fail on current staging and pass with this change. pnpm regression:security picks both up.
    • e2e remote-message-images.e2e.ts: sanitizer output with the setting off, approved and on. A roleplay chat with Markdown, HTML and broken images checks that nothing is requested before a click and that a click loads only that image and saves it to the server. It also checks that a failed load is not saved, that re-rendering never shows an approved image's placeholder, and that the image shows right away after a reload and in a second browser context. Turning the setting on shows everything.

Behaviour changes users may notice:

  • Images from other websites in messages, greetings and card previews now show a Load image button until loaded once. This includes GIFs in older Conversation messages. Users who want the old behaviour can turn on the setting.
  • With the setting off, CSS backgrounds and fonts that HTML cards load from other websites do not show.
  • Card CSS that relies on native nesting, @property or sibling selectors at the top of a rule no longer applies.

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

Commands the agent ran on this branch:

  • pnpm check: passed (one existing lint warning in HomeProfessorMariChat.tsx, not touched here).
  • pnpm regression:security: 24/24 in the security group after rerunning multiplayer-control-security, which first timed out at 30 s under machine load and passed alone in 28.6 s. The runtime-integrity, shell-sandbox, extension-ipc, android-local-auth and docker-proxy-auth groups all passed.
  • chat-message-css-security and remote-message-images-security fail against the staging versions of chat-message-css.ts, card-css.ts and remote-images.ts, and pass with this change.
  • Also passed: assigned-issue-sweep, roleplay-streaming, persona-client-contract, open-issues, chat-html-newlines, theme-css-security and janny-character-import.
  • Playwright desktop-chromium with these specs, all passing:
    • remote-message-images.e2e.ts.
    • chat-open-bottom.e2e.ts. Its conversation case failed once on a cold dev server and passed when rerun.
    • The roleplay-commands.e2e.ts cases for inline rolls, in-line illustrations and documents.
    • From core-flows.e2e.ts: "Downloaded cards use Marinara destination and lorebook choices" (Bot Browser notes).
    • From chat-insights.e2e.ts: "chat search, stats and story exports".
  • Mobile projects, WebKit and a container build were not run.

Manual verification notes

  • Manually verify in a Roleplay chat that a reply containing ![x](https://<another site>/image.png) shows the placeholder with that site's name. Check that the browser's network panel shows no request to that site until Load image is clicked.
  • Manually verify that clicking Load image shows the image, and that it still shows after swiping away and back, reloading the page, restarting Marinara and opening the chat on a second device.
  • Manually verify that an HTML card message with remote <img> tags and CSS backgrounds looks right after loading each image, and with the setting on.
  • Manually verify that streaming a reply with an already-approved image never flashes the placeholder.
  • Manually verify that a link to something that is not an image shows "Couldn't load. Try again" and asks again after a reload.
  • Manually verify the placeholder in light and dark mode, with a custom theme, and on a mobile viewport.
  • Manually verify that greeting previews (character drop options, chat settings), Bot Browser notes, Conversation messages, Professor Mari replies and a sent GIF behave as described.
  • Manually verify that the setting is found by searching "images" in the omnibar, and that turning it on shows every image directly.
  • Manually verify that a card with creator-notes CSS in Chat and Exclusive modes still themes its messages as before.

Docs and release impact

  • No docs changes needed
  • Updated docs (README / CONTRIBUTING / android/README) 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)

English docs changed: docs/settings/settings-overview.md and docs/appearance/card-css-theming.md. The release translation sweep covers the language packs.

UI evidence (if applicable)

The placeholder is a dashed, theme-coloured pill: the website's name, then a Load image button. The e2e saves a screenshot of held Markdown and HTML images as held-images.png in its test output.

Summary by CodeRabbit

  • New Features

    • External images in messages, greetings, and card previews are held by default and show the source website with a Load image button. Successfully loaded images are remembered across devices; failed loads can be retried.
    • A Text Rules setting lets you choose whether external images load immediately. Images stored in Marinara are unaffected.
  • Bug Fixes

    • Card and message styling is more tightly scoped, preventing nested rules, sibling selectors, and external CSS images from affecting content outside their intended area.

🔄 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/7829 **Author:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@SpicyMarinara](https://github.com/SpicyMarinara) **Base:** `staging` ← **Head:** `fix/harden-remote-images` --- ### 📝 Commits (2) - [`3358124`](https://github.com/Pasta-Devs/Marinara-Engine/commit/3358124c210d2d7fdd09c5206fafa244eedef056) feat(chat): load images from other websites on request - [`94b0639`](https://github.com/Pasta-Devs/Marinara-Engine/commit/94b0639e7ff78e566be78300aa32cf12a356766c) fix(chat): approve a GIF only once it is sent, larger Load image tap target ### 📊 Changes **22 files changed** (+1020 additions, -203 deletions) <details> <summary>View changed files</summary> 📝 `docs/appearance/card-css-theming.md` (+1 -0) 📝 `docs/settings/settings-overview.md` (+4 -0) ➕ `e2e/remote-message-images.e2e.ts` (+232 -0) 📝 `packages/client/src/components/bot-browser/BotBrowserView.tsx` (+6 -3) 📝 `packages/client/src/components/chat/ChatMessage.tsx` (+27 -4) 📝 `packages/client/src/components/chat/ConversationInput.tsx` (+2 -0) 📝 `packages/client/src/components/chat/ConversationMessageShared.tsx` (+19 -16) 📝 `packages/client/src/components/panels/SettingsPanel.tsx` (+9 -0) 📝 `packages/client/src/hooks/use-settings-sync.ts` (+11 -0) 📝 `packages/client/src/lib/card-css.ts` (+41 -151) 📝 `packages/client/src/lib/chat-html.ts` (+19 -2) 📝 `packages/client/src/lib/chat-message-css.ts` (+148 -19) 📝 `packages/client/src/lib/markdown.tsx` (+3 -8) ➕ `packages/client/src/lib/remote-image-placeholder.tsx` (+53 -0) ➕ `packages/client/src/lib/remote-image-policy.ts` (+106 -0) ➕ `packages/client/src/lib/remote-images.ts` (+66 -0) 📝 `packages/client/src/lib/settings-registry.ts` (+11 -0) 📝 `packages/client/src/localization/locales/en.json` (+7 -0) 📝 `packages/client/src/stores/ui.store.ts` (+18 -0) 📝 `packages/client/src/styles/globals.css` (+73 -0) _...and 2 more files_ </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 No linked issue. This comes from a pre-release hardening pass of message rendering, following the maintainer's decision to make images from other websites click-to-load. ## Why this change Message content (model replies, greetings, card notes) can include images and CSS that point at any website. Until now the browser fetched those as soon as a message appeared, with nothing for the user to decide. A message could make Marinara contact a site the user never chose to visit, and whatever was in the image address went with it. Now an image from another website waits behind a small **Load image** placeholder unless the user loads it or turns on a new setting. Once loaded, it stays loaded: the user is never asked again for that image, on any device. The same pass tightens the CSS scoping for card creator notes and message styles, so their selectors can only match things inside their own box. ## What changed - **Click-to-load (`lib/remote-images.ts`, `lib/remote-image-policy.ts`, `lib/remote-image-placeholder.tsx`):** - An image counts as "from another website" when it is `http(s)` on a different origin than the app. The app's own files (`/api/...` uploads, gallery, generated images, sprites, avatars), `data:` and `blob:` URLs are unaffected. - A held image shows the website's name and a **Load image** button, styled with the chat chrome theme colours. Its rules are `!important` so message or card CSS cannot hide, resize or relabel it. - Clicking loads exactly that image. Only an image that really loads is remembered; a failed load or a non-image shows "Couldn't load. Try again" and is not saved. - **One shared path for every surface:** - `sanitizeChatHtml` holds images in its final pass (HTML messages, swipes, translations, greeting previews, Bot Browser notes). `renderContent` passes the policy and handles the button click on the message box. - The Markdown image renderer (`lib/markdown.tsx`) uses the same placeholder, so Conversation messages, Professor Mari, the omnibar, Game journal and character library notes follow it too. A message that is just an image link (Conversation) does as well. - While the setting is off, CSS `url()`, `image-set()` and `src()` sources on other websites are dropped from inline styles and message `<style>` blocks. - **Remembering approvals (`ui.store.ts`, `use-settings-sync.ts`):** approved image addresses are stored with the synced UI settings (the server-side `ui` app setting) and in the browser copy, so they apply immediately after a reload and arrive on other devices. Startup sync merges this browser's and the server's approvals instead of letting one side overwrite the other. The list is capped (1000 addresses, 200k characters) to stay well inside the settings size limit. - Why the synced UI settings and not message `extra`: the same card image usually appears in many messages and in previews that have no message (greetings, Bot Browser), and the browser copy lets an approved image render on the first paint without a placeholder flash. - **Setting:** **Settings > General > Text Rules > Load images from other websites in messages**, off by default and searchable. Turning it on renders everything directly, as before. - **GIFs:** a GIF picked in Conversation is approved when it is sent, so the sender's own GIFs do not ask. - **CSS scoping (`lib/card-css.ts`, `lib/chat-message-css.ts`):** - Card creator-notes CSS now goes through the same postcss parse-and-walk scoping as message CSS (`scopeCssRules`), replacing the hand-written block splitter. The tokenizer now treats escaped characters the way browsers do. - In card and message CSS, selectors that would match siblings of the scope element (starting with `~`, `+` or `||`, or `:root ~ …`, `body:not(…) + …`, Exclusive-mode `[data-card-css] ~ …`) are dropped. Child selectors (`> …`) stay. - Card CSS keeps fonts, animations and conditional at-rules. It no longer keeps nested rules or `@property`. A block left open at the end is closed the way browsers do. - Spaced `! important` is stripped like `!important`. - **Docs:** `settings/settings-overview.md` (new Text Rules entry) and `appearance/card-css-theming.md` (nested rules and sibling selectors). - **Regressions:** - `remote-message-images-security`: which addresses count as other websites, approval list limits, CSS sources held with the setting off and kept with it on. - `chat-message-css-security` (extended): leading combinators, escaped quotes in card CSS, card sibling selectors in Chat and Exclusive scope, card at-rules, spaced `! important`. - Both fail on current `staging` and pass with this change. `pnpm regression:security` picks both up. - e2e `remote-message-images.e2e.ts`: sanitizer output with the setting off, approved and on. A roleplay chat with Markdown, HTML and broken images checks that nothing is requested before a click and that a click loads only that image and saves it to the server. It also checks that a failed load is not saved, that re-rendering never shows an approved image's placeholder, and that the image shows right away after a reload and in a second browser context. Turning the setting on shows everything. **Behaviour changes users may notice:** - Images from other websites in messages, greetings and card previews now show a **Load image** button until loaded once. This includes GIFs in older Conversation messages. Users who want the old behaviour can turn on the setting. - With the setting off, CSS backgrounds and fonts that HTML cards load from other websites do not show. - Card CSS that relies on native nesting, `@property` or sibling selectors at the top of a rule no longer applies. ## 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` Commands the agent ran on this branch: - `pnpm check`: passed (one existing lint warning in `HomeProfessorMariChat.tsx`, not touched here). - `pnpm regression:security`: 24/24 in the `security` group after rerunning `multiplayer-control-security`, which first timed out at 30 s under machine load and passed alone in 28.6 s. The `runtime-integrity`, `shell-sandbox`, `extension-ipc`, `android-local-auth` and `docker-proxy-auth` groups all passed. - `chat-message-css-security` and `remote-message-images-security` fail against the `staging` versions of `chat-message-css.ts`, `card-css.ts` and `remote-images.ts`, and pass with this change. - Also passed: `assigned-issue-sweep`, `roleplay-streaming`, `persona-client-contract`, `open-issues`, `chat-html-newlines`, `theme-css-security` and `janny-character-import`. - Playwright `desktop-chromium` with these specs, all passing: - `remote-message-images.e2e.ts`. - `chat-open-bottom.e2e.ts`. Its conversation case failed once on a cold dev server and passed when rerun. - The `roleplay-commands.e2e.ts` cases for inline rolls, in-line illustrations and documents. - From `core-flows.e2e.ts`: "Downloaded cards use Marinara destination and lorebook choices" (Bot Browser notes). - From `chat-insights.e2e.ts`: "chat search, stats and story exports". - Mobile projects, WebKit and a container build were not run. ### Manual verification notes - Manually verify in a Roleplay chat that a reply containing `![x](https://<another site>/image.png)` shows the placeholder with that site's name. Check that the browser's network panel shows no request to that site until **Load image** is clicked. - Manually verify that clicking **Load image** shows the image, and that it still shows after swiping away and back, reloading the page, restarting Marinara and opening the chat on a second device. - Manually verify that an HTML card message with remote `<img>` tags and CSS backgrounds looks right after loading each image, and with the setting on. - Manually verify that streaming a reply with an already-approved image never flashes the placeholder. - Manually verify that a link to something that is not an image shows "Couldn't load. Try again" and asks again after a reload. - Manually verify the placeholder in light and dark mode, with a custom theme, and on a mobile viewport. - Manually verify that greeting previews (character drop options, chat settings), Bot Browser notes, Conversation messages, Professor Mari replies and a sent GIF behave as described. - Manually verify that the setting is found by searching "images" in the omnibar, and that turning it on shows every image directly. - Manually verify that a card with creator-notes CSS in Chat and Exclusive modes still themes its messages as before. ## Docs and release impact - [ ] No docs changes needed - [ ] Updated docs (README / CONTRIBUTING / android/README) 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) English docs changed: `docs/settings/settings-overview.md` and `docs/appearance/card-css-theming.md`. The release translation sweep covers the language packs. ## UI evidence (if applicable) The placeholder is a dashed, theme-coloured pill: the website's name, then a **Load image** button. The e2e saves a screenshot of held Markdown and HTML images as `held-images.png` in its test output. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * External images in messages, greetings, and card previews are held by default and show the source website with a **Load image** button. Successfully loaded images are remembered across devices; failed loads can be retried. * A Text Rules setting lets you choose whether external images load immediately. Images stored in Marinara are unaffected. * **Bug Fixes** * Card and message styling is more tightly scoped, preventing nested rules, sibling selectors, and external CSS images from affecting content outside their intended area. <!-- 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:09:09 +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#7956
No description provided.