将 CSP 标头添加到 Google Cloud Storage

2023-12-26

我正在从 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. 

So this works. But upon checking the response headers, they did not alter it to Content-Security-Policy header: enter image description here

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

提前致谢。


目前,Google Cloud Storage 不接受自定义标头,仅接受文档中包含的标题 https://cloud.google.com/storage/docs/xml-api/reference-headers.

有一个公开的功能请求,您可以关注here https://issuetracker.google.com/issues/36427250.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

将 CSP 标头添加到 Google Cloud Storage 的相关文章

随机推荐