← 中文资源

简体中文版本

第三方 Cookie 与存储分区

第三方 Cookie 由被访问页面之外的源设置,现代浏览器对其加以限制或按顶层站点分区,以遏制跨站跟踪与身份识别。

阅读英文原文

概念概述

第三方 Cookie 与存储分区(Third-Party Cookies and Storage Partitioning)指的是:第三方 Cookie 由被访问页面之外的源设置,现代浏览器对其加以限制或按顶层站点分区,以遏制跨站跟踪与身份识别。

从更严格的定义看,A third-party cookie is a cookie issued in the context of an embedded resource whose origin differs from the top-level page, allowing that embedded origin to recognise the same browser across many sites. 该概念在工程实践中的价值,在于它能帮助团队用统一的语言描述一个具体的质量属性或设计约束,从而在评审与协作中减少歧义。

为什么需要它

The classification drives how analytics, embedded widgets, and federated login behave as browsers tighten cross-site storage. 它与 Subresource Integrity (SRI)、Preconnect and DNS-Prefetch Hints、Fetch Priority Signals 等概念经常一起出现,用于解决相近的工程问题。理解它的适用场景,有助于在多种备选方案之间做出有依据的取舍,而不是凭直觉选择技术方案。

常见误解

  • all cookies are inherently third-party
  • SameSite alone makes a cookie invisible to the embedded origin

需要避免的反模式

  • relying on a shared embedded cookie for cross-site identity
  • assuming partitioned storage shares state between top-level sites

实践要点

  1. Browsers decide third-party status from the context in which the cookie is read or written, so a cookie whose value is first-party on one site becomes third-party when the same origin is embedded elsewhere.
  2. SameSite and storage partitioning split that state per top-level site, which breaks cross-site single sign-on unless a deliberate, standardised mechanism such as a supported federated flow is used.
  3. Design for server-side identifiers or explicit user consent rather than ambient cookies, because the trend is toward ever narrower cross-site access.

参考来源

https://developer.mozilla.org/en-US/docs/Web/Privacy/Guides/Third-party_cookies