Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: catch protocol-relative remote refs and reset opt-in on content change (#8358)
[._.]/ Adam Eivy4af3fd0054e9
diff --git a/client/src/components/messages/MessageDetail.jsx b/client/src/components/messages/MessageDetail.jsxindex 26a54d14ca..47bfa652df 100644--- a/client/src/components/messages/MessageDetail.jsx+++ b/client/src/components/messages/MessageDetail.jsx@@ -4,11 +4,13 @@ import toast from '../ui/Toast';import { formatCount, formatDateTime } from '../../utils/formatters';import * as api from '../../services/api';-// Any src/href/poster/url()/@import that points at a remote http(s) resource —-// the load vectors a tracking pixel or remote stylesheet rides in on. Used-// only to decide whether to show the "remote images blocked" notice; the CSP-// meta below is what actually blocks the fetch, regardless of this matching.-const REMOTE_REF_RE = /(?:<(?:img|source|video)\b[^>]*\bsrc\s*=\s*["']?https?:)|(?:<link\b[^>]*\bhref\s*=\s*["']?https?:)|(?:\burl\(\s*["']?https?:)|(?:@import\s+(?:url\()?["']?https?:)|(?:\bposter\s*=\s*["']?https?:)/i;+// Any src/href/poster/url()/@import that points at a remote http(s) or+// protocol-relative (`//host/...`) resource — the load vectors a tracking+// pixel or remote stylesheet rides in on. Used only to decide whether to show+// the "remote images blocked" notice; the CSP meta below is what actually+// blocks the fetch (for every scheme, including a bare `//`), regardless of+// what this matches.+const REMOTE_REF_RE = /(?:<(?:img|source|video)\b[^>]*\bsrc\s*=\s*["']?(?:https?:)?\/\/)|(?:<link\b[^>]*\bhref\s*=\s*["']?(?:https?:)?\/\/)|(?:\burl\(\s*["']?(?:https?:)?\/\/)|(?:@import\s+(?:url\()?["']?(?:https?:)?\/\/)|(?:\bposter\s*=\s*["']?(?:https?:)?\/\/)/i;// `default-src 'none'` blocks every fetch the sanitizer regex above doesn't// catch (background-image, @import, <link>, <source>, <video poster>, …);@@ -28,6 +30,14 @@ function SafeHtmlBody({ html }) {const [allowRemote, setAllowRemote] = useState(false);const hasRemoteRefs = useMemo(() => REMOTE_REF_RE.test(html || ''), [html]);+ // Consent is per rendered body, not per component instance: if this+ // instance gets reused for a different message/refreshed content (list+ // position reuse, not a remount), a prior "Load remote images" click must+ // not silently carry over to content the user never opted into.+ useEffect(() => {+ setAllowRemote(false);+ }, [html]);+const writeContent = useCallback(() => {const iframe = iframeRef.current;if (!iframe) return;diff --git a/client/src/components/messages/MessageDetail.test.jsx b/client/src/components/messages/MessageDetail.test.jsxindex 2b987f7bba..033d9a37fe 100644--- a/client/src/components/messages/MessageDetail.test.jsx+++ b/client/src/components/messages/MessageDetail.test.jsx@@ -83,6 +83,30 @@ describe('MessageDetail SafeHtmlBody remote content blocking', () => {expect(screen.queryByText('Remote images blocked')).not.toBeInTheDocument();});+ it('does not carry a "load remote images" opt-in over to different content in a reused instance', async () => {+ const { rerender } = renderMessage({+ ...baseMessage,+ bodyHtml: '<img src="https://example.com/pixel.gif" alt="">',+ });+ await waitFor(() => expect(iframeCsp()).toContain("default-src 'none'"));+ fireEvent.click(await screen.findByRole('button', { name: 'Load remote images' }));+ await waitFor(() => expect(iframeCsp()).toMatch(/img-src[^;]*https:/));++ // Same component tree, different message content — as if a list item's+ // key were reused (refreshed body, or a different message rendered in+ // the same position) rather than remounted.+ rerender(+ <MessageDetail+ message={{ ...baseMessage, bodyHtml: '<img src="https://tracker.example/pixel.gif" alt="">' }}+ accounts={[{ id: 'acct-1', name: 'Personal' }]}+ onBack={() => {}}+ />,+ );++ await waitFor(() => expect(iframeCsp()).not.toMatch(/img-src[^;]*https:/));+ expect(await screen.findByText('Remote images blocked')).toBeInTheDocument();+ });+it('shows no remote-content notice for a body with only inline data: images and plain formatting', async () => {renderMessage({...baseMessage,