fix(files): allowlist the schemes a markdown link may target - #7012
Conversation
`normalizeLinkHref` rejected only `file` for a `scheme://` target, so any other scheme was returned unchanged. `scheme://` is well-formed for every scheme, so the check let through spellings that are not navigable targets at all. - Keep a scheme only when it is http(s), ftp(s), mailto, or tel; drop the rest - Leave an existing link alone when a committed target normalizes away, rather than unsetting it — the editor seeds that field with the current href, so committing an untouched one previously removed the link Detection is unchanged for relative, anchor, protocol-relative, and bare-domain targets. A document's stored markdown is untouched: normalization runs on the render and edit paths, never on parse or serialize, so a target that is refused still round-trips verbatim.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Schemes are now allowlisted (
Reviewed by Cursor Bugbot for commit 383c010. Configure here. |
Greptile SummaryThis PR replaces markdown link scheme blocklisting with an explicit allowlist and distinguishes clearing a link from refusing an unsafe target.
Confidence Score: 5/5The PR appears safe to merge, with no concrete blocking or independently actionable non-blocking issues identified. The allowlist closes the unsafe explicit-scheme path across the known render and editing callers, and the revised edit behavior preserves links only when a refused nonempty target is submitted while explicit clearing continues to remove them.
|
| Filename | Overview |
|---|---|
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/markdown-fidelity.ts | Replaces permissive explicit-scheme handling with a focused safe-scheme allowlist while retaining established relative and bare-host behavior. |
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus/link-editing.tsx | Separates explicit link removal from rejection of a nonempty unsafe target so opening and committing an unchanged refused link does not delete it. |
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/menus/link-editing.test.ts | Covers setting, clearing, and refusing links through the shared applyLink helper. |
| apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/round-trip.test.ts | Expands coverage for unknown and executable schemes, browser-normalized whitespace variants, and linked-image target sanitization. |
Reviews (1): Last reviewed commit: "fix(files): allowlist the schemes a mark..." | Re-trigger Greptile
Summary
normalizeLinkHrefrejected onlyfilefor ascheme://target and returned every other scheme unchanged.scheme://is well-formed for any scheme, so a blocklist can't be complete here — switched it to an allowlist ofhttp(s),ftp(s),mailto,tel.Type of Change
Testing
applyLinkoutcomes. Each was verified to fail against the previous behavior.host:porthandling are unchanged, as aresim:mention links, which take a different branch.bun run type-check,bun run lintand the fullbun run check:audits(33 audits) pass; 770 tests in the affected area pass.Checklist