Repository navigation
fix(links): allow only http, https, and mailto link schemes - #571
Open
cameronapak wants to merge 1 commit into
Open
cameronapak wants to merge 1 commit into
cameronapak wants to merge 1 commit into
Conversation
Co-Authored-By: Cameron Pak <cameronandrewpak@gmail.com>
Contributor
Contributor
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

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 towindow.open. No step checked the scheme.New shared helper in
src/data/links.ts: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:
foldedLinkEl(moved tosrc/plugins/links/render.ts) renders an unsafe url as an anchor with nohref,targetor favicon, markeddata-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.openUrlInFocusedTabrejects any url that fails the check. This also covers Mod+Enter (link-keymap.ts) and route-bible links.<a href>with an unsafe scheme keeps only its label and reports a degraded count.<a>.Tests:
links.test.tsforsafeLinkHref.render.test.tsfor[x](javascript:alert(1))and[x](JaVaScRiPt:alert(1)).rich-links.spec.ts: neither a click nor Mod+Enter opens anything.render.tswas split out ofindex.tsso these unit tests can render links without loading the plugin registry (which has an import cycle).Pre-existing
bun run testfailures onmain(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