没有名字的饼干?

Cookie without a name?

以下 cookie 是怎么回事:

"=value"

在 Chrome 和 Firefox 中,这等同于:

"value"

即空 cookie 名称的值变为 cookie 名称。

这种行为有任何官方原因吗?

它看起来像一个错误,因为 rfc 说:

  1. If the name string is empty, ignore the set-cookie-string entirely.

cookie RFC 标准在某些地方有点模糊和矛盾,并且在各种修订中也改变了行为。因此,就 cookie 的要求而言,浏览器也有不同的行为。所以简而言之,对于某些浏览器来说,一个空的 cookie 名称是可以的,而对于其他浏览器则不行。如果这是您正在构建的应用程序(您希望在各种浏览器上工作),那么设置 cookie 名称可能是最安全的。

https://www.rfc-editor.org/rfc/rfc6265#section-5.2

   5.  If the name string is empty, ignore the set-cookie-string
       entirely.

https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-05#section-5.3

   2.  If the name-value-pair string lacks a %x3D ("=") character, then
       the name string is empty, and the value string is the value of
       name-value-pair.

       Otherwise, the name string consists of the characters up to, but
       not including, the first %x3D ("=") character, and the (possibly
       empty) value string consists of the characters after the first
       %x3D ("=") character.

我今天偶然发现了同样的问题。

澄清@buffoonism 的答案...

https://whosebug.com/a/72250741/2323764

必须忽略set-cookie header。