Skip to content

fix(tui): address PR #3720 review feedback on markdown image rendering#3721

Merged
Sayt-0 merged 1 commit into
mainfrom
worktree-board-570607f2c61e5e8e
Jul 17, 2026
Merged

fix(tui): address PR #3720 review feedback on markdown image rendering#3721
Sayt-0 merged 1 commit into
mainfrom
worktree-board-570607f2c61e5e8e

Conversation

@dgageot

@dgageot dgageot commented Jul 17, 2026

Copy link
Copy Markdown
Member

Three code-review findings left on PR #3720 (#3720) were not addressed before merge. This commit fixes all three.

LoadMarkdownReference in pkg/tui/image/image.go now rejects file:// and sandbox:// URI schemes before attempting a fetch. LLM-generated markdown could otherwise craft an image reference that causes the agent to read arbitrary local files on behalf of the user — a confused-deputy attack. Bare relative paths (used for agent-generated images) are unaffected.

In pkg/tui/components/message/message.go, failed image fetches are now removed from loadingImages rather than left in place. Because the loaded message carries only the refs that succeeded, leaving failures in the set caused them to be treated as already-in-flight on the next SetMessage call, permanently suppressing any retry. The fix lets transient failures recover on a subsequent render cycle. The same file also fixes replaceMarkdownImagePlaceholders, which was computing code-block line shifts against the post-replacement line number instead of the original one; any code block appearing after an image placeholder ended up shifted by the wrong amount, breaking click-to-copy on those blocks.

Each fix is covered by a new unit test (TestLoadMarkdownReferenceRejectsLocalSchemes, TestFailedMarkdownImageLoadCanRetry, TestReplaceMarkdownImagePlaceholdersShiftsCodeBlocksByOriginalLine). Build, tests, and linter all pass.

Reject file:// and sandbox:// URIs in LoadMarkdownReference to prevent
prompt-injected markdown from reading local files. Clear failed image
sources from loadingImages so a later SetMessage can retry them. Fix
code-block line-shift comparison to use the pre-replacement line number.

Assisted-By: Claude
@dgageot
dgageot requested a review from a team as a code owner July 17, 2026 14:29
@dgageot

dgageot commented Jul 17, 2026

Copy link
Copy Markdown
Member Author

cc @rumpl @Sayt-0 wdyt?

@aheritier aheritier added area/security Authentication, authorization, secrets, vulnerabilities area/tui For features/issues/fixes related to the TUI kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Jul 17, 2026
@Sayt-0
Sayt-0 merged commit 16583cd into main Jul 17, 2026
14 checks passed
@Sayt-0
Sayt-0 deleted the worktree-board-570607f2c61e5e8e branch July 17, 2026 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/security Authentication, authorization, secrets, vulnerabilities area/tui For features/issues/fixes related to the TUI kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants