question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:14
  • Comments:5

github_iconTop GitHub Comments

4reactions
confiscarcommented, 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);
1reaction
alexjamesmacphersoncommented, Jan 28, 2022

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I allow secure http(not s) cookies with Cypress and ...
Cookie “token” has been rejected because a non-HTTPS cookie can't be set as “secure”. If I run in a regular private Firefox window...
Read more >
Changelog - Cypress Documentation
This change aligns Cypress' cookie rules with the browser cookie rules. This may affect what cookies are returned by cy.getCookie() , what cookies...
Read more >
Challenge solutions - Pwning OWASP Juice Shop
Open Juice Shop in a web browser which sets cookies with SameSite=None by default. With Firefox 96.x or Chrome 79.x this has been...
Read more >
Error 7 (net::ERR_TIMED_OUT): The operation timed out.
in some or all tabs. 2.As it seems the Chrome having problems loading pages – It take too much time until it give...
Read more >
Fix sameSite cookie issue in Cypress by installing an older ...
Before Chrome 80 SameSite=None was on all cookies by default but now it needs to be explicitly added in the API request or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found