Repository navigation
Load a remote image from an AI chat reply only when the person asks for it - #4277
Conversation
|
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
Findings (all non-blocking)
Could not verify: the 15 Rust tests and 8 mutations, the Chromium tests, Merge is the user's call. |
|
Resolution of the review (new commit 9b3ba03 on the PR branch, no force-push):
Checks: |
|
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.
|
…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]>
9b3ba03 to
3fae96a
Compare
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:andconnect-src 'self' ipc: …, and the chat sanitiser drops every network source. Looseningimg-srcwould 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:
renderChatImage(marked image renderer) writes anhttp(s)image as<span class="ns-remote-image-placeholder" data-image-url=… data-alt=…>. Every other address is not a remote image: an inlinedata: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.chat-markdown.sveltemountsRemoteImagePlaceholderon that span after sanitising (the same mechanism as node cards). No{@html}.fetch_remote_image(url). It returns{ mime, data_base64 }, shown asdata:<mime>;base64,…, whichimg-srcalready 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.22andurl(already in the workspace, already in the lock);reqwestwas already there.What the command does with a hostile address (
app-lib/src/commands/remote_image.rs)localhost, decimal/hex IP forms)::ffff:a.b.c.d,::a.b.c.d, NAT64 /96, 6to4).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.http:,file:,ftp:, credentials in the address, odd portsdata:URL is built (type allow-list and base64 character set).network.<img src=https://…>in a replyhttpaddress 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
fetch_remote_imageover 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
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 tofile:/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.invokeand nofetchand 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, noimg/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:changedpasses (frontend, scripts, browser, types, shape, Rust nextest); clippy-D warningsand 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