Skip to content

Load a remote image from an AI chat reply only when the person asks for it - #4277

Merged
mstomar125 merged 2 commits into
mainfrom
issue-3928-image-click
Nov 16, 2026
Merged

mstomar125 merged 2 commits into
mainfrom
issue-3928-image-click

Conversation

@mstomar125

@mstomar125 mstomar125 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What

A reply in an AI chat that contains an image with an http(s) address now shows a placeholder: the alt text, the host and the full address as plain text, and a Load image button. Nothing is requested before the press. A press loads that one image only. This is option 2 of the issue, decided on 2026-11-16.

Design, and why it needs no policy change

Remote images cannot load in the webview at all: the content security policy has img-src 'self' asset: https://asset.localhost data: and connect-src 'self' ipc: …, and the chat sanitiser drops every network source. Loosening img-src would let any markup in a message fetch (a tracking pixel needing no click), so it is not done.

Instead the one image the person asked for is fetched by the app process:

  1. renderChatImage (marked image renderer) writes an http(s) image as <span class="ns-remote-image-placeholder" data-image-url=… data-alt=…>. Every other address is not a remote image: an inline data:image/* keeps marked's own renderer (the sanitiser still filters it); file:, javascript:, protocol-relative, relative and SVG-data addresses become their alt text only.
  2. chat-markdown.svelte mounts RemoteImagePlaceholder on that span after sanitising (the same mechanism as node cards). No {@html}.
  3. The button calls the new Tauri command fetch_remote_image(url). It returns { mime, data_base64 }, shown as data:<mime>;base64,…, which img-src already allows.

No change to tauri.conf.json, to capabilities (custom commands are not gated by a manifest here), or to the sanitiser. New dependencies in the app crate: base64 = 0.22 and url (already in the workspace, already in the lock); reqwest was already there.

What the command does with a hostile address (app-lib/src/commands/remote_image.rs)

Attack by a reply Mitigation
Tracking pixel or IP leak with no user action Nothing is requested before a press. The placeholder says in one sentence that loading sends the full address, query string included, to that host, which also sees the IP address. The press is the consent.
Data smuggled out in the URL query The full address is shown as text before the press. Only the explicit press sends it.
SSRF to the machine or LAN (127.0.0.1, 10/8, 192.168/16, 169.254.169.254 metadata, localhost, decimal/hex IP forms) The host is resolved and every returned address must be public. Refused ranges: unspecified, loopback, private, link-local, carrier-grade NAT, IETF protocol, benchmarking, documentation, multicast, broadcast, reserved, 6to4 relay anycast (192.88.99.0/24); IPv6 loopback, unique-local, link-local, site-local, documentation, multicast, discard (100::/64), the IETF protocol block 2001::/23 (Teredo and others), the NAT64 prefix outside the well-known /96 (local-use 64:ff9b:1::/48 included), and the forms that carry an IPv4 address (::ffff:a.b.c.d, ::a.b.c.d, NAT64 /96, 6to4).
DNS rebinding between check and connect The connection is pinned to the checked addresses (resolve_to_addrs). Tested: a name that exists in no resolver is reached only through the pin, a second lookup that would answer differently is never made, and each redirect hop is looked up and pinned again; removing the pin fails those tests.
A hostile name server that never answers The whole load, every lookup and every hop included, runs under one 15 s deadline. Tested for a first lookup that stalls and for a later hop's lookup that stalls.
Redirect into the local network Redirects are followed by hand, at most 3, and each hop goes through the same address-shape and address checks. No proxy is used, because a proxy resolves names itself and would sidestep the check.
http:, file:, ftp:, credentials in the address, odd ports https only, no userinfo, default port only, 2048 bytes at most. Also enforced on every redirect hop.
Credentials or cookies sent along No cookie store, no authentication, no referrer, no origin; fixed user agent. Tested by reading the raw request.
Huge or slow response 5 MiB cap (announced size refused early, streamed size cut off), 5 s connect and 15 s total timeouts.
SVG or HTML disguised as an image (script) Declared type must be PNG, JPEG, GIF or WebP (never SVG), and the first bytes must match the declared type. Checked again in the frontend before a data: URL is built (type allow-list and base64 character set).
Using the error message to probe the network A refusal is returned as one of eight short codes, never the underlying error; unknown failures become network.
Raw HTML <img src=https://…> in a reply Still dropped by the sanitiser, no placeholder.
A forged placeholder span written as raw HTML Becomes the same click-gated placeholder as a markdown image; an http address gets no button. mount() keeps what is already in its target, so the span is emptied before the card is mounted; text the reply put inside it cannot sit beside the card (tested). The node-card placeholder has the same pattern and is not changed here.

What remains true, for the reviewer to weigh

  • The press does contact a third party (that is the feature). Loading from a host the person does not trust is their call, made with the address in front of them.
  • The webview decodes the bytes as an image. The type allow-list, the signature check and the size cap bound that, but a decoder bug in the platform webview is outside this change.
  • No proxy is used, so on a network that only reaches the internet through a proxy the load fails with "could not be reached". This is deliberate (see the proxy row); say so if you want it relaxed.
  • A reply that is still streaming can re-render its last block; a loaded image in that block then shows as a placeholder again and needs another press. Nothing is cached.
  • Any script in the webview could call fetch_remote_image over IPC. The policy (script-src 'self', no {@html}) is what keeps hostile content from running script; the command's own checks are what limit what such a call could reach (public https images only, no body returned unless it is an image).

Tests

  • Rust: 20 tests in remote_image (address classification incl. range edges and IPv6 carriers, address shape, redirect vetting, a local HTTP test server for the fetch itself: success, each allowed format, svg/html/mislabelled refused, error status, size cap announced and streamed, redirect followed and chain limit, redirects to file:/ftp:/credentials refused with no second request, no credentials/cookies/referrer on the wire). 15 mutations (address check, signature check, redirect re-vetting, size cap, CGNAT range, IPv6-carried IPv4, scheme rule, userinfo rule, the DNS pin, the total deadline, the NAT64 prefix rule, 2001::/23, 100::/64, 192.88.99.0/24, per-hop lookup) each fail a test. The NAT64 prefix mutation first survived because the test addresses embedded a refused IPv4; addresses embedding a public IPv4 were added.
  • Frontend (Happy-DOM): renderer output, service (one invoke per load, codes, payload validation), placeholder component (no invoke and no fetch and no <img> before the click, one load per press for one address, failure sentence and retry, http gets no button, several placeholders are independent), ChatMarkdown end to end. Real Chromium: the renderer plus the real sanitiser (placeholder survives with exactly three attributes, no img/src, raw <img> still dropped, script removed). Mutations of auto-load, <img> output, unescaped address, payload validation, the disabled button, the https rule, the emptying of a forged span and the note's sentence each fail a test.
  • bun run test:changed passes (frontend, scripts, browser, types, shape, Rust nextest); clippy -D warnings and fmt are clean on the app crate.

Docs (not edited here)

  • architecture/security-posture.md, threat T8: add that a remote image in a chat reply loads only after an explicit click, through a command in the app process that accepts only public https addresses and returns only PNG, JPEG, GIF or WebP.
  • architecture/acp-integration.md, the markdown-rendering paragraph: images in chat replies are placeholders until clicked.

Refs #3928

🤖 Generated with Claude Code

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (head 800ca45). No blocking finding. Read-only review: I read the full diff and the Rust module, the renderer, service, component and the central placeholder tests. I did not run any tests or mutations.

What I attacked and found sound

  • Pin is real: build_client calls resolve_to_addrs(name, addrs) with the checked set; reqwest keeps the original hostname for SNI, Host and certificate validation. A new client is built per hop, so each redirect is re-resolved, re-checked and re-pinned. IP-literal hosts connect directly to the literal that was checked.
  • Parser differential: the checker and the client use the same url::Url; decimal, hex and octal IPv4 forms are normalised to Ipv4 before the check (tested: 0x7f.1, 2130706433). Trailing-dot, IDN/punycode and userinfo tricks go through the same parse. localhost is covered by the resolve path. Mixed public+private answer sets are refused (any, not all). Relative redirects are joined and then re-vetted. No proxy; https_only is set.
  • Streaming cap: checked per chunk, so it is enforced before buffering past 5 MiB. A lying Content-Length cannot bypass it, and a decompressed stream would be counted too. Total timeout (15 s) covers body reading per hop, so slow-loris is bounded. Magic bytes are checked against the declared type, the MIME in the data: URL comes from the declared-and-sniff-matched value, never raw header text. The frontend re-validates MIME and base64 charset.
  • Abuse: no capability or manifest gates custom commands in this repo (no capabilities/ directory, no AppManifest), same as the existing update-check command, so any webview script can call it. That is the T8 trust model, and the command's own checks bound what such a call reaches. Nothing in the chat path calls it except the button onclick; forging a placeholder via raw HTML only yields the same click-gated card. Alt and URL render through Svelte text interpolation and title, no {@html}. Repo rules checked on the diff (no console, no any, no ticket numbers, no node-type or lifecycle literals, no sync wording): clean.
  • Docs: no ADR or doc I could find forbids this (grep of architecture/ and decisions/ on docs origin/main for remote image / img-src / external image: nothing). T8 and the acp-integration line (1366, "Markdown Rendering") do need the two edits the author names; T8 currently says the webview boundary is the whole defence, so the new command should be listed there as an outbound-network surface reachable from the webview. A new ADR is not required; the command narrows nothing in an accepted ADR. A short ADR would be reasonable only if you want the "app process fetches on behalf of the webview" pattern recorded for future commands.

Findings (all non-blocking)

  1. Low, test gap. remote_image.rs tests never exercise the DNS pin: every fetch test uses an IP-literal host under the loose policy, so removing resolve_to_addrs (lines ~248-251) would pass all 15 tests, and it is not among the 8 mutations. The PR body's "DNS rebinding" row is therefore true by construction but unproven by test. Suggest a loose-policy test using hostname localhost plus a local server, or at least a note.
  2. Low, range gaps in is_public_v6/v4 (~106-158): not refused are 64:ff9b:1::/48 (local-use NAT64), Teredo 2001::/32, 2001:10::/28 and 2001:2::/48 style special ranges, 100::/64, 192.88.99.0/24. Exploit needs a NAT64 or Teredo gateway on the victim's network that maps to a private v4; unlikely. Cheap to add 64:ff9b:1::/48 to the embedded-IPv4 branch.
  3. Low, resolve (~189): lookup_host has no timeout of its own, so a hostile authoritative DNS can stall up to the resolver timeout per hop (up to 4 hops) before the 15 s total applies. Bounded by the user's click; wrap in tokio::time::timeout for tidiness.
  4. Low, disclosure wording (remote-image-placeholder.svelte): the note says the host sees the IP address; the full address (query string included) is shown above the button, so the data is visible before the press, but the note does not say the address is sent. Consider "sends this address and your IP address".
  5. Info: a forged raw-HTML placeholder span keeps its own children and the card is mounted inside it, so hostile text can sit beside the card (same as the existing node-card placeholder pattern). Not exploitable beyond cosmetic text; I did not verify whether mount clears the target.
  6. Info: placeholder url is not length-limited for display (Rust caps at 2048); long text wraps, harmless.

Could not verify: the 15 Rust tests and 8 mutations, the Chromium tests, test:changed, real-network TLS behaviour, the webview image decoder, and whether the app-wide reqwest feature set enables gzip (the cap is on decompressed chunks either way).

Merge is the user's call.

@mstomar125

Copy link
Copy Markdown
Contributor Author

Resolution of the review (new commit 9b3ba03 on the PR branch, no force-push):

  1. DNS pin: now tested. The lookup is behind a small trait; a name that exists in no resolver is reached only through the pin, a second (rebinding) answer is never asked for, and each redirect hop is looked up and pinned again. Removing resolve_to_addrs fails two tests, and so does skipping the per-hop lookup.
  2. Ranges: 64:ff9b::/32 outside the well-known /96 (64:ff9b:1::/48 included), 2001::/23 (Teredo and the other protocol assignments), 100::/64 and 192.88.99.0/24 are refused, with tests at the edges and addresses that embed a public IPv4 so only the prefix rules can refuse them (one mutation survived until those were added).
  3. Lookup deadline: the whole load, every lookup and hop included, runs under one deadline (15 s in production). Tests: a first lookup that never answers, and a later hop's lookup that never answers; removing the deadline fails both.
  4. Note wording: 'Loading sends this full address, including any query string, to , which also sees your IP address.' The test pins the sentence.
  5. Forged span: confirmed that mount() keeps the target's children, so hostile text sat beside the card. The span is emptied before mounting, with a test that failed before the fix. The node-card placeholder has the same pattern; it is not changed here.

Checks: bun run test:changed passes (frontend, scripts, browser, types, shape, Rust nextest); clippy -D warnings and fmt are clean on the app crate; every mutation of the new tests is killed. The PR body's table is updated to match. Not merged.

@mstomar125

Copy link
Copy Markdown
Contributor Author

APPROVE (re-review of 9b3ba03, read-only; I read the diff and the surrounding code, I did not run the Rust or frontend tests or the mutations). All five earlier low findings are fixed; no new finding above info level.

  1. Resolver trait and pin: Lookup is a private trait, fetch_remote_image calls fetch_image with the hard-coded Policy::STRICT, which calls fetch_image_with(.., &SystemLookup). Nothing from the webview reaches a stub, a loosened policy or the trait; only the url string is an input. build_client still pins with resolve_to_addrs(name, addrs) (original hostname stays in the request, so SNI/Host/cert are for that name), and each hop runs resolve then build_client again. Note reqwest ignores the port inside an overridden SocketAddr and uses the URL's; in production that is 443 on both sides, so no mismatch. The new pin test uses a hostname no real resolver knows plus a stub that would answer differently on a second call and asserts one lookup, so it fails if the pin is removed (the client would look up pinned.test itself and fail). The hop test does the same for second.test.
  2. Range math (checked bit by bit): 2001 with second group < 0x0200 is exactly 2001::/23 (2001:0000 to 2001:01ff); 2001:200::/23 and up (APNIC and the rest), 2001:4860 (Google) and 2606:4700 (Cloudflare) stay public, and the 2001:db8::/32 rule is unchanged and exact. 100::/64 is correct (s[0]==0x0100 and the next three groups zero). For 64:ff9b::/32, anything outside the /96 (including 64:ff9b:1::/48) is now refused, and the /96 still falls through to the embedded-IPv4 check; 64:ff9a stays public. 192.88.99.0/24 is exact. The pre-existing refusals are untouched, and the new tests cover both edges of each new range plus public-IPv4-in-local-NAT64 cases that only the prefix rule can catch. Residual, info only: 3fff::/20 (documentation) and 5f00::/16 are not listed; neither is routable.
  3. Deadline: tokio::time::timeout(total_deadline, fetch_hops(..)) wraps every lookup, every hop and the body read, and the per-client timeout is still set as a second bound. A timeout maps to Refusal::Network, i.e. the short code network, no detail. The two stall tests (first lookup, and a later hop's lookup) would hang to their outer 5 s guard and fail if the wrapper were removed. Info: dropping the future does not cancel the blocking getaddrinfo thread, so a stalled system lookup still occupies one pool thread until the OS gives up; bounded by user clicks, not exploitable.
  4. Placeholder sentence now reads "Loading sends this full address, including any query string, to {host}, which also sees your IP address."; the test asserts the exact string. Good.
  5. el.replaceChildren() runs before mount(), only on the remote-image branch and only when a url is present; mountedByEl still guards double mounting. The new ChatMarkdown test forges the span with child text and would fail without the call. No hostile child text can survive; the span's own attributes (class/style) are normal sanitiser-allowed raw HTML any reply can already produce, not new. The node-card placeholder has the same pattern: cosmetic only (fake text beside a card, no IPC path, no escalation, the model can already write arbitrary text in a reply). Out of scope, fine to leave.
  6. Spot-checked for vacuity: the private/mixed-answer test (stub returns 10.0.0.5 and public+169.254.169.254) would end in network or a real connect attempt, not blocked_address, if the guard were removed; and the pin test above. Both are real. The 20 tests and 15 mutations I could not run; I did not execute test:changed.

mstomar125 and others added 2 commits November 16, 2026 09:37
…or it

A reply that contains an image with an http(s) address now shows a placeholder: the alt text, the host and the full address as plain text, and a "Load image" button. Nothing is requested before the press, and a press loads that one image only.

The webview cannot load a remote image, because the content security policy keeps img-src to the app, asset: and data:, so the image is fetched by the app process. A new Tauri command, fetch_remote_image, takes the address and returns an allow-listed image as base64, which the placeholder shows as a data: image. No policy or capability changes.

The command treats the address as hostile: https only, no credentials in the address, the default port only; every address the host resolves to must be public (loopback, private, link-local, carrier-grade NAT, documentation, multicast and reserved ranges are refused, including the IPv6 forms that carry an IPv4 address) and the connection is pinned to the addresses that were checked; redirects are followed by hand, at most three, each vetted the same way; no proxy, cookies, authentication or referrer; the status must be 200, the type PNG, JPEG, GIF or WebP (never SVG), the body at most 5 MiB, and the first bytes must match the declared type. A refusal is returned as a short code, not the underlying error.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…special ranges, clearer note

Review of the click-to-load change found no blocking issue and asked for these:

- The DNS pin is now tested. The name lookup is behind a small trait, so a test can point a name that exists in no resolver at a local server and answer a second lookup differently: the fetch must connect to the checked address, look each hop's name up once, and look a redirect's name up again and pin it again. Removing the pin fails these tests.
- The whole load, every lookup and every hop included, runs under one deadline, so a name server that never answers cannot stall it. Tested for a first lookup that stalls and for a later hop's lookup that stalls.
- The public-address check also refuses the rest of 64:ff9b::/32 (the local-use NAT64 prefix included; only the well-known /96 carrying a public IPv4 address is accepted), 2001::/23 (Teredo and the other protocol assignments), 100::/64 and 192.88.99.0/24, with tests at the edges.
- The placeholder note says what a press does in one sentence: the full address, query string included, is sent to that host, which also sees the IP address. The test pins the sentence.
- mount() adds to its target and keeps what is already in it, so a reply that wrote the placeholder span as raw HTML with text of its own showed that text beside the card. The span is emptied before the card is mounted, with a test.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant