添加Xframeoptions后,不会发生跨域通信:Sameorigin

时间:2018-08-17 13:04:55

标签: asp.net-mvc iframe cross-domain content-security-policy clickjacking

我正在为我们的网站实施预防Clickjacking的工作。我从添加标题X-Frame-Options开始:sameorigin。使用此工具,我们的网站无法加载到任何其他网站托管的任何iframe中,因此Clickjacking部分可以正常工作。

现在是问题,我们只有几个页面,其中使用iframe加载托管形式的付款网关,该页面利用iframeCommunicator Url选项进行跨域通信。添加X-Frame-Options标头后,托管表单无法与付款网关通信。

我在控制台中遇到以下错误:  拒绝在帧中显示“ http://localhost:44352/examplesite/payment/iFrameCommunicator#action=resizeWindow&width=1106&height=152”,因为它将“ X-Frame-Options”设置为“ sameorigin”。

上述错误是由于我在webconfig中设置的标头如下

<httpProtocol>
  <customHeaders>
      <add name="X-FRAME-OPTIONS" value="SAMEORIGIN" />
  </customHeaders>
</httpProtocol>

我尝试过的其他设置:

<add name="X-Content-Security-Policy" value="frame-ancestors 'self' *.example.net*" /> 

<add name="Content-Security-Policy" value="frame-ancestors 'self' *.example.net*" />

其中 .example.net 是用于获取托管表格的付款网关网址。

1 个答案:

答案 0 :(得分:0)

正在考虑...

  • 您要拒绝将自己的网站伪装成其他网站,但允许将iframe投放到您自己网站中的内容:

    <add name="Content-Security-Policy" value="frame-ancestors 'self';" />

    与旧的X-Frame-Options标头具有相同的作用:

    <add name="X-Frame-Options" value="sameorigin" />

  • 您要允许包含付款网关页面的iframe:

    <add name="Content-Security-Policy" value="frame-src *.example.net;" />

因此,您需要设置两个HTTP标头。请注意,HTTP标头仅添加到您的页面,而不添加到支付提供商页面,它们由另一台服务器提供。

但是...

这不能解释为什么您无法通过将X-FRAME-OPTIONS标头设置为 allow sameorigin来从iframe中的付款网关提供内容,