阻止脚本更改document.location.href?

use*_*986 2 javascript xss jquery

我刚刚浏览过的网站(cheezburger.com)显然存在漏洞,因为有人在<script>document.location.href="http://net-cheezburger.cu.cc/"</script>邮件中注入了一些内容.Firefox重定向到那里,X-Frame-Options停止了框架,导致空屏幕.

是否有其他方法可以阻止脚本在Firefox中工作,而不是在cheezburger网站上向document.location.href添加CAPS策略?这也阻止了合法的变化.现在我只是告诉Greasemonkey一个脚本在错误的地方,所以如果他们尝试其他恶意脚本,我立即知道发生了什么.

我想在网站本身修复之前暂时修复.

我想知道有没有办法以编程方式拦截该脚本或重定向.如果我已经正确理解你不能用Greasemonkey更改内联脚本但是还有其他选择吗?

Ren*_*non 10

由于您使用的是firefox(现代浏览器),因此可以使用Object.freezelocation对象转换为只读:

Object.freeze(document.location);

document.location.href = "http://google.com";
// No navigation happens

console.log(document.location.href);
// => "http://stackoverflow.com/questions/22290948/stopping-script-from-changeing-document-location-href"
Run Code Online (Sandbox Code Playgroud)

  • 在 Firefox 64.0 上,您无法使用“Object.freeze”,您会收到错误“TypeError:无法阻止此代理对象上的扩展”。 (3认同)