【问题标题】:Where to add `SameSite=None`?在哪里添加“SameSite=None”?
【发布时间】:2020-07-04 11:16:21
【问题描述】:

我的网站上发生了以下代码,但我尽力无法掌握,所以我有几个问题,请阅读。

category-search-Forum:1 A cookie associated with a cross-site resource at https://www.google.com/ was set without the `SameSite` attribute. It has been blocked, as Chrome now only delivers cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

我看到很多人在堆栈和其他在线位置谈论这个,但没有人解释过如何添加SameSite=None

1 问题:如何或在何处添加SameSite=None

看看错误,什么是'安全'

这是否意味着SameSite=Secure

SameSite=NoneSameSite=Secure 有什么区别?

【问题讨论】:

  • 您的 cookie 应添加 SameSite=None; Secure 属性,但具体答案取决于您选择的语言/框架。有关该问题的良好起点,请参阅this wiki page

标签: google-chrome samesite


【解决方案1】:

这里讨论过:https://blog.chromium.org/2019/10/developers-get-ready-for-new.html

这实际上是服务器端问题。它只是说,您正在使用来自另一个站点(通常是 JS 或 CSS)的资源,并且该服务器正在尝试设置 cookie;但是,它没有 SameSite 属性集。

这样做是因为:

如今,如果 cookie 仅打算在第一方上下文中访问,则开发人员可以选择应用两种设置(SameSite=Lax 或 SameSite=Strict)中的一种来阻止外部访问。但是,很少有开发人员遵循此推荐做法,从而使大量同站点 cookie 不必要地暴露在跨站点请求伪造攻击等威胁之下。

为了保护更多网站及其用户,新的默认安全模型假定所有 cookie 都应受到保护,除非另有说明。开发人员必须使用新的 cookie 设置 SameSite=None 来指定用于跨站点访问的 cookie。当 SameSite=None 属性存在时,必须使用额外的 Secure 属性,以便只能通过 HTTPS 连接访问跨站点 cookie。这不会降低与跨站点访问相关的所有风险,但会提供针对网络攻击的保护。

除了直接的安全优势之外,跨站点 cookie 的明确声明还可以提高透明度和用户选择。例如,浏览器可以为用户提供细粒度的控制,以管理仅由单个站点访问的 cookie,与跨多个站点访问的 cookie 分开。

由于您的帖子没有定义您是在服务器端还是客户端工作,我的假设是您在客户端工作,因此,您无能为力,因为该资源需要更新它。但是,如果您正在做服务器端开发,这里是不同语言的资源列表:https://github.com/GoogleChromeLabs/samesite-examples

TLDR;如果您是客户端开发人员,那么这是因为链接资源没有此集,您对此无能为力。如果您是服务器端开发人员,请查看 github 链接以获取有关如何为您的站点解决此问题的示例。

编辑:如果您只是想摆脱该消息,则在此处讨论了解决方案:Chrome Console SameSite Cookie Attribute Warning 您可以通过chrome://flags Cookie Deprecation messages disabled 禁用它们。

【讨论】:

  • 您实际上填写了我缺少的关键细节,错误来自 twitter 小部件。我明白了,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-05-21
  • 2020-03-04
  • 1970-01-01
  • 2020-12-19
  • 2020-09-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多