【发布时间】:2016-01-19 10:22:04
【问题描述】:
我的应用程序中的静态文件已上传到 GCS 并设置为公共链接。
当请求静态资源(在本例中为字体)时,它会点击像 https://example.com/static/fonts/font.woff 这样的 url
然后服务器将请求重定向到要服务的适当 GCS url。
这里的问题是使用 chrome 我得到了这个 CORS 问题:
xxxxxxxxe3b8ccc0e3:1 Font from origin 'https://storage.googleapis.com' has been blocked from loading by Cross-Origin Resource Sharing policy: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'https://example.com' is therefore not allowed access.
存储桶和所有子文件夹的 CORS 默认设置如下:
[{"origin": ["*"], "responseHeader": ["Content-Type"], "method": ["GET"], "maxAgeSeconds": 3600}]
问题是这个凭据标志设置在哪里? 我确实重定向到公共链接,因此它不是 ajax 请求,该链接位于 css 文件的字体声明中。
也不能将源设置为特定域或域列表,因为我的应用是多租户的,并且有多个不同的域访问同一个文件。
当请求来自http 时,这似乎可以正常工作,但在https 上时会出现此错误
这在 safari 中也可以按预期工作,但在 chrome 中没有。
【问题讨论】:
-
你是如何加载字体的?你在 CSS 文档中使用@font-face 吗?
-
@BrandonYarbrough 是的,正确。
@font-face {...} -
我无法重现此问题。您能否粘贴您从 storage.googleapis.com 获得的请求/响应(删除身份验证内容?)我使用您创建的确切 CORS 策略创建了一个网络字体,但没有看到这个问题:yarbrough-cors-test.storage.googleapis.com/index.html
-
您可以在这里轻松查看:toteme-nyc.com/shop/aw15 将商品添加到购物车并导航到结帐页面。显然是镀铬
-
啊!相信你可能已经发现了 Chrome 的 bug,见:code.google.com/p/chromium/issues/detail?id=544879
标签: css google-chrome fonts cors google-cloud-storage