首页 > 解决方案 > 内容安全策略框架祖先在 IE 11 中不起作用

问题描述

目的是阻止其他网站在 iframe 中显示我们网站的内容。

X-Frame-Options = SAMEORIGIN由于网站的 URL,我无法使用。主要为 www.xyz.com,次要为 sec.xyz.com。

所以我求助于内容安全策略(...代表其他域等)

<httpProtocol>
            <customHeaders>
                <add name="Content-Security-Policy" value="default-src 'self' localhost ...; script-src 'unsafe-inline' 'unsafe-eval' *;               style-src 'unsafe-inline' *; img-src * data; font-src * data:;               frame-ancestors 'self' localhost ...;" />
            </customHeaders>
        </httpProtocol>

FF 和 Chrome 不会在测试页面 iframe 中显示网站。

在此处输入图像描述

现在 IE 11 显示 iframe 内的站点,因为不支持 frame-ancestors。https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors

我尝试X-Content-Security-Policy在全局文件中添加标题,但 IE 11 仍然显示该站点。

protected void Application_BeginRequest(object sender, EventArgs e)
    {
        HttpContext.Current.Response.AddHeader("X-Content-Security-Policy", "frame-ancestors 'self' localhost ...");
    }

在此处输入图像描述

如何使 IE 11 遵守标题X-Content-Security-Policy

标签: asp.netcontent-security-policy

解决方案


IE 不frame-ancestors支持X-Content-Security-Policy. 使用X-Frame-Options和使用ALLOW-FROM.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options


推荐阅读