【问题标题】:Content Security Policy issues on Google AppEngineGoogle AppEngine 上的内容安全政策问题
【发布时间】:2018-05-03 21:47:11
【问题描述】:

我无法让我的应用程序在 Google AppEngine 上正常运行。我有一个 Flask 应用程序,其内容安全策略 (CSP) 由 flask-talisman 管理

我正在阻止对http://my-project.appspot.com/api/foo 的 API 调用,因为它们违反了“connect-src”政策。对该 URL 的请求类型为 xhr。实际消息如下:

Refused to connect to 'http://review-dot-my-project.appspot.com/api/foo' because it violates the following Content Security Policy directive: "connect-src 'self' *.appspot.com".

在生产中,我的网址是https://my-project.appspot.com

对于评论应用,我的网址是http://review-dot-my-project.appspot.com

在我的评论应用中使用 http 协议,在生产中使用的是 https。

我的CSP的相关部分如下:

...
Talisman(app, content_security_policy={
        'default-src': ["'self'", "*.google.com"],
        ...
        'connect-src': ["'self'", "*.appspot.com"]
    })

我已经尝试过多次迭代我的 CSP 的 connect-src 部分

'connect-src': ["'self'", "*://*.appspot.com"]

'connect-src': ["'self'", "*://*my-project.appspot.com"]

'connect-src': ["'self'", "*.appspot.com"]

'connect-src': ["'self'", "*.appspot.com*"]

我似乎找不到关于通配符如何工作的明确文档。由于 Flask Talisman 来自 Google Cloud Platform 组织,我希望能够找到更多示例

【问题讨论】:

  • 嘿,我遇到了类似的问题,GAE 正在为我(节点)设置 CSP 标头,我在哪里以及如何覆盖它?

标签: python google-app-engine flask google-cloud-platform


【解决方案1】:

我建议试试这个:

'connect-src': ["'self'", 
                "http://review-dot-my-project.appspot.com", 
                "https://my-project.appspot.com"]

看起来您不需要通配符,而且您的 CSP 越具体越好。

你也可以试试这个:

'connect-src': ["'self'", 
                "http://*.appspot.com", 
                "https://my-project.appspot.com"]

如果您有其他非生产版本的应用。

【讨论】:

  • 在 flex env 上运行的 GAE 项目中,应该在哪里添加这些标头?
猜你喜欢
  • 1970-01-01
  • 2021-08-03
  • 2015-09-05
  • 2021-09-29
  • 2015-07-13
  • 2019-04-15
  • 2023-04-10
  • 2022-08-19
  • 2015-07-22
相关资源
最近更新 更多