【问题标题】:Stopping script from changing document.location.href?阻止脚本更改 document.location.href?
【发布时间】:2014-04-13 00:17:23
【问题描述】:

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

除了在 cheezburger 网站上的 document.location.href 中添加 CAPS 策略之外,还有其他方法可以阻止脚本在 Firefox 中运行吗?这也阻止了合法的更改。 现在我只是提醒 Greasemonkey 一个脚本在错误的地方,所以我可以立即知道如果他们尝试其他恶意脚本会发生什么。

我只想要一个临时修复,直到网站本身修复为止。

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

【问题讨论】:

  • 不确定这是否与编程有关。
  • 不确定这是否真的可以纯粹使用 js,任何你可以在 JS 中实现的东西都可能被其他人轻松实现......这就是清理插入到数据库中的地方。 .. 在进入数据库的路上把那些东西去掉
  • net-cheezburger.cu.cc 的主机文件设置为127.0.0.1?我不确定您决定屏蔽的确切标准。

标签: javascript jquery xss


【解决方案1】:

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

【讨论】:

  • 这也会阻止 OP 希望允许的合法使用。
  • 在 Firefox 64.0 上你不能使用 Object.freeze,你会得到一个错误 TypeError: can't prevent extensions on this proxy object
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-12-31
  • 1970-01-01
  • 2020-01-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-01
相关资源
最近更新 更多