22

Chrome 80+ 跨域Samesite 导致的cookie not found 解决方法

 3 years ago
source link: http://www.cnblogs.com/shanyou/p/13713681.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

应用系统使用的Http, 没有使用Https(https不存在SameSite问题), 应用系统 通过IdentityServer4的认证中心返回后报错误:  Correlation failed ,如下图

36Bv2mV.png!mobile

Chrome 51 开始,浏览器的 Cookie 新增加了一个 SameSite 属性,用来防止 CSRF 攻击和用户追踪。Chrome的更新导致SamSite策略有所变更,这个导致IS4的认证有问题,无法使用http客户端连入IS4的服务端,abp的社区里提供了文章告诉我们解决方案 : How to fix the Chrome login issue for the IdentityServer4

Cookie 的 SameSite 属性用来限制第三方 Cookie,从而减少安全风险。

它可以设置三个值。

  • Strict
  • Lax
  • None

1.1 Strict

Strict 最为严格,完全禁止第三方 Cookie,跨站点时,任何情况下都不会发送 Cookie。换言之,只有当前网页的 URL 与请求目标一致,才会带上 Cookie。

Set-Cookie: CookieName=CookieValue; SameSite=Strict;

这个规则过于严格,可能造成非常不好的用户体验。比如,当前网页有一个 GitHub 链接,用户点击跳转就不会带有 GitHub 的 Cookie,跳转过去总是未登陆状态。

1.2 Lax

Lax 规则稍稍放宽,大多数情况也是不发送第三方 Cookie,但是导航到目标网址的 Get 请求除外。

Set-Cookie: CookieName=CookieValue; SameSite=Lax;

导航到目标网址的 GET 请求,只包括三种情况:链接,预加载请求,GET 表单。详见下表。

eeqmmi2.png!mobile

设置了 StrictLax 以后,基本就杜绝了 CSRF 攻击。当然,前提是用户浏览器支持 SameSite 属性。

1.3 None

Chrome 计划将 Lax 变为默认设置。这时,网站可以选择显式关闭 SameSite 属性,将其设为 None 。不过,前提是必须同时设置 Secure 属性(Cookie 只能通过 HTTPS 协议发送),否则无效。

下面的设置无效。

Set-Cookie: widget_session=abc123; SameSite=None

下面的设置有效。

Set-Cookie: widget_session=abc123; SameSite=None; Secure

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK