python - Google AppEngine 上的内容安全政策问题
问题描述
我无法让我的应用程序在 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".
在生产中,我的 URL 是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"]
})
connect-src
我已经尝试了我的 CSP 部分的多次迭代
'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 组织,我希望能够找到更多示例
解决方案
我建议试试这个:
'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"]
如果您有其他非生产版本的应用。
推荐阅读
- mysql - 需要帮助舍入从 python 函数返回的 Mysql 结果
- c# - 您将如何实现将此属性映射到可序列化类对象的一般情况?
- php - 显示在网页加载时执行的 PHP 文件的输出/回显
- php - 如何针对 Laravel 中的任何按钮添加自定义操作?
- android - 无法通过蓝牙成功读取数据
- linux - For循环处理所有学生及其在线状态的列表
- json - 为什么 mongoexport 会生成格式错误的 JSON?
- c# - ThreadPool.SetMaxThreads 不会阻止手动创建更多线程?
- javascript - 使用内容交付网络 (CDN) 托管优于托管文件?
- javascript - 未捕获的类型错误:无法读取 null 的属性“0” - 传单