cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.97k stars 3.18k forks source link

Consider moving away from document.domain to adhere to better security practices #29590

Open AtofStryker opened 5 months ago

AtofStryker commented 5 months ago

What would you like?

I would like to consider removing document.domain injection and making cy.visit() require a full navigation when a subdomain navigation occurs, changing the cookie APIs to set the cookie on the current domain (not super domain), and to better adhere to full origin specifications without strange exceptions when it comes to origin and domain nomenclature.

document.domain modification deprecation The origin specification

Why is this needed?

With the introduction of Chrome 119, Chrome and other browsers now bucket all requests to an origin server with a given Origin-Agent-Cluster key:

The browser will ensure that all pages from a given origin are either origin-keyed or they are not. This means that:

If the first page from an origin does not set the header, then no other pages from that origin will be origin-keyed, even if those other pages do set the header.
If the first page from an origin sets the header and is made origin-keyed, then all other pages from that origin will be origin-keyed whether they ask for it or not.

Cypress ran into this in it's own system tests in #29391 and we patched a work around internally (see thread on PR).

This means the Agent-Origin-Cluster header needs to be set on the first page request. However, this is difficult for Cypress for a few reasons:

Cypress only injects into cy.origin() or the Application Under Test (AUT). It is sometimes impossible to know when injection is going to be required in the future for a request that has already been sent to an origin server, which gives us two options:

Other

No response

cacieprins commented 2 weeks ago

The solution we are moving forward with, in Cypress 14: