假设一个站点有两个文档:index.html和test.jpg,它们都位于根目录。index.html有以下内容。
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta content="text/html; charset=utf-8" http-equiv=content-type>
<title>Test</title>
</head>
<body>
<p>Hello.</p>
<img src="/test.jpg">
</body>
</html>如果在没有安全头的情况下服务,这是很好的工作。但是,在index.html上使用这些标头
Cross-Origin-Embedder-Policy: require-corp
Cross-Origin-Opener-Policy: same-origin以及test.jpg上的这个标头
Cross-Origin-Resource-Policy: same-origintest.jpg将不再由Chrome 98加载。它在控制台中报告net::ERR_BLOCKED_BY_RESPONSE.NotSameOrigin 200。
将以下标题添加到index.html中也会导致图像被Firefox 97阻塞:
Content-Security-Policy: default-src 'none'; style-src 'self'; img-src 'self'; prefetch-src 'self'; frame-ancestors 'none'; form-action 'none'; upgrade-insecure-requests; block-all-mixed-content; disown-opener; sandbox; base-uri 'none'(我知道这是很多指令,但我试图把它们一分为二,但我无法理解。)
这里发生了什么?https://example.com和https://example.com/test.jpg是同一个起源,不是吗?显式导航到https://example.com/index.html也会阻止test.jpg的加载。我对同一来源的理解中缺少了什么?为什么Chrome和Firefox的处理方式有区别?为什么添加CSP会导致Firefox开始阻塞对test.jpg的请求
如果我遗漏了什么,下面是每个请求的完整标题集(来自cURL):
> GET / HTTP/2
> Host: example.com
> user-agent: curl/7.77.0
> accept: */*
>
< HTTP/2 200
< date: Wed, 16 Feb 2022 04:56:43 GMT
< server: Apache
< via: e3s
< last-modified: Wed, 16 Feb 2022 04:43:18 GMT
< content-length: 226
< x-content-type-options: nosniff
< referrer-policy: same-origin
< content-security-policy: default-src 'none'; style-src 'self'; img-src 'self'; prefetch-src 'self'; frame-ancestors 'none'; form-action 'none'; upgrade-insecure-requests; block-all-mixed-content; disown-opener; sandbox; base-uri 'none'
< cross-origin-embedder-policy: require-corp
< cross-origin-opener-policy: same-origin
< etag: "e2-5d81b49ddfad8"
< accept-ranges: bytes
< vary: Accept-Encoding
< content-type: text/html; charset=UTF-8
<> GET /test.jpg HTTP/2
> Host: example.com
> user-agent: curl/7.77.0
> accept: */*
>
< HTTP/2 200
< date: Wed, 16 Feb 2022 04:52:19 GMT
< server: Apache
< x-content-type-options: nosniff
< referrer-policy: same-origin
< cross-origin-resource-policy: same-origin
< last-modified: Wed, 16 Feb 2022 04:22:59 GMT
< etag: "18692-5d81b013bbe82"
< accept-ranges: bytes
< content-length: 99986
< cache-control: public, max-age=31557600, immutable
< age: 336
< via: e2s
< content-type: image/jpeg
<发布于 2022-02-16 07:57:59
我并没有尝试复制,但是从阅读这篇文章来看,火狐开始屏蔽文档是有意义的,这意味着它有一个不透明的来源,因此图像会出现交叉原点。
至于Chrome,在某种程度上,沙箱也会存在吗?
https://stackoverflow.com/questions/71136656
复制相似问题