Firefox 不遵守 RFC6265 关于处理 cookie 的路径属性

Firefox is not complying with RFC6265 regarding processing the path attribute of cookies

我正在写一个 PHP class 用于处理 with/parsing CookieSet-Cookie HTTP headers 在我的自定义 user-agents(爬虫、爬虫、机器人等),在测试它时我发现它在处理 Set-Cookie Path 属性的方式上与 Firefox 不同。 =102=]。我回到了RFC 6265,我是对的

###如何重现? 在任何 PHP 文件中设置此行并请求它

<?php
header("set-cookie: foo=1; path=/bar/", true);
exit;

现在用 Firefox 请求 /bar,您会看到 Firefox 正在发送 cookie,而根据规范它应该只发送到 /bar/ 或更长的路径!!

###规格是多少?

我会引用RFC 6265 5.1.4 Paths and Path-Match

中的相关部分

A request-path path-matches a given cookie-path if at least one of the following conditions holds:

o The cookie-path and the request-path are identical.

o The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").

o The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie- path is a %x2F ("/") character.

在这种情况下 request-path /bar 和 cookie-path /bar/ 不 path-match

### Google Chrome 呢?

Google Chrome 不会 将 cookie 发送到 /bar

我的问题

Who is right ? Chrome ? or Firefox ?

###额外的细节:

我在 Linux 和 Chrome 版本 76.0.3809.132 Linux

上测试了 Firefox 66.0.4

这是我在 class

中使用的相关函数
public static function isPathMatch(string $requestPath, string $cookiePath)
{
    if ($requestPath === $cookiePath) return true;
    if (strpos($requestPath, $cookiePath) !== 0) return false;
    if (substr($cookiePath, strlen($cookiePath) - 1, 1) === "/") return true;
    if (substr($requestPath, strlen($cookiePath), 1) === "/") return true;
    return false;
}

这是我 Firefox 的第二期,但它仍然是我最喜欢的浏览器:)

感谢@fendall 对 RFC 的评论,我跟踪了与此问题相关的 RFC

MDN Set-Cookie 文档 使用了 RFC 6265draft-ietf-httpbis- rfc6265bis-02 和“路径和 Path-Match”部分中的两个规范几乎相同。 (我在问题中引用的部分

我向 Bugzilla 报告了一个错误 https://bugzilla.mozilla.org/show_bug.cgi?id=1579552

是的,Chrome 是正确的,正如 ehsan akhgari 在错误报告中评论的那样

Yes, our path matching algorithm is completely different than the spec. Comparing to Chrome's they seeming to be following the spec pretty closely.

...他们更改了 Firefox 的源代码并修复了它 https://phabricator.services.mozilla.com/D45427