内容安全-政策(CSP)的解决方法为Internet Explorer

问题描述 投票:5回答:5

我们正在建设一个ASP.NET网站,并希望只允许某些领域谁可以iFrame我们的网站。 CSP是无法在Internet Explorer的支持。我设置类似Response.AddHeader("Content-Security-Policy", "frame-ancestors mydomain1.com mydomain2.com")

大家是怎么处理的Internet Explorer。我读IE支持X-Content-Security-Policy,但它不具有frame-ancestors

此外,我除去默认的X型框架,选项首部由IIS添加做

Response.Headers.Remove("X-Frame-Options")
internet-explorer iframe content-security-policy
5个回答
8
投票

通过Microsoft推荐的解决方案如下:

  1. 在内部,白名单domain1.com和domain2.com
  2. 嵌入你的iframe网址时,加在URL参数指定的由来:IFRAME SRC =“http://example.org/frame.html?origin=http://domain1.com”
  3. 您的服务器上,检查原点值列入白名单。用它来设置X框-选项:允许-FROM http://domain1.com

你也可以检查Referer标头(如果存在)。


4
投票

X-框架,选项是由内容安全,政策所取代,但正如你所说,并不是所有的浏览器完全支持内容安全-政策呢。

你说你是故意删除X框的选项,但你不应该。这是通过Internet Explorer支持,所以如果你除了内容安全,政策使用它,你会得到在更宽范围的浏览器相同的效果。

见X框,选择文件在这里,其中包括IE支持一提:https://developer.mozilla.org/en-US/docs/Web/HTTP/X-Frame-Options


1
投票

的Internet Explorer 8至11只支持X框的选项,并且可以使用允许-FROM值。指定您的I帧的网址中。

请记住只有最新的Internet Explorer浏览器支持X-内容安全-政策。


1
投票

X-内容安全,政策适用于IE浏览器,使用https://content-security-policy.com/browser-test/测试CSP支持的浏览器

片段中明确将如下所示:

function applyCSPforIE(req, res, next) {
    res.setHeader('X-Content-Security-Policy', 'frame-ancestors \'self\' http://whatever.com/');
    next();
}

你可以同时使用这两个和它的作品,但有一个在这个article关于它的警告。


1
投票

下面的Apache配置对我的作品在所有主要的浏览器(2018年4月):

<IfModule mod_headers.c>

    Header set Content-Security-Policy "frame-ancestors http://*.example.com/ 'self';"

    # For IE 11 and below
    Header set X-Frame-Options SAMEORIGIN
    Header append X-Frame-Options "ALLOW-FROM http://example.com/" </IfModule>
© www.soinside.com 2019 - 2024. All rights reserved.