Skip to content

Move link sanitizer into core - #4329

Closed
acywatson wants to merge 2 commits into
mainfrom
sani-links
Closed

acywatson wants to merge 2 commits into
mainfrom
sani-links

Conversation

@acywatson

Copy link
Copy Markdown
Contributor

This makes the link library more secure by default by sanitizing links using default library logic. Users can provider their own sanitizer overrider or pass explicit null to disable sanitization altogether.

@vercel

vercel Bot commented Apr 14, 2023 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2023 10:44pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 14, 2023 10:44pm

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 14, 2023
@github-actions

github-actions Bot commented Apr 14, 2023 •

Copy link
Copy Markdown

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
packages/lexical/dist/Lexical.js 26.94 KB (0%) 539 ms (0%) 44 ms (+44.98% 🔺) 583 ms
packages/lexical-rich-text/dist/LexicalRichText.js 37.8 KB (0%) 757 ms (0%) 34 ms (-21.53% 🔽) 790 ms
packages/lexical-plain-text/dist/LexicalPlainText.js 37.78 KB (0%) 756 ms (0%) 50 ms (+9.37% 🔺) 806 ms

@zurfyx zurfyx left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have we considered sanitization rules at a plugin level? This is seamless when using the default but there's repetition every time you want to toggle a link. Additionally, I think that this function is doing too much, it's a setter and a toggle, perhaps we should revisit this in the future.

if (url !== null) {
let sanitizedUrl: string | null = url;
if (sanitizeUrl !== null) {
const sanitize = sanitizeUrl ? sanitizeUrl : _sanitizeUrl;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.10? This is a breaking change isn't it? Some URLs will stop working unless you pass an explicit null.

@acywatson

Copy link
Copy Markdown
Contributor Author

@zurfyx

Have we considered sanitization rules at a plugin level?

Yes, that means no protection for non-React users. If React can do this in the core, so can we.

there's repetition every time you want to toggle a link

Sure, good thinking

Additionally, I think that this function is doing too much, it's a setter and a toggle, perhaps we should revisit this in the future.

Sure

@acywatson acywatson closed this Apr 17, 2023
@acywatson acywatson reopened this Apr 17, 2023
@zurfyx

zurfyx commented Apr 17, 2023

Copy link
Copy Markdown
Member

Having reviewed the internal context around the criticality of having this by default, I can extend my review to say:

  1. It's very hard to catch all malicious sites with a sanitizer that works for everybody - internally we use a shimming approach that will kick in when moving to external non-Meta owned sites. Other people may be OK without a shimmer.
  2. Sanitizer can be bypassed as it's a client-side module, on Collab this means that all users can be impacted

I believe that the best solution is a curated platform-specific solution around Shimming. However, I also agree that React's link validation (ban javascript:) is lightweight and works for 99% of the users. Given that Lexical is heavily inspired in React I think it's good having this built-in.

So I'd suggest something like this

<LinkPlugin disableJavaScriptURLs={true} />

And this can work in 2 different ways. 1) URL overwritten 2) Overwritting click handler. Preferably the first.

@acywatson

acywatson commented Apr 17, 2023 •

Copy link
Copy Markdown
Contributor Author

<LinkPlugin disableJavaScriptURLs={true} />

This won't work for non-React users. Also doesn't address all the other ways a LinkNode can get into the editor (Markdown, setEditorState, custom plugin etc, etc)

internally we use a shimming approach that will kick in when moving to external non-Meta owned sites. Other people may be OK without a shimmer.

I believe that the best solution is a curated platform-specific solution around Shimming.

This is a solution for a different problem, I think. It doesn't make sense to ask every user to implement shimming just to avoid this vulnerability.

@acywatson

Copy link
Copy Markdown
Contributor Author

We can consider either putting this in LinkNode.createDOM or in the reconciler.

@acywatson

Copy link
Copy Markdown
Contributor Author

Closed in favor of #4342

@acywatson acywatson closed this Apr 17, 2023
@zurfyx
zurfyx deleted the sani-links branch February 28, 2025 18:20

This branch was successfully deployed

2 active deployments
Preview – lexical-playground — 239d1d29 Deployed Apr 14, 2023 by vercel[bot]
Preview – lexical — 239d1d29 Deployed Apr 14, 2023 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants