【问题标题】:Why cookie received in "Set-Cookie" response not sent in next request (only FireFox)?为什么在“Set-Cookie”响应中收到的 cookie 未在下一个请求中发送(仅限 FireFox)?
【发布时间】:2020-09-10 01:18:39
【问题描述】:

我在尝试登录服务器时遇到了这个问题(在我的本地网络上运行)。使用 Chrome/Edge 时登录效果很好,但在 FireFox 上失败。

在浏览器 devtools/wireshark 中,当我访问登录页面时,我看到服务器发送了一个 cookie _oauth2_proxy_csrf。这个 cookie 应该包含在我的浏览器到服务器的所有未来请求中。

在铬上

来自服务器的响应

Server: nginx/1.15.7
Date: Sun, 05 Jul 2020 12:18:43 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 281
Location: http://192.168.0.101/oauth2/oauth2/auth?approval_prompt=force&client_id=oauth2-proxy&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-proxy%2Fcallback&response_type=code&scope=openid+email+profile+roles&state=472474af0548b13655fd6e8515f0fc31%3A%2F
Connection: keep-alive
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 UTC
Set-Cookie: _oauth2_proxy_csrf=472474af0548b13655fd6e8515f0fc31; Path=/; Expires=Sun, 12 Jul 2020 12:18:43 GMT; HttpOnly; SameSite=Lax

chrome 下一个请求

GET /oauth2/oauth2/auth?approval_prompt=force&client_id=oauth2-proxy&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-proxy%2Fcallback&response_type=code&scope=openid+email+profile+roles&state=472474af0548b13655fd6e8515f0fc31%3A%2F HTTP/1.1
Host: 192.168.0.101
Connection: keep-alive
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.125 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: _oauth2_proxy_csrf=472474af0548b13655fd6e8515f0fc31

一切正常,如果我继续这个流程,可以登录,但是

在火狐上

来自服务器的响应

HTTP/1.1 302 Found
Server: nginx/1.15.7
Date: Sun, 05 Jul 2020 12:21:33 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 281
Location: http://192.168.0.101/oauth2/oauth2/auth?approval_prompt=force&client_id=oauth2-proxy&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-proxy%2Fcallback&response_type=code&scope=openid+email+profile+roles&state=4b06492a222e53045d0447826a50c47e%3A%2F
Connection: keep-alive
Cache-Control: no-cache, no-store, must-revalidate, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 UTC
Set-Cookie: _oauth2_proxy_csrf=4b06492a222e53045d0447826a50c47e; Path=/; Expires=Sun, 12 Jul 2020 12:21:33 GMT; HttpOnly; SameSite=Lax

Firefox 下一个请求(未设置 cookie)

GET /oauth2/oauth2/auth?approval_prompt=force&client_id=oauth2-proxy&redirect_uri=http%3A%2F%2Flocalhost%2Foauth-proxy%2Fcallback&response_type=code&scope=openid+email+profile+roles&state=4b06492a222e53045d0447826a50c47e%3A%2F HTTP/1.1
Host: 192.168.0.101
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-GB,en;q=0.5
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1

服务器登录失败(错误:找不到命名的cookie)

我在 google 上看到过其他 cookie 问题,但我没有看到与我类似的任何东西。

【问题讨论】:

  • 所有浏览器都允许用户选择不使用某些 cookie。 Firefox 的默认设置blocks some cookies。尝试使用此设置。

标签: http firefox cookies browser


【解决方案1】:

所以问题在于服务器的时间。它正在创建过期时间已经在过去 12 Jul 2020 12:18:43 GMT 与浏览器时间 2020 年 9 月的 cookie。

显然 chrome 在下一个请求中发送回 cookie 没有问题,但 Firefox 丢弃了 cookie。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-24
    • 2012-05-02
    • 1970-01-01
    • 2019-04-25
    • 1970-01-01
    • 2014-06-22
    • 2018-03-16
    • 2020-11-08
    相关资源
    最近更新 更多