有没有可能到沙盒用户提交的Javascript通过覆盖各种功能,例如alert,window.location和eval?
我不是在寻找一个完美的解决方案.我敢肯定有些人仍然会找到一种方法来重新排列div来拼出脏话或恶意的东西,但如果我可以100%可靠地禁用页面重定向,我会非常高兴.
我在Chrome中试过,并做了类似的事情
context={}; //use this to prevent `this` from being `window`
context.f=function(){
var window=null,location=null,eval=function(){};
console.log(window); //also the other two
};
context.f();
Run Code Online (Sandbox Code Playgroud)
似乎很有希望 如果我console用用户提交的代码替换该行(检查平衡),这是一个荒谬的坏主意还是一个有点不好的主意?在Chrome上,我仍然可以通过this功能和重新定义来解决问题,但这对我来说是可以接受的.