停止脚本更改document.location.href

Stopping script from changing document.location.href?

本文关键字:document location href 脚本      更新时间:2023-09-26

我刚刚浏览过的一个网站(cheezburger.com)显然有漏洞,因为有人在消息中注入了<script>document.location.href="http://net-cheezburger.cu.cc/"</script>之类的行。Firefox将自己重定向到那里,X-Frame-Options停止帧,导致空屏幕。

除了在cheezburger站点的document.location.href中添加一个CAPS策略之外,还有其他方法可以阻止脚本在Firefox中工作吗?这也阻碍了合法的变革。现在我只是警告Greasemonkey脚本在错误的地方,所以如果他们尝试其他恶意脚本,我可以立即知道发生了什么。

我只是想临时修复,直到网站本身修复。

我想知道是否有办法以编程方式拦截该脚本或重定向。如果我理解正确,你不能改变内联脚本与Greasemonkey,但有其他选择吗?

由于您使用的是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"