Giter Club home page Giter Club logo

standardizing-cross-site-cookie-semantics's Introduction

Standardizing Security Semantics of Cross-Site Cookies

Editors

Table of Contents

The Problem

Major browsers have shipped or announced their plans to ship the blocking of cross-site cookies by default. However, there are differing definitions of what “cross-site” could mean in this context and, as a result, major browsers' cross-site cookie blocking behavior has subtle differences.

This document is concerned with the security properties that arise from differences in treatment of SameSite=None cookies in certain scenarios, and seeks to drive alignment in browser behavior for these scenarios, keeping the privacy properties of cross-site cookie blocking. The ultimate goal of this work is to promote interoperability and specify cross-site cookie blocking semantics for these configurations.

Goals

This proposal aims to:

  • Develop a shared understanding of cross-site cookie blocking and its potential security benefits between user agents and other stakeholders.

  • To support these security benefits, specify common rules and semantics for cross-site cookie blocking, for future standardization in HTML, Fetch and the Cookies RFC.

  • Discuss how existing proposals such as CHIPS or the Storage Access API might interact with cross-site cookie blocking to restore access to blocked SameSite=None cookies if needed.

Non-Goals

  • We do not intend to discuss or change the commonly agreed upon cross-site privacy boundary for cookies that some browsers have already established. This proposal wants to discuss details on how this boundary might be designed pertaining both security and developer ergonomics, without compromising on its privacy properties.

  • We want to avoid adding dependencies on non-existing APIs to solve problems outlined in this proposal.

  • Most of the described behavior and APIs are shipping in browsers today and this document is an attempt to find pragmatic solutions that can be easily implemented and standardized.

  • We encourage new proposals that build on top of this work to further strengthen the security posture through the development of new APIs.

Proposal

Guiding Principles

The primary reason for restricting cross-site cookies is protecting user privacy, because giving embedded resources access to single-keyed cookies in a third-party context allows for cross-site tracking. As such, cookies should maintain a privacy boundary that is at least partitioned to the top-level site that any resource is loaded under.

Another important consideration is security. Cross-site cookies are key to a number of web application security vulnerabilities and cross-site leaks. As we improve the default security stance of the web through stricter cross-site cookie semantics, it is imperative to ensure developers are not caught unaware and put at risk by edge cases such as ABA embeds, as described below.

Finally, cross-site cookies remain a useful mechanic for many developers to build rich user experiences. Where it aligns with the other two principles, we want to give developers the greatest possible flexibility and composability working with cross-site cookies. This may involve utilization of other functionality such as CHIPS or the Storage Access API.

Overview

In short, we want to propose the following updates to the current (unspecified) status quo:

  • In embedded contexts, establish third-party cookie blocking based on "site for cookies" as the default behavior across user agents, except for “navigational requests” (iframe or top-level navigations) as outlined below.

  • Update the Storage Access API to ensure that it grants access to unpartitioned cookies in the ABA embed scenario detailed below.

This tradeoff would retain developer utility in the outlined scenarios while providing effective default protections against cross-site leaks. It still relies on correct usage of SameSite=None for full protection against CSRF from cross-site navigations.

Once we have reached consensus on the final design, we would like to update the relevant specification documents and write web platform tests to exercise the outlined scenarios.

Additional details can be found below.

Scenarios

Same-Site Embeds with Cross-Site Ancestors (ABA embeds)

Sites will have embeds that are same-site with the top-level site, but the embed has at least one cross-site ancestor in the frame tree. For brevity, we call these embeds ABA embeds.

When current third-party cookie blocking controls are enabled, major browsers' behaviors differ:

  • Chrome will always block cookies in the ABA embed unless the inner 1p.com frame requests storage access. Chrome will auto-grant requests in these contexts.

  • Firefox allows the ABA embed to read cookies set by A as the top-level site, but the ABA embed cannot write new cookies.

  • Safari and Brave allow ABA embeds to read and write cookies, including with headers in subresource requests to A that originate from an embedded site B frame.

Security Considerations

Allowing embeds with cross-site ancestors to have access to cookies has the consequence of also permitting any embedded site to make credentialed requests to the top-level domain. This could allow malicious third-party sites to exploit cross-site information leaks. The cookie specification was recently updated to require that sites opt-in to cookies that need to be sent on cross-site requests with the SameSite=None attribute. One may contend that this already offers websites some protection by default. However, sites which enable SameSite=None cookies tend to have multiple endpoints, only some of which expect to be served in specific, trusted cross-site contexts. Endpoints which don't expect cross-site interactions (and hence do not deploy sufficient protections against cross-site leaks or cross-site request forgery) might be unwittingly exposed to attacks from cross-site iframes.

Developer Utility

There are a few known use cases that utilize cross-site cookies in an ABA setup:

Given that both Firefox and Safari have so far not blocked SameSite=None cookies in this scenario, it is imaginable that there is other usage on the web.

However, we have APIs that can retain usability through an explicit opt-in to sending cookies in this case:

  • Storage Access API, which would allow embedded A iframes to request access to SameSite=None cookies as in a traditional cross-site scenario. The Storage Access API would be updated to automatically grant these calls without requesting permission from the user, since the purpose of the SAA invocation is for the top-level site's security rather than the user's privacy.

  • CORS: We could require use of CORS for any requests in an ABA setting. This would not prevent credentials from being sent, but it would allow the server to prevent leaking information to the intermediate “B” embedder.

Recommendation

In order to defend against these types of attacks, we recommend that ABA embeds which wish to use SameSite=None cookies must either invoke the (auto-granted) Storage Access API first, or opt-in via CORS.

Navigating a Cross-Site Embed to a Same-Site Page

Another SameSite=None cookie use case with diverging browser behavior is navigation requests for cross-site embedded frames to a same-site page.

Currently, all major browsers will send the SameSite=None cookie in these navigations. Should this be included in a spec as standard behavior?

Security Considerations

The ability of a cross-site iframe to force the top-level window to embed an arbitrary same-site endpoint as an <iframe> does not introduce a major risk of cross-site leaks – the attacker does not gain capabilities to learn information about the data loaded in the iframe. The primary risk in this context is CSRF due to the possibility of initiating a credentialed navigation (via either a GET or POST request) to arbitrary same-site destinations. This could be mitigated by allowing credentialed GET navigations, but restricting the sending of cookies on POST requests (most state-changing actions require non-safe methods such as POST).

Another potential attack in this scenario is clickjacking through iframing an unexpected same-site endpoint with state-changing functionality executed upon a user interaction with the embedded document. However, the A > A relationship between top-level site and iframe generally does not allow attackers sufficient control over the embed to execute compelling attacks, substantially reducing the risk of such attacks.

Developer Utility

There are examples that rely on this kind of behavior (e.g. login services provided by idp.elliemae.com). If SameSite=None cookies were blocked by default in this case, it would seem prudent to offer some more granular opt-in capability for developers. We are currently lacking this capability (CORS would not prevent a credentialed request to the server unless preflighted).

Recommendation

Given the relatively low risk from this behavior and the lack of an alternative opt-in method, we should send SameSite=None cookies by default here. We could aim to not send cookies for POST requests in this scenario, however, that might have a reduced effect depending on the feasibility of blocking cookies in the top-level cross-site POST requests scenario outlined below.

Top-Level Cross-Site POST Requests

In this example, site A initiates a cross-site POST request to B which is also a top-level navigation.

In this case, the question is whether we want to have the browser send Site B's SameSite=None cookies in the POST request. All major browsers currently do.

Security Considerations

As outlined in the previous section, POST requests usually change server state and as such are especially vulnerable to CSRF attacks via top-level navigation. SameSite cookies exist as a protection mechanism for this attack.

Developer Utility

There seems to be very widespread usage of this pattern on the web, such as for online credit card payments via 3D-Secure. It might be possible to build an improved opt-in mechanism for this kind of scenario that allows for more fine-grained control over which sites are allowed to perform cross-site POST requests to other sites, compared to SameSite. However, as stated in the Goals section, inventing such a mechanism is considered out of scope for this document.

Recommendation

Given the existing widespread usage and lack of clear alternatives, we recommend following the current state of the web and not blocking cross-site cookies in this scenario.

Redirecting a Cross-Site Subresource to a Same-Site Subresource

Another edge case of SameSite=None cookies are when third-party requests, which have their cookies blocked by third-party cookie blocking, are redirected to a first-party domain. We should consider standardizing that the redirected first party request should not get cookies.

Recently as part of ITP, Safari introduced Cookie Blocking Latch Mode, which blocks cookies in these redirected requests.

Security Considerations

If we allow cookies to be sent in these types of redirected requests, then it would be possible for an embedded site to redirect requests to its own server to endpoints of the top-level site. This could potentially leak entropy to the embedded site about the top-level site's state for the user.

Developer Utility

Currently unknown.

Recommendation

Browsers which use SameSite for third-party cookie blocking already block cookies in these redirected requests, since these redirected requests are still considered cross-site for SameSite protections. Therefore, we believe this should be specified as standard behavior.

We could require that top-level sites signal to browsers via some security opt-in that they are comfortable with sending SameSite=None cookies in these types of redirected requests.

standardizing-cross-site-cookie-semantics's People

Contributors

dcthetall avatar johannhof avatar krgovind avatar

Stargazers

Wai Lin avatar Laszlo Gombos avatar rsenguns.org avatar Mizuki Kameda avatar Thiago Diogo avatar  avatar azu avatar Universaliser avatar Yusuke Saito avatar Ryan Armstrong avatar Gowtham Ayna Raveendran avatar  avatar David Turner avatar Rowan Merewood avatar yuki avatar

Watchers

Rowan Merewood avatar Thiago Diogo avatar David Dabbs avatar  avatar  avatar uazo avatar  avatar  avatar Universaliser avatar

Forkers

rsengunrs

standardizing-cross-site-cookie-semantics's Issues

Include simpler scenario of cross-domain and cross-site iframes or subresources

For the sake of completeness - even at risk of stating the obvious - it might make sense to write down the simpler scenario of cross-domain and cross-site iframes or subresources (without ancestors or redirects involved). Specifically, I'm not sure if we've tested cross-domain vs. cross-site. Do all major browsers currently take the URL scheme into account when blocking third-party cookies? (i.e. would a request to http://example.com have its cookies blocked when a request is made from https://example.com?)

SameSite cookie quirks and the need to prescribe a solution for "Redirecting a Cross-Site Subresource to a Same-Site Subresource"

The existing section for Redirecting a Cross-Site Subresource to a Same-Site Subresource needs a couple of edits:

  • It seems to assume that only SameSite=None cookies are sent on these requests. However, Chrome's implementation currently has a quirk that allows SameSite=Lax|unspecified cookies to be sent on these requests, and is being tracked in crbug.com/1221316.
  • The section does not provide a recommendation on how sites may opt-in to receiving cookies on those requests; although it does acknowledge that "We could require that top-level sites signal to browsers via some security opt-in that they are comfortable with sending SameSite=None cookies in these types of redirected requests."
    • The above bug and crbug.com/1214360 indicate that there is likely web compat impact by blocking these cookies; so we may need to do some work to identify a solution, and validate it against the use-cases.

cc @sbingler

Changing recommendation for using CORS for cookies in A>B>A embeds

In the explainer section on A>B>A embeds, one possible solution we proposed was to allow A>B>A embeds to use CORS to regain cookie access without needing to call the Request Storage Access API.

After thinking about this more and discussing with our team, we have decided that CORS is not the right solution for A>B>A embeds that need an HTTP-only solution to restore cookie access. Our main line of reasoning is that requests opted into CORS still send credentials by default before the site has a chance to reveal to the browser whether the context sending cookies is acceptable. In particular, this can cause a problem for cross-site POST requests which may have side effects on the server side before they can tell the browser not to send cookies.

A more favorable solution for this use case is the Request Storage Access headers proposal which offers a mechanism in which will not send cookies to the site until it has explicitly opted into doing so in that particular context.

Status of this document

Hi Team

Thanks for working on this. I believe it's a very important missing piece for deprecating 3rd party cookie work.
I'm digging the behavior of POST submit, and I accidentally found it in privacysandbox/privacy-sandbox-dev-support#197 where @krgovind mentioned).

What is the current status of this document ? any progress for standardizing it ?
I understand this doc requires tons of works, but I think this document should be visible for more widely also.

Thanks
Jxck

Embedded Analytics scenario (A - B - A)

We have an analytics product that accesses data sources directly from the browser via CORS Fetch/XHR requests.
This analytics product has scenarios in which it is embedded in another application.

When the analytics product then queries the business application (as the data source) it results in an "A - B - A" deployment:

  1. The business application UI (A)
  2. opens the analytics product in an iframe (B)
  3. which accesses the business data via CORS Fetch/XHR requests to the business application server (A)

UI Embedding (A => B)
The analytics product is authenticated via SAML redirects to a common identity provider (with the assumption that the identity provider within the iframe will find its first party cookies, via requestStorageAccess if necessary).

Data Access (B => A)
For data access, the analytics product may open a pop-up against the business application to ensure that there is a session with the target system. In the embedded case, the pop-up can be omitted, or will immediately close due to the fact that A already has a valid first-party session cookie.

Then the actual data access happens via Fetch/XHR using CORS with Access-Control-Allow-Credentials. This expects that the first party session cookie (from the top-level business application) can be accessed from this third party context.

Discussion of Privacy Sandbox features

  • Partitioning the Business Application's cookies will break the data access. Even using mechanisms to propagate the authentication information into the partitioned context, it still results in two active sessions with the business application within one user workflow.
  • Storage Access API requires an unauthenticated document hosted by A and injected into a iframe within B. This is not trivial to implement due to the large number of business applications that would need to be revised. On top of that, the storage access request only applies to the iframe itself and not to any CORS requests made from B.
  • The storage access headers proposal does seem promising for this case, but it would need to lower overhead and ideally the storage access should be auto-granted given the fact that the same domain is at the top-level.

Note on Brave's handling on ABA embeds

thank you for writing this up and circulating it!

In case it might be of interest to the authors, I wanted to note that Brave's handling of 3p cookies in general, and ABA embeds is different than the other browsers mentioned here:

As background, unique from other browsers, Brave:

i. does not enable (or plan to enable) Storage Access API, and
ii. partitions storage in 3p frames under the eTLD+1 of the top frame, and clears those partitions shortly (~30 sec currently) after there are no more top-level frames with the same eTLD+1 open

We currently allow ABA embeds full r/w access to the same storage area as the top level frame, which makes Brave's handling of ABA frames closest to Safari's (though w/o the SAA support). We're not fixed or committed to this though, and would probably be fine aligning with others on this if other browsers do

We're also considering (for it becomes necessary for compat reasons in the future) possibly enabling a modified Storage Access API implementation that always resolves 'accepted', but which results in the same access patterns as the above (i.e., even after a SSA resolves accepted in a 3p frame, we would still clear state for that frame when there are no longer any top level frames with the current eTLD+1).

Not sure anything turns the above, no worries to close this issue immediately if its not useful, but mostly wanted to note that there are other handlings of 3p state / ABA frames in the wild

Q for "Redirecting a Cross-Site Subresource to a Same-Site Subresource" scenario

Hi Team, thanks for this work !

I have question for the scenario below.
Redirecting a Cross-Site Subresource to a Same-Site Subresource

IIUC, this scenario illustrates that

  • A embeds sub-resource of B
  • B's cookies are SameSite=None
  • Request to B doesn't have Cookie
  • B responds (302, 307, 308 etc) with Location: A
  • A should have Cookie or not ?

But I don't understand what kind of information leaks in this case.

This could potentially leak entropy to the embedded site about the top-level site's state for the user.

In the case above, B server doesn't receive any information from request/response with A since it's already redirected.

Could you clarify what the really problem is ? Adding image as other scenario also welcome.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.