Skip to content

fix(attachments): keep the Host token on the Host's origin - #178

Merged
touch2be merged 1 commit into
akemmanuel:masterfrom
touch2be:fix/host-image-token-origin
Oct 25, 2026
Merged

touch2be merged 1 commit into
akemmanuel:masterfrom
touch2be:fix/host-image-token-origin

Conversation

@touch2be

Copy link
Copy Markdown
Collaborator

Problem

Since #174 (in 0.7.2 and 0.7.3), HostImage attaches the Host bearer token to every http(s) image URL it fetches. It does not check that the URL belongs to the Host.

Image mentions are not limited to Host paths: @https://example.com/x.png matches the mention pattern, and resolveAttachmentImageSrc passes http(s) URLs through unchanged. On hosted web, the login session token is workspace.authToken, so attachmentAuthToken is always set. Rendering such a mention therefore sends the viewer's session token to that third-party origin, without a click. This also affects the owner or admin when they open a shared Session.

Two smaller issues on the same path:

  • SVG as a blob URL. The bearer path wraps any response in a blob URL. A blob URL has the app's origin, and the sandbox CSP from /api/fs/file does not carry over. An SVG opened from it ("Open image in new tab") runs script on the app origin.
  • No size limit. /api/fs/file reads the whole file into memory. The transcript requests every referenced image on render.

Change

  • isAttachmentHostUrl(src, baseUrl) (src/lib/attachment-src.ts): true only when the image URL has the same http(s) origin as attachmentBaseUrl. HostImage fetches with the token only in that case. Every other URL keeps the plain <img> request, as before feat(transcript): show Host image files referenced in assistant replies #174, without a credential.
  • Raster only for blobs: HostImage creates blob URLs only for png, jpeg, gif, webp, avif and bmp. Anything else (including SVG and text/html) shows the existing "Image unavailable" placeholder. SVG on Desktop Local and cookie Hosts is unchanged: those use plain <img>, and opening the file directly keeps the sandbox CSP.
  • /api/fs/file answers 413 for files over 25 MB (MAX_FILE_PREVIEW_BYTES) before reading them. This route only serves attachment previews.

Tests

  • HostImage.test.tsx
    • Token never sent to another origin. Cases: a foreign host, a lookalike subdomain, http instead of https, and another port.
    • No blob for SVG, HTML or a missing content type.
    • All 7 new cases fail on master and pass with this change.
  • attachment-src.test.ts: origin helper with blob, relative, null and invalid base URLs.
  • path-enforcement.routes.test.ts: a sparse file just over the limit returns 413; one exactly at the limit returns 200.

Results:

  • pnpm run check and pnpm run slop-check pass.
  • pnpm run test: 1,628 tests pass.

For review

  • Releases: 0.7.2 and 0.7.3 are affected on hosted / token-authenticated Hosts. A patch release is recommended.
  • Open question: whether third-party http(s) image mentions should render at all. They would still reveal the viewer's IP (as before feat(transcript): show Host image files referenced in assistant replies #174). This PR leaves that unchanged; blocking them like markdown remote images would be a small follow-up.

🤖 Generated with Claude Code

HostImage attached the Host bearer token to every http(s) image URL. An
image mention such as `@https://attacker.example/x.png` passes through
resolveAttachmentImageSrc unchanged, so rendering it sent each viewer's
session token to that origin. On hosted web the session token lives in
workspace.authToken, so every viewer was affected, including admins
opening shared Sessions.

- Fetch with the token only when the image URL has the same origin as
  the attachment base URL. Other origins keep the plain request.
- Turn only raster responses into blob URLs. A blob URL shares the app
  origin, and an SVG opened from one would run script there.
- /api/fs/file refuses files over 25 MB with 413 instead of reading them
  into memory on every transcript render.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@touch2be
touch2be merged commit 0215407 into akemmanuel:master Oct 25, 2026
2 checks passed
@touch2be touch2be mentioned this pull request Oct 25, 2026
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