Phonegap app Content-Security-Policy

时间:2016-12-23 13:17:57

标签: ios cordova content-security-policy phonegap-cli phonegap-developer-app

我用cordova建立应用程序。我使用phonegap serve使用phonegap开发者应用加载应用。

index.html

<meta http-equiv="Content-Security-Policy" content="default-src gap: file: tel: *; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *">

(我也试过没有file: tel:,结果是一样的)

我可以在platforms/browser/www/index.html

中验证是否已正确准备

然后我在iPad上打开phonegap应用程序,运行phonegap serve,打开Safari开发工具,按连接,然后是:

Refused to load gap://ready because it appears in neither the child-src directive nor the default-src directive of the Content Security Policy.

index.html我可以看到该指令已转换为:

<meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'">

有没有办法让ipad正确加载指令?

修改

我还试图在index.html中使用CSP指令编译phonegap app developer,结果是一样的

编辑 - 1

我还从http://192.168.1.130:3200/__api__/appzip下载了zip文件(这是我拥有phonegap serve服务器的地方),index.html已经转换了!

这里奇怪的是platforms/browser/www/index.html没有被转换,所以中间有一些过程正在改变CSP。

在我的config.xml我的指令中:

<content src="index.html" />
<access origin="*" />
<access origin="cdvfile://*" />
<access launch-external="yes" origin="tel:*" />

<!-- Allowed WebView navigations -->
<allow-navigation href="http://*"/>
<allow-navigation href="https://*"/>
<allow-navigation href="http://*/*"/>
<allow-navigation href="https://*/*"/>
<allow-navigation href="data:*"/>
<allow-navigation href="about:*"/>
<allow-navigation href="tel:*"/>
<allow-navigation href="gap:*" />
<!-- Allowed URLs to be opened from the app -->
<allow-intent href="http://*"/>
<allow-intent href="https://*"/>
<allow-intent href="http://*/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="geo:*"/>
<allow-intent href="cdvfile://*" />

1 个答案:

答案 0 :(得分:0)

与此问题有关:https://github.com/creationix/nvm/issues/1361

主要是,bash检测到v6.4.2并指向它(which phonegap指向正确的版本)但是从命令行执行phonegap时,它正在执行v6.0.2,这可能是没有设置正确的CSP。