Skip to content

text: Keep document image sources URI-backed - #2735

Merged
huacnlee merged 2 commits into
longbridge:mainfrom
lurenjia534:fix/textview-local-image-access
Aug 16, 2026
Merged

text: Keep document image sources URI-backed#2735
huacnlee merged 2 commits into
longbridge:mainfrom
lurenjia534:fix/textview-local-image-access

Conversation

@lurenjia534

@lurenjia534 lurenjia534 commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Closes #2733

Description

Keep image sources originating from TextView documents URI-backed instead of
implicitly converting file:// and scheme-less strings into Resource::Path.

The previous conversion allowed Markdown and HTML content, including LSP hover
and completion documentation, to trigger reads of attacker-selected local
filesystem paths.

Inline images, block images, and intrinsic-size measurement already share the
image_source helper, so this change is confined to that conversion and its
existing unit test. Relative paths, absolute paths, Windows paths, and
file:// values are now all kept as Resource::Uri.

This intentionally removes implicit local-filesystem image loading from generic
TextView content. As a result, relative images such as
website/public/logo.svg in the Story Gallery README will no longer load as
local files. Supporting trusted local document resources requires a separate,
explicit API; base-directory confinement, path normalization, file-size
limits, and other resource-policy changes are outside the scope of this patch.

How to Test

The following checks pass:

cargo test -p gpui-component text::utils::tests::test_image_source -- --nocapture
cargo fmt --all -- --check
cargo test -p gpui-component

The updated test_image_source verifies that remote URLs, data URLs, relative
paths (including .. traversal), Unix absolute paths, Windows paths, paths
containing colons, and file:// values all remain Resource::Uri.

Manual runtime verification was also performed on Linux with the existing
markdown_table example and a Markdown document containing:

![poc](/tmp/textview-local-read-poc.svg)

Under strace, the vulnerable implementation opened the referenced SVG:

openat(AT_FDCWD, "/tmp/textview-local-read-poc.svg", O_RDONLY|O_CLOEXEC) = 28

With this patch, the example opened the injected Markdown document but did not
issue any open or openat call for the referenced SVG.

Checklist

  • I have read the CONTRIBUTING document and followed the guidelines.
  • Reviewed the changes in this PR and confirmed AI-generated code is accurate.
  • Passed cargo run for story tests related to the changes. The Story
    Gallery starts successfully; the README relative image is no longer loaded
    from the local filesystem, as documented above.
  • This change is not platform-specific.

@huacnlee

Copy link
Copy Markdown
Member

cc @madcodelife

@huacnlee
huacnlee merged commit bd83329 into longbridge:main Aug 16, 2026
3 checks passed
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.

TextView image sources can read arbitrary local filesystem paths

2 participants