【问题标题】:Add CSP header to Google Cloud Storage将 CSP 标头添加到 Google Cloud Storage
【发布时间】:2020-04-17 09:19:48
【问题描述】:

我正在通过 Google Cloud Storage 存储桶提供 SPA(Vue 应用)。 我正在尝试配置 Google Cloud Storage 存储桶以添加 CSP 响应标头。 (Content-Security-Policy: default ...)

我尝试了以下方法,但没有成功:

1。使用gsutil 添加标题

运行以下:

gsutil setmeta -h "Content-Security-Policy:${CSP}" gs://{BUCKET_NAME}/index.html

但这会返回以下响应:

CommandException: Invalid or disallowed header (Content-Security-Policy).
Only these fields (plus x-goog-meta-* fields) can be set or unset:
[u'cache-control', u'content-disposition', u'content-encoding', u'content-language', u'content-type']

似乎标准不允许添加此标头。

2。添加带有 gsutil 前缀的自定义标头

然后我继续听从他们的建议,并在前面加上 x-goog-meta-*,希望他们自己将其转换回 Content-Security-Policy。运行以下命令:

gsutil setmeta -h "x-goog-meta-Content-Security-Policy:${CSP}" gs://{BUCKET_NAME}/index.html

..给出以下响应:

Setting metadata on gs://{BUCKET_NAME}/index.html...
/ [1 objects]                                                                   
Operation completed over 1 objects. 

所以这行得通。但是在检查响应标头时,他们没有将其更改为 Content-Security-Policy 标头:

所以现在我有点不知道如何为 Google 存储桶启用这个 CSP 标头。 我错过了什么?或者这根本不可能?

提前致谢。

【问题讨论】:

  • 遗憾的是目前不可能

标签: google-cloud-platform google-cloud-storage content-security-policy


【解决方案1】:

目前,Google Cloud Storage 不接受海关标题,只接受 headers included in the documentation

对此有一个公开功能请求,您可以在here 中关注。

【讨论】:

    【解决方案2】:

    在您的 SPA 的 <head> 标签内使用以下标签来启用 Content-Security-Policy

    <meta http-equiv="Content-Security-Policy" content="default-src https:">
    

    如需更多信息,请参阅以下内容:

    Mozilla: The Document-level Metadata element

    Mozilla: Content-Security-Policy

    【讨论】:

      【解决方案3】:

      bucket级别不支持,但是Load Balancer级别支持,查看官方Cloud Storage Documentation

      【讨论】:

        猜你喜欢
        • 2017-07-11
        • 2020-04-12
        • 2020-11-20
        • 2017-04-02
        • 2018-04-30
        • 2018-04-22
        • 2017-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多