mathjax / MathJax

Beautiful and accessible math in all browsers
http://www.mathjax.org/
Apache License 2.0
10.2k stars 1.16k forks source link

Url sanitization bypass in ui/safe #2885

Open sgoedecke opened 2 years ago

sgoedecke commented 2 years ago

Issue Summary

With ui/safe enabled, it's still possible to render javascript: protocol links by including \n or \r characters in the protocol.

Steps to Reproduce:

Go to this codepen: https://codepen.io/sgoedecke/pen/KKQJyPw

Rendering this notebook with the ui/safe extension will create a link that when clicked executes that JS alert(1) code. Explicitly adding

    safeOptions: {
      allow: { URLs: 'safe' },
      safeProtocols: { http: 'true', https: 'true', javascript: 'false' }
    }

doesn't fix the problem.

Technical details:

I am using the following MathJax configuration:

window.MathJax = {
  loader: {
    load: ['ui/safe']
  }
  };

and loading MathJax via <script src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>

Supporting information:

sgoedecke commented 2 years ago

I've submitted a PR with a fix here: https://github.com/mathjax/MathJax-src/pull/829. If you agree with this fix, I'd like to also port it to the legacy-v2-develop branch.