Skip to content

fix(links): allow only http, https, and mailto link schemes - #571

Open
cameronapak wants to merge 1 commit into
mainfrom
devin/1795101165-safe-link-href
Open

cameronapak wants to merge 1 commit into
mainfrom
devin/1795101165-safe-link-href

Conversation

@cameronapak

Copy link
Copy Markdown
Owner

Summary

Fixes stored XSS through link schemes. Before this change, a [x](javascript:alert(1)) token could come from OPML import, a plain-text paste, MCP, or a capture key. It rendered as <a href="javascript:…">, and a click passed it to window.open. No step checked the scheme.

New shared helper in src/data/links.ts:

safeLinkHref(url): string | null
// new URL(url.trim(), "https://dotflowy.invalid/").protocol ∈ {http:, https:, mailto:}

It uses the WHATWG parser, the same one the browser applies to href. So mixed case (JaVaScRiPt:), leading spaces, and embedded tabs or newlines all reduce to the real scheme. Relative URLs resolve to https and still work.

Where the helper is enforced:

  • Renderer: foldedLinkEl (moved to src/plugins/links/render.ts) renders an unsafe url as an anchor with no href, target or favicon, marked data-unsafe-link. It stays one source atom, so caret math and the edit pencil still work and the user can fix the url. The revealed form never had an href.
  • Click and open: the anchor click handler checks again, and openUrlInFocusedTab rejects any url that fails the check. This also covers Mod+Enter (link-keymap.ts) and route-bible links.
  • OPML import: an <a href> with an unsafe scheme keeps only its label and reports a degraded count.
  • OPML export: an unsafe link exports as its label with no <a>.

Tests:

  • Unit tests in links.test.ts for safeLinkHref.
  • Unit tests in render.test.ts for [x](javascript:alert(1)) and [x](JaVaScRiPt:alert(1)).
  • New OPML import and export cases.
  • A new e2e test in rich-links.spec.ts: neither a click nor Mod+Enter opens anything.

render.ts was split out of index.ts so these unit tests can render links without loading the plugin registry (which has an import cycle).

Pre-existing bun run test failures on main (Stripe and unfurl worker tests) are unrelated.

Link to Devin session: https://app.devin.ai/sessions/f067e339827443878be6364ab95c0d00
Open in Devin Desktop: https://app.devin.ai/desktop/session/f067e339827443878be6364ab95c0d00?variant=devin
Requested by: @cameronapak

Co-Authored-By: Cameron Pak <cameronandrewpak@gmail.com>
@pullfrog

pullfrog Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

Pullfrog  | Review this ➔

@cameronapak cameronapak self-assigned this Nov 19, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

This branch has not been deployed

No deployments
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.

1 participant