#34902·cypress

Cypress 16 regression: manipulating cookies in cy.intercept response callback no longer works with native network interception

Author: BaesKevinCreated Sep 23, 2026Updated Sep 24, 2026
Labelstype: bugpkg/serverbrowser: chrometopic: cookies :cookie:type: regressiontopic: networkexisting workaroundtopic: cy.intercept()

Current behavior

We need to rewrite cookies in a cy.intercept response handler to make our login flow work, from this blog. forceHttp1 fixes the issue.

Before Cypress 16, the code below would succesfully change samesite to none. Now, this no longer works and chrome shows this error, which is why we had to introduce the hack in the first place.

'This "Set-Cookie" header didn't specify a "SameSite" attribute and was defaulted to "SameSite=Lax", and was blocked because it came from a cross-site response which was not the response to a top-level navigation. The "Set-Cookie" header had to have been set with "SameSite=None" to enable cross-site usage.'

Desired behavior

No response

Test code to reproduce

We are testing an oauth2 authorization code flow that uses EntraID and our own authentication proxy, for which we need 2 workarounds to work. Our own proxy uses session based authentication, so when we get back from entry, the proxy responds with a redirection back to the application with a Set-Cookie header.

Unfortunately, I can't think of a way to fully reproduce this without me setting up a pretty extensive demo repo with Keycloak or something. Pseudocode-ish of what we do in our login:

cypress.config.js: experimentalModifyObstructiveThirdPartyCode: true as documented in https://docs.cypress.io/guides/end-to-end-testing/azure-active-directory-authentication

javascript
export function loginToMyApplicatoin() {
    rewriteSameSiteLaxOrStrictCookies()

    makeSureOriginIsMyApplication()
    cy.visit(`/`)

    cy.origin('https://login.microsoftonline.com', { args: { token: mfaToken, username, password } }, (args) => {
        submitUsername(args.username)
        submitPassword(args.password)
        submitTotp(args.token)
        submitDoNotStaySignedIn()
    })

    cy.url().should('equal', Cypress.config().baseUrl)
}

function rewriteSameSiteLaxOrStrictCookies() {
    //www.tomoliver.net/posts/cypress-samesite-problem
    cy.intercept('*', (req) =>
        req.on('response', (res) => {
            const setCookies = res.headers['set-cookie']
            res.headers['set-cookie'] = (Array.isArray(setCookies) ? setCookies : [setCookies])
                .filter((x) => x)
                .map((headerContent) => headerContent.replace(/samesite=(lax|strict)/gi, 'secure; samesite=none'))
                .map((headerContent) => headerContent.replace(/samesite=none/gi, 'secure; samesite=none'))
        }),
    )
}

function makeSureOriginIsMyApplication() {
    // visiting the root does not work as our application redirects the browser to the idp
    cy.visit(`/some-unauthenticated-page`)
}

Cypress Version

16.0.0

Debug Logs

bash

Other

No response