Cypress: Error: Failed to parse or set cookie named

Created on 19 Feb 2019  ยท  14Comments  ยท  Source: cypress-io/cypress

Current behavior:

When using a cookie with attribute Secure using a HTTP connection an error is thrown and tests are aborted:

Error: Failed to parse or set cookie named "".

For more context, see https://github.com/cypress-io/cypress/issues/1321#issuecomment-462647518

Desired behavior:

Cypress should continue to run tests and ignore cookie, perhaps showing a warning about trying to set a secure cookie on a non-secure connection.

Steps to reproduce: (app code and test code)

  1. Use a non-encrypted connection (http)
  2. Navigate Cypress to a url which tries to set a Secure cookie as response

Versions

Cypress 3.1.5 (3.1.0 works fine), any OS, both Electron and Chrome are affected.

ready for work topic bug

Most helpful comment

@jennifer-shehane I would like to re-open this issue as I am unable to catch the exception using uncaught:exception and Cypress just straight up crashes when the set cookie error occurs. This halts all execution, which I think is pretty bad.

support/index.js

Cypress.on('uncaught:exception', () => {
  return false;
});

Run

$ cypress run

====================================================================================================

  (Run Starting)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Cypress:    3.1.1                                                                              โ”‚
  โ”‚ Browser:    Electron 59 (headless)                                                             โ”‚
  โ”‚ Specs:      1 found (smokeTest.spec.js)                                                        โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

  Running: smokeTest.spec.js...                                                            (1 of 1) 


  Smoke tests
    1) Should render an insecure page
{ Error: Setting cookie failed


  cause: 
   Error: Setting cookie failed

   ,
  isOperational: true }
Error: Setting cookie failed


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I was able to confirm that this started happening on 3.1.1, so for now I'm going with 3.1.0 as @sweoggy suggested.

Unfortunately I don't have a reproducible example I can share at this moment ๐Ÿ˜ž

All 14 comments

From MDN:

Note: Insecure sites (http:) can't set cookies with the "secure" directive anymore (new in Chrome 52+ and Firefox 52+). https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie

I believe Cypress is following the actual behavior of the browser. The cookie will not be set.

In terms of preventing Cypress from failing, can you try to listen to uncaught:exception and see if you can ignore this error? Docs for this are here.

I believe Cypress is following the actual behavior of the browser. The cookie will not be set.

That's true, but I would like Cypress to give a warning instead of throwing an error, or, a more descriptive error message. Something along the lines of:

Error: Failed to parse or set cookie named "<JSESSIONID>". "Secure" cookie is not allowed on non-encrypted connection"

@sweoggy Did listening to the uncaught:exception work in allowing you to ignore the failure?

@jennifer-shehane we fixed it by not using Secure cookies in our test environment

@jennifer-shehane I would like to re-open this issue as I am unable to catch the exception using uncaught:exception and Cypress just straight up crashes when the set cookie error occurs. This halts all execution, which I think is pretty bad.

support/index.js

Cypress.on('uncaught:exception', () => {
  return false;
});

Run

$ cypress run

====================================================================================================

  (Run Starting)

  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
  โ”‚ Cypress:    3.1.1                                                                              โ”‚
  โ”‚ Browser:    Electron 59 (headless)                                                             โ”‚
  โ”‚ Specs:      1 found (smokeTest.spec.js)                                                        โ”‚
  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜


โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

  Running: smokeTest.spec.js...                                                            (1 of 1) 


  Smoke tests
    1) Should render an insecure page
{ Error: Setting cookie failed


  cause: 
   Error: Setting cookie failed

   ,
  isOperational: true }
Error: Setting cookie failed


error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I was able to confirm that this started happening on 3.1.1, so for now I'm going with 3.1.0 as @sweoggy suggested.

Unfortunately I don't have a reproducible example I can share at this moment ๐Ÿ˜ž

Yeah, the browser should certainly not crash in this case. We should handle this error better.

Ah, I'll try to help out here if I can. Running into a similar issue (may be the same) intermittently. I'll try to set up a minimal reproduction, but downgrading to 3.1.0 does indeed work.

Both 3.1.1 and 3.1.5 were displaying the same "error" -- as mentioned above, though, the error isn't caught listening for exceptions.

@jennifer-shehane I am getting the same issue, On 3.2.0 when I try to run Cypress tests in local I get failed to parse or set cooked ... The cookie that it fails to set is sent a Secure and the local environment is just HTTP. It was working fine in 3.1.0.

We also have stage environments(which run over https), i set base_url to stage and ran the cypress tests locally and they work fine. (3.2.0)

Can confirm this exact issue happens when upgrading from 3.1.0 to 3.1.1. I assume the secure cookie expiration fixes mentioned in the change log for 3.1.1 introduced this issue.

Tests run fine on our secure production environment but breaks on our development environment, which is not secure. Securing our development environment is not really an option so fix or workaround would be ideal.

Hello, sorry, my English is not fluent so I'm using google translator. After a few days suffering, doing everything I saw in the forums and could not solve the problem.

How I solved: In my tests I call a login function before each case, and there was the problem, I created a suite of tetes for login screen, and the others I do the direct access. From what I understand, since I do not log off at the end of the tests, then it raises the problem. I'm a beginner in automated testing, but that's how I can solve it.
Cypress version: 3.4.0

At least the error that is shown in 3.4.0 is much clearer than in 3.2.0. But I also would like the test to continue, as this is also how the website behaves when a normal user visits it.

This is the error I now get:

CypressError: cy.visit() failed trying to load:

http://[address of website]

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

Error: Setting cookie failed

Common situations why this would fail:

  • you don't have internet access
  • you forgot to run / boot your web server
  • your web server isn't accessible
  • you have weird network configuration settings on your computer

The stack trace for this error is:

Error: Setting cookie failed

We're still seeing this in 3.4.1 and its making it impossible to write a programmatic login command.

I am also getting the above error. please help.

Also reproduced this error , I confirm that removing the Secure tag from the Set-Cookie header works, or using HTTPs.

Was this page helpful?
0 / 5 - 0 ratings