"Referer" 当用户从覆盖 Chrome 中的新标签的 iframe 中点击 link 时,header 丢失
"Referer" header is missing when user clicks on a link from inside an iframe that overrides a newtab in Chrome
问题
这是浏览器的预期行为吗?
相关的 Chromium 错误
https://code.google.com/p/chromium/issues/detail?id=492761
步骤
为 Chrome
创建一个 empty extension
将新标签覆盖到 manifest.json
:"chrome_url_overrides": {"newtab": "newtab.html"}
创建 newtab.html
(chrome-extension://<extension_id>/newtab.html
),创建一个 iframe 并将一些页面加载到其中,例如https://<some_page>.com/
将 link 添加到该页面,例如https://example.org/
- 单击 link 并观察请求
预期结果
"Referer" header 应该存在,例如:
GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36
Referer: https://<some_page>.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4
Cookie: ...
实际结果
没有"Referer" header:
GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4
Cookie: ...
“chromium.org 的 eroman”将其钉牢(参见 linked chromium 错误报告,已经关闭)。
问题是,如果 iframe 包含安全 (https) 页面,但 iframe 本身包含在非安全页面中(在本例中替换 Chrome newtab),则非安全 ( http) 当用户从该 iframe 中单击 link 时发出请求。
RFC 2616 section 15.1.3 说的步骤:
Clients SHOULD NOT include a Referer header field in a (non-secure)
HTTP request if the referring page was transferred with a secure
protocol.
这使得所描述的情况成为所需的情况,因此浏览器的行为符合标准。
此外,如果 link 指向一个不安全的页面,例如http://example.org/,这将是一个正常的(非安全的)http 请求,因此“Referer”将被省略 - 只是因为引用页面是安全的。当然,即使没有 iframe 包装安全页面,这仍然有效。
问题
这是浏览器的预期行为吗?
相关的 Chromium 错误
https://code.google.com/p/chromium/issues/detail?id=492761
步骤
为 Chrome
创建一个 empty extension
将新标签覆盖到
manifest.json
:"chrome_url_overrides": {"newtab": "newtab.html"}
创建
newtab.html
(chrome-extension://<extension_id>/newtab.html
),创建一个 iframe 并将一些页面加载到其中,例如https://<some_page>.com/
将 link 添加到该页面,例如
https://example.org/
- 单击 link 并观察请求
预期结果
"Referer" header 应该存在,例如:
GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36
Referer: https://<some_page>.com/
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4
Cookie: ...
实际结果
没有"Referer" header:
GET / HTTP/1.1
Host: example.org
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.65 Safari/537.36
Accept-Encoding: gzip, deflate, sdch
Accept-Language: en-US,en;q=0.8,de;q=0.6,ru;q=0.4
Cookie: ...
“chromium.org 的 eroman”将其钉牢(参见 linked chromium 错误报告,已经关闭)。
问题是,如果 iframe 包含安全 (https) 页面,但 iframe 本身包含在非安全页面中(在本例中替换 Chrome newtab),则非安全 ( http) 当用户从该 iframe 中单击 link 时发出请求。
RFC 2616 section 15.1.3 说的步骤:
Clients SHOULD NOT include a Referer header field in a (non-secure)
HTTP request if the referring page was transferred with a secure
protocol.
这使得所描述的情况成为所需的情况,因此浏览器的行为符合标准。
此外,如果 link 指向一个不安全的页面,例如http://example.org/,这将是一个正常的(非安全的)http 请求,因此“Referer”将被省略 - 只是因为引用页面是安全的。当然,即使没有 iframe 包装安全页面,这仍然有效。