什么是主机唯一的cookie?

问题描述 投票:22回答:3

我想知道什么是host only饼干。

在检索form auth时,浏览器会在头文件中显示一个JSESSIONID cookie,显示为host only

java-ee cookies jsessionid
3个回答
44
投票

首先,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.comhost-only作为false的cookie发送给example.com。如果host-only为真,则foo.example.com仅被发送到foo.example.com


11
投票

仅限主机cookie意味着浏览器应将cookie仅处理到服务器,而不是首先将其发送到浏览器的主机/服务器。

您不希望仅为广告系列发送此主机Cookie,因为它可能包含敏感信息。


0
投票

cookie的host-only-flag为true,规范化的请求主机与cookie的域相同。

http://tools.ietf.org/html/rfc6265#section-5.4

© www.soinside.com 2019 - 2024. All rights reserved.