iframe无法在iOS中加载

时间:2017-11-01 22:32:14

标签: ios iphone iframe content-security-policy

我的网络应用有一个iframe:

<div id="iframe-wrapper" class="iframe-wrapper">
  <iframe src="https://xxx.company.com/aaa/bbbb/cccc" style="border:none; height: 100%; width : 100%; scrolling: no;">
    <p>Your browser does not support iframes.</p>
 </iframe>
</div>

它可以在Windows桌面和Android设备的任何浏览器中正常工作(已加载url)但在iOS和MacOS中没有(在MacOS上的Chrome除外)。

在iOS - iPad / iPhone - Safari中,我在控制台中看到此错误

refuse to load https://xxx.company.com/aaa/bbbb/cccc because it appears in neither the child-src directive nor the default-source directive of the content security policy 

我做了研究,发现它与内容安全政策有关,所以我用这个

<meta http-equiv="Content-Security-Policy" content="
  default-src https://*.company.com;
  child-src     https://*.company.com;
  frame-src     https://*.company.com;">

<meta http-equiv="Content-Security-Policy" content="
   default-src * data: blob: ws: wss: gap://ready ;
   style-src * 'unsafe-inline'; 
   script-src * 'unsafe-inline' 'unsafe-eval';
   connect-src * ws: wss:;
   child-src * https://*.company.com gap://ready;
   frame-src * https://*.company.com gap://ready">

它们都不起作用。你能帮我把它搞定吗?

更新: 这是我在ipad safari(iOS 10.2.1)和MacOS -Safari(最新版本)的响应标题中看到的内容。他们两个都不允许加载iframe URL

X-Frame-Options  sameorigin
X-XSS-Protection 1;mode=block
X-Content-Type-Options   nosniff
X-Webkit-CSP  default-src 'self'

但我也在MacOS和Chrome上看到相同的标题(macbook pro最新版本),Chrome允许在MacOS上加载iframe而不会出现问题。

1 个答案:

答案 0 :(得分:0)

我根据调查响应标头的想法得到了我的问题的答案。感谢sideshowbaker的回复。

首先,我尝试在jsp文件中的标头元标记中设置“Content-Security-Policy”。但那个不起作用。 所以我尝试在控制器中设置服务器端(spring MVC)的头值。它工作正常。

public ModelAndView confirmNumber(....,HttpServletResponse response) {  
.....
response.setHeader("Content-Security-Policy","style-src * 'unsafe-inline';  script-src * 'unsafe-inline' 'unsafe-eval'; connect-src *; default-src *; child-src * https://*.company.com; frame-src  * https://*.company.com;");

return modelView;
}

现在,通过safari中的Web Inspector,我可以看到标题值。

相关问题