Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cypress silently drops secure cookies from requests (Chromium), fails to set secure cookie at all (Firefox) #18690

Open
spiffytech opened this issue Oct 28, 2021 · 12 comments

Comments

@spiffytech
Copy link

spiffytech commented Oct 28, 2021

Current behavior

Cypress misbehaves when managing secure cookies on localhost.

Chromium

Cypress visits some path (e.g., /set-cookie) that sets a secure cookie. Then, Cypress visits another path (/) that reads the cookie value. On that second request, Cypress doesn't send the cookie. Chromium indicates the cookie is sent, but the web server doesn't receive it, and a MitM proxy shows the cookie is not in the request. If the cookie is not marked as secure, everything behaves correctly.

The attached reproduction repo provides the details about this test.

Cookie in devtools:
devtools-cookie

Request that pretends to send the cookie:
devtools-request

Intercepted request:
mitm-intercept-secure

For comparison, here's the intercepted request when using an insecure cookie:
mitm-intercept-insecure

Firefox

In Firefox, the secure cookie is never set in the first place.

Devtools prints: Cookie “mySecureCookie” has been rejected because a non-HTTPS cookie can’t be set as “secure”. (Related: #16611)

Desired behavior

localhost is considered a secure browsing context, and the repro app works correctly outside of Cypress. Setting and transmitting a secure cookie on localhost should be successful. Failing that, Chromium should not lie about whether the cookie is being sent.

Test code to reproduce

Here's an app I put together that minimally reproduces the issue, with failing Cypress tests.

npm install, npm start to launch the web server, npm test to show the Cypress tests demonstrating the failure.

Cypress Version

8.7.0

Other

If I open a normal Chromium or Firefox instance, everything works correctly. This only happens under Cypress' automation.

Chromium version: 94.0.4606.81 (openSUSE Build) stable (64-bit)

Firefox version: 93.0 (64-bit)

@alexjamesmacpherson
Copy link

I am also observing this issue and it significantly impedes our ability to implement and run Cypress tests for our application when it's running locally.

Any update on resolving this problem would be greatly appreciated, or if anyone knows of a workaround we can implement in the meantime, that would be great!

@confiscar
Copy link

confiscar commented Feb 2, 2022

Not really a work around, but had a similar problem today. Found another issue that mentioned how downgrading to 6.4.0 resolved their issues, which also fixed mine. Its either that or not setting the cookie as secure :(

Seems like a regression?

@confiscar
Copy link

confiscar commented Feb 7, 2022

Workaround:

Instead of using cy.visit(), get the window object and manually set location.href.

e.g.

cy.window().then((win) => win.location.href=yourURL);

nicholaschiang added a commit to rooteco/tweetscape that referenced this issue Mar 16, 2022
* fix(db/setup.pgsql): use less intrusive deletions

* test(fixtures): add `pg_dump` sql seed

* wip(tests/index): add placeholder for cookie tests

Blocked by cypress-io/cypress#18690 and cypress-io/cypress#19316

* test(fixtures/db.sql): update for new constraints

* fix(db/setup): add unique constraints to dedupe `scores`

Fixes TS-66

* chore(scripts/data): import latest influencer scores

Fixes TS-66

* feat(app): add `data-cy` testing labels

* test($cluster.spec): use new filters and sorting

* ci(test): setup docker services tests

* deps: add `@percy/cli` package

* ci(workflows): remove unused env vars

* test(cypress.json): add retries during ci

* test($cluster): add nprogress hidden assertions

* test($cluster): move `loading(false)` outside `within`
@sethlivingston
Copy link

We're seeing the same problem. It happens when we intercept a call and modify the body -- the subsequent call won't have the cookie.

@mheers
Copy link

mheers commented Aug 22, 2022

I'm also seeing the same problem. Running Cypress locally is fine, but when running in docker it breaks. I created a simple repository to reproduce the problem:

https://github.com/mheers/cypress-docker-cookie

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label May 15, 2023
@cypress-app-bot
Copy link
Collaborator

This issue has been closed due to inactivity.

@cypress-app-bot cypress-app-bot closed this as not planned Won't fix, can't repro, duplicate, stale May 31, 2023
@dcsaszar
Copy link

dcsaszar commented Nov 29, 2023

This is still an issue in Cypress 13.6.0

FWIW, here's the workaround helper we run as the last step of our login command:

(Update 2024-03-24: We found a more effective workaround here.)

/**
 * Workaround for https://github.com/cypress-io/cypress/issues/18690
 */
function makeCookiesInsecure() {
  cy.getCookies().then((cookies) => {
    const cookie = cookies.find(({ secure }) => !!secure);
    if (!cookie) return;

    cy.clearCookie(cookie.name).setCookie(cookie.name, cookie.value, {
      ...cookie,
      secure: false,
      sameSite: undefined,
    });

    cy.reload();

    makeCookiesInsecure();
  });
}

@jennifer-shehane
Copy link
Member

Reopening

@jennifer-shehane jennifer-shehane removed the stale no activity on this issue for a long period label Nov 29, 2023
@georgwindhaber
Copy link

I'm seeing the same problem with firefox v121 and cypress v12.17.4 or v13.6.3

In Chrome v120 it works for me

@cypress-app-bot
Copy link
Collaborator

This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.

@cypress-app-bot cypress-app-bot added the stale no activity on this issue for a long period label Sep 21, 2024
@dcsaszar
Copy link

We still see the issue with SameSite=Lax in Cypress 13.14.2.

@cypress-app-bot cypress-app-bot removed the stale no activity on this issue for a long period label Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants