fix: open Windows file links in chat #5283
main fromrefs/pull/5283/head·opened View on GitHubSummary#
Make chat file links in Windows native app clickable Clicking opens sidebar with the file Adds a relevant file icon too
Why#
Chat file links in Windows native apps look clickable, act clickable, but arent, its confusing, would be nice to add clickable behavior
Validation#
Have AI reply to you with file links in chat on Windows app:
Before:
https://github.com/user-attachments/assets/95980b0c-60e0-450c-8876-1d3dfe7da907
After ( clickable, opens sidebar with file ):
https://github.com/user-attachments/assets/6670d6aa-207a-46a4-8e07-591756de2fb9
Checklist#
- This PR is small and focused
- I explained what changed and why
- I included before/after screenshots for any UI changes
- I included a video for animation/interaction changes
Note
Low Risk Localized markdown link normalization and sanitize allowlist for chat rendering; no auth or server changes, with added unit tests.
Overview
Windows drive-letter paths in chat markdown (e.g. C:/Users/... or file:///D:/...) now survive sanitization and are normalized so the existing file-link UI can treat them as workspace files instead of broken or external links.
rehype-sanitize is extended so single-letter href protocols are allowed before urlTransform runs—otherwise C: is stripped as an unknown scheme. rewriteMarkdownFileUriHref then canonicalizes backslashes, encoded %5C, and duplicate slashes to a leading-slash form like /C:/path, which keeps the drive letter from being parsed as a URL scheme downstream.
Tests cover file:// Windows URIs, angle-bracketed destinations, and several slash/encoding variants; non-file hrefs like https:// and x:command stay unchanged.
Note
[!NOTE]
Fix Windows drive letter file links opening in chat#
- Extends the rehype-sanitize schema in ChatMarkdown.tsx to allow Windows drive-letter pseudo-protocols (e.g.
C:) so they are not stripped beforeurlTransformruns. - Updates
rewriteMarkdownFileUriHrefin markdown-links.ts to canonicalize Windows drive-style hrefs (including backslash, URL-encoded backslash, and duplicate-slash variants) to a leading-slash form like/C:/path. - Adds tests in markdown-links.test.ts covering normalization of
file://URIs, angle-bracketed paths, and various slash/encoding variants.
Macroscope summarized 76625da. >
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:S
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).
Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b63420eafddff973a991e392c46b1ee7ab164a42. Configure [here](https://www.cursor.com/dashboard/bugbot).@@ -103,3 +103,11 @@103103 export function rewriteMarkdownFileUriHref(href: string | undefined): string | null {104104 if (!href) return null;105105 const normalizedHref = normalizeMarkdownLinkDestination(href);106+ // Markdown parsing can encode backslashes or duplicate the drive separator.107+ const windowsDriveHref = normalizedHref108+ .replaceAll(/%5c/gi, "/")109+ .replaceAll(/\\/g, "/")110+ .replace(/^\/?([A-Za-z]):\/+/, "/$1:/");111+ // A leading slash keeps the drive letter from being treated as a URL scheme.112+ if (/^\/[A-Za-z]:\//.test(windowsDriveHref)) return windowsDriveHref;113+Windows file link key mismatch#
High Severity
rewriteMarkdownFileUriHrefnow turns bare Windows drive paths into slash-prefixed form (/C:/...), butfile://Windows URLs still rewrite to the unprefixed form (C:/...).normalizeMarkdownLinkHrefKeyruns that rewrite again on the already-transformedhrefat render time, so the meta map key no longer matches and previously workingfile://Windows links miss the file-link renderer.Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit b63420eafddff973a991e392c46b1ee7ab164a42. Configure [here](https://www.cursor.com/dashboard/bugbot).Additional Locations (2)
Approvability#
Verdict: Approved e1752e5
Straightforward bug fix for Windows file path handling in chat markdown. Changes are self-contained to link processing logic, include comprehensive test coverage, and have no security or infrastructure implications.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Second Windows repro, independently confirming this, plus one consequence that I don't think has been spelled out yet.
Environment: T3 Code Nightly 0.0.33, Windows 11 (26220) x64,
react-markdown10.1.0,rehype-sanitize6.0.0.Repro: ask an agent where a build artifact landed. Both Codex and Claude routinely emit a bare drive path as the link destination rather than a
file://URI:[Download the local installer](C:\projects\app\dist\App_1.12.0_x64-setup.exe)That renders as an ordinary blue link, and clicking it does nothing at all.
Mechanism. Two independent layers each kill it, which lines up with the two halves of this PR:
rehype-sanitizeruns before react-markdown'surlTransform, andCHAT_MARKDOWN_SANITIZE_SCHEMAallowlistsfile:but not drive letters — soC:reads as an unknown protocol and thehrefattribute is dropped outright. Runningmain's actual schema through the pipeline:destination hrefafter sanitizeC:\projects\...\setup.exeundefinedC:/projects/.../setup.exeundefinedfile:///C:/projects/.../setup.exepreserved /Users/x/project/AGENTS.mdpreserved Even if it survived sanitize,
defaultUrlTransformreturns""for anyX:/…— the first colon precedes the first slash andCisn't insafeProtocol. Verified directly against react-markdown 10.1.0:C:/…andD:/…both →"", while POSIX and relative destinations pass through untouched.
The part worth calling out: it isn't only the anchor that dies. The file-chip lookup is keyed on the transformed href —
markdownFileLinkMetaByHref.get(normalizeMarkdownLinkHrefKey(href))— so an empty href also misses the map and the destination never becomes a file chip. That costs the chip's right-click menu as well, so there's no "Copy full path" and no "Open in editor" to fall back on. On Windows the link is completely inert rather than merely pointing somewhere useless, which is why this reads as broken rather than as a minor papercut. POSIX destinations are unaffected throughout, which is what makes this Windows-only.I read the diff, and allowing drive letters at the sanitize layer plus canonicalizing to
/C:/…beforeurlTransformcloses both layers — and because the lookup key now matches, it restores the chip and its context menu too, not just the click. Would be good to see this land.Heads up that #6237 is open against the same bug and touches the same two places,
CHAT_MARKDOWN_SANITIZE_SCHEMAandrewriteMarkdownFileUriHref. The approaches are not just different, they produce different href shapes, so whichever lands second will not merge cleanly and its tests will contradict the first. Worth a maintainer picking one before either goes further.The comparison, since it is not obvious from either description alone:
This PR widens the sanitizer to accept every single letter as a scheme:
const WINDOWS_DRIVE_LINK_PROTOCOLS = Array.from("ABC...xyz"); href: [...(defaultSchema.protocols?.href ?? []), "file", ...WINDOWS_DRIVE_LINK_PROTOCOLS],#6237 instead runs a remark plugin before sanitization so drive paths never reach it looking like a scheme, and leaves the allowlist at
file. Both end up safe today, becauseurlTransformruns afterwards and falls back todefaultUrlTransform, which drops anything that is not http/https/mailto/tel. But this version's safety depends on that second gate staying correct forever, for 52 schemes rather than one. Sanitizer allowlists are the thing people audit and trust, so widening it toa:throughz:is a bigger claim than the bug needs. Your ownx:commandtest proves the backstop works rather than that the allowlist is tight.The other thing worth weighing is the leading-slash canonical form:
if (/^\/[A-Za-z]:\//.test(windowsDriveHref)) return windowsDriveHref;WINDOWS_DRIVE_PATH_PATTERNis/^[A-Za-z]:[\\/]/, anchored, so/C:/Users/...stops matching it. Everything downstream that keys off that pattern therefore stops seeing these as Windows paths, and they get routed into the POSIX branch instead:if (path.startsWith("/")) return looksLikePosixFilesystemPath(path);That still works for the cases in your tests, but only by accident:
/C:/is not inPOSIX_FILE_ROOT_PREFIXES, so it survives on the trailing-extension check or the:42position suffix. A drive link with neither, say a directory link like/C:/Users/mike/project, fails all three and stops resolving as a file link. #6237 keepsC:/Users/...intact and so keeps matching the existing pattern.Also note this changes the return shape of an already-exported function, which is why the two existing expectations had to be edited:
-).toBe("D:/Programme/t3code/apps/web/src/components/chat/OpenInPicker.tsx#L69"); +).toBe(canonicalHref); // now "/D:/Programme/..."Only two call sites today, both in
ChatMarkdown.tsx, so the blast radius is small right now. But an exported helper whose contract is "no leading slash" quietly becoming "leading slash on Windows" is the kind of thing that bites the third caller.The
%5CandC://normalization here is genuinely good and I did not see an equivalent in #6237. If the maintainers go with the remark-plugin approach, those cases are worth porting across rather than losing.CDVolvik(GitHub profile, opens in a new tab) requested changes
Formalizing my 8/14 review as changes-requested — the head commit is unchanged (76625da) and both findings still hold:
The leading-slash form this PR produces (
/C:/...) no longer matchesWINDOWS_DRIVE_PATH_PATTERN = /^[A-Za-z]:[\/]/— the pattern is anchored, so every downstream consumer of that check stops recognizing the path as a Windows drive path. #6237 fixes the same bug with theC:/...shape, which keeps the pattern matching.The sanitizer widening catches all 52 single-letter prefixes, not just real drive letters in path position — that over-matches.
Full detail with repro in my earlier review on this commit.
t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.

Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
87977cab-9de8-4fbe-a6ba-7757776415abYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share