mehdisadeghi / react-mathjax-preview

The MathJax React component you were looking for.
https://mehdisadeghi.github.io/react-mathjax-preview/
MIT License
49 stars 30 forks source link

Component is susceptible to XSS #9

Closed dpikt closed 5 years ago

dpikt commented 6 years ago

I was using this component to render some user input- I didn't realize it was using innerHTML under the hood 😱

For example, you can enter the following into the demo:

<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" onload="document.body.style.backgroundColor = 'red';alert('Im a bunch of arbitrary javascript!!!');">

This is bad news.

I'm not sure if there's a way around this with the way this component currently renders Mathjax, but it should certainly be documented if it's a necessary consideration in using the component.

mehdisadeghi commented 6 years ago

Thanks for reporting @dpikt.

I'll get to it as soon as I can and sanitize the math source before adding it to the DOM. You can beat me to it by a PR of course 😉

mehdisadeghi commented 6 years ago

@dpikt it turns out it is not that easy task. Sanitizing the input will break MathML rendering. I'm looking for a better solution.

mehdisadeghi commented 5 years ago

@dpikt I used DOMPurify to sanitize the inputs. The problem should not happen again.