Blacklists are a losing game. Always use a whitelist.
This was actually the second fix I had in mind, after the author mentioned that they would like mathjs to have complete browser support (and therefore couldn't use the `vm` module from Node.js): >If, anyway, you want to make math.eval resistant against arbitrary code execution, I think it would be best to have a whitelist of methods and constructs (i.e. you parse the code that is meant to be evaluated and ensure that…
browsers do have isolated contexts these days, they're just cumbersome to use.
1. spawn an iframe with sandbox="allow-script" and srcdoc="........."
2. use window.postMessage to communicate between the parent page and the iframe running in a null origin
3. send code to eval into that iframe