防止网站被注入 iframe - 服务器和客户端验证

prevent website to be injected in iframe - server and client validation

我正在开发 asp.net mvc 网站并希望实现一些安全功能。其中之一是防止网站被注入 iframe。我读过可以使用服务器端验证的 x-frame-options 来做到这一点,但我也读过它也需要用 JS 实现客户端验证。有人可以帮我吗?非常感谢!!

可以使用破坏 JS 完成客户端验证。 要实现服务器端验证,您需要(正如您已经提到的)在 IIS 或应用程序(全局 asax 文件)中设置 x-frame-options:

IIS:

<httpProtocol>
  <customHeaders>
    <add name="X-Frame-Options" value="DENY" />
  </customHeaders>
</httpProtocol>

全球asax:

protected void Application_BeginRequest(object sender, EventArgs e)
{
  HttpContext.Current.Response.AddHeader("x-frame-options", "DENY");
}

有关破坏 js 的更多信息,请参阅此 link: https://www.owasp.org/index.php/Clickjacking_Defense_Cheat_Sheet

老版浏览器也有同样的问题,比如mozilla 3.0

希望对您有所帮助!