【发布时间】:2012-09-05 10:10:32
【问题描述】:
我想知道host only cookie 是什么。
在检索form auth 时,浏览器会在标头中获取一个显示为host only 的JSESSIONID cookie。
【问题讨论】:
标签: jakarta-ee cookies jsessionid
我想知道host only cookie 是什么。
在检索form auth 时,浏览器会在标头中获取一个显示为host only 的JSESSIONID cookie。
【问题讨论】:
标签: jakarta-ee cookies jsessionid
首先,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 属性,则 cookie 将使用域 www.example.com 设置,并且 cookie 将是主机专用 cookie。
另一个例子:如果cookie是由www.example.com设置的,并且Domain属性被指定为example.com(所以cookie也会被发送到foo.example.com),那么cookie将被设置为域@987654340 @(或者可能是 .example.com,某些浏览器使用之前 RFC 2109 中的点来表示 not host-only)并且 cookie 将 not 仅是 host饼干。
关于 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.
因此,域 example.com 和 host-only 为 false 的 cookie 被发送到 foo.example.com 。如果 host-only 为真,则 example.com cookie 仅发送到 example.com。
【讨论】:
example.com 和host-only 为false 的cookie 被发送到foo.example.com。如果host-only 是true,则example.com 仅发送到example.com。”
Host Only cookie 意味着 cookie 应该由浏览器处理到服务器only到首先发送到浏览器的同一主机/服务器。
您不想为广告活动发送此主机专用 cookie,因为它可能包含敏感信息。
【讨论】:
cookie 的 host-only-flag 为 true,并且规范化的 request-host 与 cookie 的域相同。
【讨论】: