Skip to content

highlight: only link a target that navigates - #226

Open
cgzones wants to merge 1 commit into
matze:masterfrom
cgzones:source-view-link-schemes
Open

cgzones wants to merge 1 commit into
matze:masterfrom
cgzones:source-view-link-schemes

Conversation

@cgzones

@cgzones cgzones commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

The source view builds its own anchors for Markdown links and, unlike rendered Markdown, its output never passes through ammonia — so a paste containing [click](javascript:alert(1)) shipped a working javascript: URL. Escaping does not help here: it keeps the attribute intact, which is exactly what makes the URL work, and only the CSP stood between that and script execution.

The target is the link scope's own text, so it is not known when the scope opens. Hold the anchor until the text arrives and emit it only for a scheme that goes somewhere (http, https, mailto, or a relative target); anything else is shown as the text it already reads as. Browsers drop whitespace and control characters before resolving a URL, so the scheme is compared with them taken out.

The source view builds its own anchors for Markdown links and, unlike
rendered Markdown, its output never passes through ammonia — so a paste
containing `[click](javascript:alert(1))` shipped a working `javascript:`
URL. Escaping does not help here: it keeps the attribute intact, which is
exactly what makes the URL work, and only the CSP stood between that and
script execution.

The target is the link scope's own text, so it is not known when the scope
opens. Hold the anchor until the text arrives and emit it only for a scheme
that goes somewhere (http, https, mailto, or a relative target); anything
else is shown as the text it already reads as. Browsers drop whitespace and
control characters before resolving a URL, so the scheme is compared with
them taken out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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