Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally sanitize links rendered by the links extension #2169

Closed

Conversation

joelreske
Copy link

closes #2068

  • Allows a sanitize function to be provided to the links extension, with a quick explanation of why it's important
  • Adds sanitization with a common library for the demo

@netlify
Copy link

netlify bot commented Nov 16, 2021

✔️ Deploy Preview for tiptap-embed ready!

🔨 Explore the source changes: 1d66d08

🔍 Inspect the deploy log: https://app.netlify.com/sites/tiptap-embed/deploys/61943d8d099c560007d1656a

😎 Browse the preview: https://deploy-preview-2169--tiptap-embed.netlify.app

@hanspagel
Copy link
Contributor

Thanks! Naive question: Is it a good idea to do this on every re-render? Or should this be done initially and then as part of the commands?

@joelreske
Copy link
Author

joelreske commented Nov 17, 2021

Hi! A bit of a tradeoff - I think having it in the render step is the safest. There would be no way to get around it, whereas I think with commands if a new one was registered they would all have to take sanitization into account? Definitely could be wrong there though.

In terms of performance, I'd be interested in a caching option (could save the key and resolved value on the mark object I think?).

These sanitize functions are really meant to be very simple string operations (example here) so I'm not very concerned but it might be good.

@philippkuehn
Copy link
Contributor

Hmm, alternatively it would be possible to track every inserted link (as a plugin – not within commands) so we can sanitize it once if needed. With your solution a malicious link would still be present in the document forever. What do think?

@joelreske
Copy link
Author

Hmm, alternatively it would be possible to track every inserted link (as a plugin – not within commands) so we can sanitize it once if needed. With your solution a malicious link would still be present in the document forever. What do think?

An interesting idea! I do think that we could solve a similar problem by having a way of generally sanitizing stored documents, potentially on edit, but I do think of this solution being a bit differently.

This PR is really meant to be a 'last line of defense' for harmful links, the user of the option shouldn't have to worry about whether a sanitization step was done before the document being rendered was stored. The concern with XSS is not so much that we always guarantee sanitized data in our DB, but rather that we are protected from malicious data that might find its way somehow into our system when rendering.

Does that distinction make sense for what you were thinking? I think that we could theoretically add both and we'd be addressing two separate but important things.

@franciscolourenco
Copy link

franciscolourenco commented Mar 29, 2022

@joelreske thank you for the PR!

Any ETA to adopt this PR? And shouldn't TipTap be safe agains XSS by default, instead of providing this protection as an option which is off by default?

@franciscolourenco
Copy link

franciscolourenco commented Apr 5, 2022

Sanitization on link insertion wouldn't solve this issue, if sanitization is not done server side. Another option would be to pass the whole html by a library like DOMPurify, before passing it to TipTap.

Any ETA for the adoption of this PR or an equivalent solution? Thanks!

@joelreske
Copy link
Author

Hi @franciscolourenco , I need to put together another version of this which caches so that it's not computing every render.

I do think that TipTap should provide this behavior by default, but I think users should have the option of disabling or replacing the sanitization function.

In terms of server-side sanitization, note from earlier:

The concern with XSS is not so much that we always guarantee sanitized data in our DB, but rather that we are protected from malicious data that might find its way somehow into our system when rendering.

@bkempe
Copy link

bkempe commented Jun 1, 2022

@bdbch I wonder about the state of this?

@franciscolourenco
Copy link

As a workaround, we are currently using DOMPurify.sanitize(html, { USE_PROFILES: { html: true } }) before passing the html to TipTap.

As a word of caution, @braintree/sanitize-url has disclosed security vulnerabilities, and I wouldn't rely on it to sanitize urls. Moreover, for TipTap's use case, I don't see a reason not to use the simpler and safer alternative, which is to use a protocol whitelist (http://|https://|).

@stale
Copy link

stale bot commented Aug 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Aug 1, 2022
@svenadlung svenadlung removed the stale label Aug 1, 2022
@github-actions github-actions bot added the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label Feb 28, 2023
@github-actions github-actions bot closed this Mar 7, 2023
@bdbch bdbch reopened this Mar 7, 2023
@github-actions github-actions bot removed the Info: Stale The issue or pullrequest has not been updated in a while and might be stale label Mar 8, 2023
@bdbch bdbch added Status: Review Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap. labels Mar 29, 2023
@janthurau
Copy link
Collaborator

fixed by #4602 (Thanks @joelreske for raising this two years ago!)

@janthurau janthurau closed this Nov 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: Open Source The issue or pull reuqest is related to the open source packages of Tiptap.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optionally sanitize links rendered by the links extension
8 participants