Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(markdown): send the session cookie with proxied remote images (#9309)
Wolf Mermelstein43bb0ea18e46
diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.mdindex 10da5e8b49..cd04ecf16e 100644--- a/apps/web/AGENTS.md+++ b/apps/web/AGENTS.md@@ -447,7 +447,7 @@ resolved session ID; keep the existing `AgentSessionProvider` subscription to- Keep desktop headers on the shared `ListHeader` / `HeaderActionGroup` pattern: view `Tabs` as pills after the title, `sm`/`icon-sm` semantic islands (28px controls) with 8px gaps on the right, fully rounded frames, New then expandable Search; retain `md` sizing for Tabs, New, and Search. Drive and Tasks list-header filter, layout, sort, and grouping islands use `md`/`icon-md` (32px) to match New and Search. Preserve touch layouts. Compose ButtonGroup actions with explicit `ButtonGroup.Button` segments; use `variant="secondary" finish="raised"` on action frames. Standalone Buttons do not inherit group styling. Pick each control by role from the [design system rule](../../.agents/rules/web/design-system.md); see [UI conventions](../../docs/agent-guide/ui-conventions.md#top-bars). Never use recessed/inset backgrounds in headers.- Keep desktop model and effort controls separate: the model selector opens the catalog and the speedometer opens the runtime's advertised slider stops; retain the mobile effort sheet.- Passive PR mentions must not retry initial GitHub status failures on remount; preserve confirmed status through refetch errors and keep pending data reads out of their parent Suspense boundary.-- PR description and comment images are remote URL images: rewrite GitHub blob/`raw` links to `raw.githubusercontent.com` and load them through the image proxy so COEP does not block github.com. Load Macro's own static-file URLs directly: a composer image reaches the server as Markdown and comes back as a URL image, and the proxy needs a session cookie that a `crossorigin="anonymous"` image never sends.+- PR description and comment images are remote URL images: rewrite GitHub blob/`raw` links to `raw.githubusercontent.com` and load them through the image proxy so COEP does not block github.com. Load Macro's own static-file URLs directly: a composer image reaches the server as Markdown and comes back as a URL image. The proxy authenticates by session cookie, so a proxied `<img>` uses `crossorigin="use-credentials"` and a fetch of it `credentials: 'include'` (`isImageProxyUrl`); `anonymous` drops the cookie cross-origin and the proxy answers 401.- Keep native booking exit navigation in the route shell, outside page loading boundaries, and use the router so the native hash route stays intact.- Diagnose native full reloads with `native_webview_started`, `native_diagnostic_recovered`, and the shared `frontend_instance_id`; use `reloadApp(reason)` for frontend reloads and keep breadcrumbs content-free. Treat `previous_document_*` checkpoints as last-observed lifecycle evidence, never a crash verdict; clear them on logout. `previous_document_last_*` comes from the native navigation breadcrumb (route and entity type, never ids). See [frontend checkpoints](docs/native-reload-diagnostics.md) and `tauri/src-tauri/README.md`.- Pass `$APPLOCALDATA` (Application Support on Apple platforms) as the native HTTP cookie storage directory; the plugin owns the `.cookies` filename. Never use purgeable caches. The location change intentionally requires one new sign-in, without migration. See `tauri/src-tauri/README.md#native-authentication-cookies`.diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsxindex 938f156c1d..b277565f09 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.test.tsx@@ -55,6 +55,34 @@ describe('markdown media loading', () => {);});+ it('sends the session cookie to the image proxy', () => {+ const view = render(() => (+ <MarkdownImage+ {...unsetMedia}+ key="proxied"+ url="https://example.com/shot.gif"+ alt="Shot"+ />+ ));+ expect(+ view.container.querySelector('img')!.getAttribute('crossorigin')+ ).toBe('use-credentials');+ });++ it('loads a static file anonymously', () => {+ const view = render(() => (+ <MarkdownImage+ {...unsetMedia}+ key="static"+ url={`${SERVER_HOSTS['static-file']}/file/299c189c-df42-4a9a-b42b-7220264b607b`}+ alt="Static"+ />+ ));+ expect(+ view.container.querySelector('img')!.getAttribute('crossorigin')+ ).toBe('anonymous');+ });+it('shows a reserved image card while the file has no size yet', () => {render(() => (<MarkdownImagediff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsxindex b233a1763b..23e5da1f19 100644--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/decorator/MarkdownImage.tsx@@ -5,7 +5,7 @@ false && internalDrag;import { Lightbox } from '@core/component/Lightbox';import { toast } from '@core/component/Toast/Toast';import { fireAndForget } from '@core/util/fireAndForget';-import { displayImageUrl } from '@core/util/imageProxy';+import { displayImageUrl, isImageProxyUrl } from '@core/util/imageProxy';import ImageIcon from '@icon/system/regular/image-broken.svg';import LoadingSpinner from '@icon/system/regular/spinner.svg';import { Dialog } from '@kobalte/core/dialog';@@ -337,7 +337,9 @@ export function MarkdownImage(props: ImageDecoratorProps) {/></Show><img- crossorigin="anonymous"+ crossorigin={+ isImageProxyUrl(imageUrl()) ? 'use-credentials' : 'anonymous'+ }class={cn('h-full object-contain',effectiveDims()[0] > 0 && 'absolute inset-0 size-full',diff --git a/apps/web/src/lib/core/component/Lightbox/createImageActions.test.ts b/apps/web/src/lib/core/component/Lightbox/createImageActions.test.tsnew file mode 100644index 0000000000..24c720065c--- /dev/null+++ b/apps/web/src/lib/core/component/Lightbox/createImageActions.test.ts@@ -0,0 +1,44 @@+import { createRoot } from 'solid-js';+import { beforeEach, describe, expect, it, vi } from 'vitest';++const platformFetch = vi.hoisted(() => vi.fn());+const copyImageToClipboard = vi.hoisted(() => vi.fn());+vi.mock('@core/util/platformFetch', () => ({ platformFetch }));+vi.mock('@core/util/imageActions', () => ({+ copyImageToClipboard,+ downloadImage: vi.fn(),+}));++import { proxyImageUrl } from '@core/util/imageProxy';+import { createImageActions } from './createImageActions';++async function copyAndFetch(src: string) {+ const actions = createRoot(() =>+ createImageActions({ src: () => src, imageId: () => 'image' })+ );+ await actions.copyToClipboard();+ const [getBlob] = copyImageToClipboard.mock.calls[0]!;+ await getBlob();+}++describe('createImageActions', () => {+ beforeEach(() => {+ platformFetch.mockReset();+ platformFetch.mockResolvedValue(new Response(new Blob(['gif'])));+ copyImageToClipboard.mockReset();+ });++ it('fetches a proxied image with the session cookie', async () => {+ const src = proxyImageUrl('https://example.com/shot.gif');+ await copyAndFetch(src);+ expect(platformFetch).toHaveBeenCalledWith(src, {+ credentials: 'include',+ });+ });++ it('fetches any other image without credentials', async () => {+ const src = 'https://example.com/shot.gif';+ await copyAndFetch(src);+ expect(platformFetch).toHaveBeenCalledWith(src, undefined);+ });+});diff --git a/apps/web/src/lib/core/component/Lightbox/createImageActions.ts b/apps/web/src/lib/core/component/Lightbox/createImageActions.tsindex f916fdc6fe..68508e7944 100644--- a/apps/web/src/lib/core/component/Lightbox/createImageActions.ts+++ b/apps/web/src/lib/core/component/Lightbox/createImageActions.ts@@ -2,6 +2,7 @@ import {copyImageToClipboard,downloadImage as downloadImageAction,} from '@core/util/imageActions';+import { isImageProxyUrl } from '@core/util/imageProxy';import { platformFetch } from '@core/util/platformFetch';import { isIOS } from '@solid-primitives/platform';import {@@ -31,7 +32,10 @@ export function createImageActions(input: ImageActionsInput) {if (input.getBlob) return input.getBlob();const url = input.src();if (!url) return undefined;- return (await platformFetch(url)).blob();+ const init: RequestInit | undefined = isImageProxyUrl(url)+ ? { credentials: 'include' }+ : undefined;+ return (await platformFetch(url, init)).blob();};// Pre-fetch the blob on iOS so it is already in memory when the user tapsdiff --git a/apps/web/src/lib/core/util/imageProxy.test.ts b/apps/web/src/lib/core/util/imageProxy.test.tsindex 14daa47e72..85a0ba1236 100644--- a/apps/web/src/lib/core/util/imageProxy.test.ts+++ b/apps/web/src/lib/core/util/imageProxy.test.ts@@ -3,6 +3,7 @@ import { SERVER_HOSTS } from '../constant/servers';import {displayImageUrl,githubRawImageUrl,+ isImageProxyUrl,proxyImageUrl,} from './imageProxy';@@ -66,3 +67,15 @@ describe('displayImageUrl', () => {);});});++describe('isImageProxyUrl', () => {+ it('recognizes a proxied URL and nothing else', () => {+ const src = 'https://example.com/shot.png';+ expect(isImageProxyUrl(proxyImageUrl(src))).toBe(true);+ expect(isImageProxyUrl(src)).toBe(false);+ expect(+ isImageProxyUrl(`${SERVER_HOSTS['static-file']}/file/299c189c`)+ ).toBe(false);+ expect(isImageProxyUrl('data:image/png;base64,AAAA')).toBe(false);+ });+});diff --git a/apps/web/src/lib/core/util/imageProxy.ts b/apps/web/src/lib/core/util/imageProxy.tsindex 1afcaec764..b2d3e56935 100644--- a/apps/web/src/lib/core/util/imageProxy.ts+++ b/apps/web/src/lib/core/util/imageProxy.ts@@ -49,8 +49,17 @@ export function proxyImageUrl(src: string): string {/** URL to put on an `<img>` for a remote markdown image. */export function displayImageUrl(src: string): string {// Markdown import turns a pasted image into a plain URL. Static files are- // public and send their own CORS headers, while the proxy needs a session- // cookie that a `crossorigin="anonymous"` image never sends.+ // public and send their own CORS headers, so they skip the proxy.if (src.startsWith(`${SERVER_HOSTS['static-file']}/`)) return src;return proxyImageUrl(githubRawImageUrl(src));}++/**+ * Whether `src` loads through the image proxy. The proxy authenticates by+ * session cookie, which a cross-origin request only sends with credentials+ * (`crossorigin="use-credentials"` on an `<img>`, `credentials: 'include'` on+ * a fetch).+ */+export function isImageProxyUrl(src: string): boolean {+ return src.startsWith(`${SERVER_HOSTS['image-proxy-service']}/proxy?`);+}