【发布时间】:2021-04-02 15:08:26
【问题描述】:
我正在将 create-react-app 迁移到 Apache Cordova。我的静态图像的相对 URL 正在工作。例如:./images/path/to/file.jpeg
但在 iOS 模拟器中,我无法在 S3 存储桶中引用远程图像源。例如://s3-us-west-2.amazonaws.com/bla/bla/bla/8CCE-B64FD7247407.jpeg?1617374606
我认为这是一个安全配置问题,但我不确定。这是我的 config.xml 文件中当前的内容:
<access origin="*" allows-local-networking='true' />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<allow-intent href="*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
<allow-intent href="*" />
</platform>
我的 index.html 文件中目前没有 <meta http-equiv="Content-Security-Policy" content="...">。
我做错了什么?
更新 1 和 2
我尝试更新我的 config.xml 文件以包含:
<allow-intent href="//:*/*" />
<access origin='*' allows-arbitrary-loads-for-media='true' allows-arbitrary-loads-in-web-content='true' allows-local-networking='true' />
很遗憾,这不起作用。
就像@DaveAlden 建议的那样,看起来这可能是一个 CSP 问题...
我的原始 index.html 文件根本不包含 Content-Security-Policy 元标记,但是当我在浏览器中运行 cordova 应用程序并查看源代码时。这是我看到的:
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval' 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
现在我想我的问题是:CSP 来自哪里?还有,如何修改?
有一段时间我一直在摸索为什么远程图像在浏览器中工作,因为我的理解是img-src 'self' 应该不允许<img src="//:bla-bla.amazonaws.com/bla/bla" />。我认为部分解释是,当我使用开发工具检查文档的<head> 时,我看到的 CSP 标记与查看源代码时不同。
??????在运行cordova run ...之前,此 CSP 与我当前在 index.html 文件中的内容相匹配。
似乎 Cordova 以某种方式为 iOS 使用了不同的默认 CSP,但不知何故在浏览器中覆盖了它。我很困惑。
** 更新 3**
我搜索了我的项目文件,发现神秘的 CSP(我在浏览器中看到的)与 cordova-plugin-whitelist README 中列出的默认“模板”策略相匹配。
【问题讨论】:
-
@DaveAlden 我的 index.html 中目前没有 CSP 元标记。我认为这会导致最大的宽容度。这不正确吗?
-
@DaveAlden 我用更多与 CSP 相关的线索更新了问题。好像是被神秘地注入了……
标签: cordova phonegap content-security-policy