什么可能导致相关 cookie 无法在特定设备上返回

What could cause a correlation cookie to not be returned on specific devices

我们有一些用户无法通过 Google 连接到我们的平台。当发生这种情况时,它总是针对特定的设备,但根据我们目前掌握的信息,它并不是所有相同的设备类型(待确认)。

我们正在使用 ASP.NET Core(和 Identity Server 4)。

我们这边的错误是,从 oauth 流程返回后,ASP.NET 身份设置的关联 cookie 消失了。我们已经验证了它在开始时设置的很好,并且是有效的。这不是关于数据保护的问题(我们确实有这个)。我们可以用 iOS 12 在两个 iPad 上进行复制,无论我们尝试连接哪个帐户。所有这些帐户都可以在其他设备上连接,包括 iPads 和 iOS 13.

因此,我们正试图找出可能导致这些特定设备发生故障的原因。此外,这似乎是最近才开始发生的,我们无法确定是什么变化导致了我们这边的这种情况。

更新 1

将 iPad 从 iOS 12 更新为 iOS 13 解决了问题。

2019/11/19,.NET Core v2.2.8 发布。此版本包含此更改,在补丁说明中提到:

Risk: Medium. The SameSite changes are known to be incompatible with older OSs and browsers, especially iOS 12 and OSX Mojave (latest - 1). These represent a small but influential portion of the web client user base. Updating to the latest OS version addresses the incompatibility.

由于我们的 Docker 图片基于 mcr.microsoft.com/dotnet/core/aspnet:2.2,12 月 3 日发生的一个不相关的更新将更新推送到我们的服务器。

This blog post 更详细地解释了情况,但简而言之:

  • Chrome 当 set-cookie 未指定 SameSite 值时,v80 将开始默认为 Lax,而不是默认为 None
  • 设置 cookie 的 SameSite=None 时,ASP.NET Core 不会将 SameSite 值发送到 set-cookie,假设浏览器默认为 None
  • 从v2.2.8开始,ASP.NET核心一直在发送SameSite=None
  • Safari 在 iOS 12 和 macOS 10.14 Mojave 上将 SameSite=None 视为 SameSite=Strict(有关详细信息,请参阅 this webkit bug
  • 因此,我们的关联 cookie 在这些操作系统上被严格对待,这意味着它们不会按预期发回。

虽然我们可以恢复到 2.2.7,但即将到来的 Chrome 更新 (80) 将停止工作。幸运的是,this article clearly states the proper course of action: we need to implement user agent sniffing and not send the SameSite=None to user agents which do not support it. This comment 提到了要过滤的建议用户代理,这看起来不错。

也许您可以在 AddOpenIdConnect("") 中使用此代码。

如果你使用.net core > 2.*

options.NonceCookie.SameSite = (SameSiteMode) (-1); 
options.CorrelationCookie.SameSite = (SameSiteMode) (-1); 

如果您使用 .net > 3.*

options.NonceCookie.SameSite = SameSiteMode.Unspecified;
options.CorrelationCookie.SameSite = SameSiteMode.Unspecified;