我想知道什么是host only
饼干。
在检索form auth
时,浏览器会在头文件中显示一个JSESSIONID cookie,显示为host only
。
首先,foo.com
不可能设置一个可以被bar.com
读取的cookie。 Host-only
只保护example.com
cookie不被bar.example.com
读取。
来自RFC 6265关于设置cookie及其Domain
属性:
If the domain-attribute is non-empty: If the canonicalized request-host does not domain-match the domain-attribute: Ignore the cookie entirely and abort these steps. Otherwise: Set the cookie's host-only-flag to false. Set the cookie's domain to the domain-attribute. Otherwise: Set the cookie's host-only-flag to true. Set the cookie's domain to the canonicalized request-host.
以上可以通过“Host-only is default”来概括。也就是说,如果未指定Domain
,则cookie只能由设置cookie的确切域读取。这可以通过在设置cookie时设置Domain
属性来放宽。
例如,如果cookie由www.example.com
设置且未指定Domain
属性,则将使用域www.example.com
设置cookie,并且cookie将仅是主机cookie。
另一个例子:如果cookie由www.example.com
设置并且Domain
属性被指定为example.com
(因此cookie也将被发送到foo.example.com
),cookie将被设置为域example.com
(或者某些浏览器使用点来自.example.com
)之前的RFC 2109表示不是仅限主机的,并且cookie不会是仅限主机的cookie。
第5.4节介绍了有关浏览器发送cookie标头的时间的发送:
The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain. Or: The cookie's host-only-flag is false and the canonicalized request-host domain-matches the cookie's domain.
因此,将foo.example.com
和host-only
作为false的cookie发送给example.com
。如果host-only
为真,则foo.example.com
仅被发送到foo.example.com
。
仅限主机cookie意味着浏览器应将cookie仅处理到服务器,而不是首先将其发送到浏览器的主机/服务器。
您不希望仅为广告系列发送此主机Cookie,因为它可能包含敏感信息。
cookie的host-only-flag为true,规范化的请求主机与cookie的域相同。