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

setCookies is broken since 9.0.0. ~ is converted to \x7e #19096

Closed
jweingarten opened this issue Nov 24, 2021 · 7 comments · Fixed by #19239
Closed

setCookies is broken since 9.0.0. ~ is converted to \x7e #19096

jweingarten opened this issue Nov 24, 2021 · 7 comments · Fixed by #19239
Labels
topic: cookies 🍪 topic: network type: bug type: regression A bug that didn't appear until a specific Cy version release v9.0.0 🐛 Issue present since 9.0

Comments

@jweingarten
Copy link

jweingarten commented Nov 24, 2021

Current behavior

After calling setCookie with a valid cookie and then loading the desired page the cookies are somehow not accepted or read. The page we load should show the user is logged in, but he appears as if the cookies are not there. The Network Application Cookies show that they are set, but the page that is loaded doesn't seem to either see them or read them. Note in this example baseUrl is not set, but I tried it with it being set and not. Same behavior.

I ran 8.7.0 and 9.0.0 and 9.0.1. Its broken since 9.0.0. Tested on Chrome, Firefox and Electron. Broken in all 3.
In 8.7.0 the user appears to be logged in, in 9.* the user is not.

Desired behavior

User should be logged in after calling setCookies and then visiting the destination url. In this example when I run the provided code and www.yahoo.com is loaded and I move the mouse over the top right mail icon I see the user as logged in.

See screen shot for Cypress 8.7.0
Screen Shot 2021-11-24 at 11 34 07 AM

Now when running with 9.0.0 you will see this. As if the user is not signed in.
Screen Shot 2021-11-24 at 11 31 42 AM

Test code to reproduce

I can't give you fully reproducible code, because I can't provide you with the way we get our cookies. Here is the basic script with a hardcoded sample cookie value.

describe('Main Dashoard login load test', function() {
  context('Login', function() {
    it('When moving the mouse over the mail icon at the top right corner the user should show logged in', function() {
      cy.clearCookie('Y');
      cy.clearCookie('T');
      cy.getCookie('Y').should('not.exist');
      cy.getCookie('T').should('not.exist');

      cy.setCookie('Y', "v=1&np=1&n=23eno0bmig3ub&l=8a2dn1nck044hib2atdgsc5adwppb5ii12lf2i04/o&p=n33vvvv00000000&r=11p&intl=us");
      cy.setCookie('T', "af=JnRzPTE2Mzc3Nzg4NTYmcHM9SDR2cHdfbnZXdd=bnMBeWFob28BZwFDTU5NWlhOUURBNkI3SFoyTFlTTUpLQUY3RQFhYwFBSTJLRmlHNQFhbAFkc3BfYXV0bwFzYwF5cWEBZnMBa1VGSTV3Qmhub1dvAXp6AW9Xb25oQjhBQQFhAVFBRQFsYXQBb1dvbmhCAW51ATA-&kt=asdffadfaf--~I&ku=FAATcU6Cc1YDmlpoXPv7S4BTWHg5Uz58mDuWHcxOtOQKf6gvdQ10fhJAnSJ9k_HlToJ4.YDa4kNdee2LAEpqg.KtqhyHvvi2o5MRjmhOesmE7p4fxxHAwiK1gYjNXygVm_AHV95GryLqDPnfuEFaHFQy_vfOKU1YtxEi3W2AdQM3j8-~E");
      cy.visit('https://www.yahoo.com');
    });
  });
});

Cypress Version

9.*

Other

No response

@jweingarten
Copy link
Author

jweingarten commented Nov 24, 2021

Network Tools | Application | Cookies screen shot for 9.0.0
Screen Shot 2021-11-24 at 11 57 26 AM

Network Tools | Application | Cookies screen shot for 8.7.0
Screen Shot 2021-11-24 at 12 01 02 PM

I don't see a difference, which is why I don't understand why this is not working in 9.0.0

@jweingarten
Copy link
Author

jweingarten commented Nov 26, 2021

I figured out what the issue is. With 9.x the a ~ is converted to \x7e during the setCookie call.
When I look at my T cookie in the Dev Tools Application Cookie entry and change the \x7e back to a ~ and reload the page it loads logged in.

Here are simple steps to reproduce the problem.

describe('Main Dashoard login load test', function() {
  context('Login', function() {
    it('The Main Dashboard should be able to load now', function() {
      cy.setCookie('FOO', '~', { domain: 'www.google.com', expiry: 1701057873, path: '/', secure: false });
      cy.visit('https://www.google.com');
      cy.setCookie('FOO', '~', { domain: 'www.google.com', expiry: 1701057873, path: '/', secure: false });
      cy.getCookies().then((cookies) => {
        for (let i = 0; i < cookies.length; i++) {
          if (cookies[i].name === 'FOO') {
            cy.log(cookies[i]);
          }
        }
      });
    });
  });
});

Note how the Dev Tools shows \x7e and it should be a ~.

Screen Shot 2021-11-26 at 12 14 06 PM

When you look at the cy.log output in the Dev Console it shows ~ again.

Screen Shot 2021-11-26 at 12 15 50 PM

Doing the same above with Cypress 8.7.0 will show the ~ all the way, meaning also in the Dev Tools Application Cookies section.

@jweingarten jweingarten changed the title setCookies is broken since 9.0.0 setCookies is broken since 9.0.0. ~ is converted to \x7e Nov 26, 2021
@jweingarten
Copy link
Author

Video showing that the cookie isn't set correctly, but when manually changing \x7e back to ~ that the cookie is valid again.

demobug.mov

@jweingarten
Copy link
Author

jweingarten commented Dec 2, 2021

@chrisbreiding This is broken since 9.0.0. At least what I am reporting in this ticket is, not sure about the other tickets.

@chrisbreiding chrisbreiding added v9.0.0 🐛 Issue present since 9.0 and removed v9.1.0 🐛 Issue present since 9.1 labels Dec 2, 2021
@cypress-bot cypress-bot bot added the stage: needs review The PR code is done & tested, needs review label Dec 3, 2021
@cypress-bot cypress-bot bot added stage: pending release and removed stage: needs review The PR code is done & tested, needs review labels Dec 3, 2021
@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 3, 2021

The code for this is done in cypress-io/cypress#19239, but has yet to be released.
We'll update this issue and reference the changelog when it's released.

@cypress-bot
Copy link
Contributor

cypress-bot bot commented Dec 4, 2021

Released in 9.1.1.

This comment thread has been locked. If you are still experiencing this issue after upgrading to
Cypress v9.1.1, please open a new issue.

@cypress-bot cypress-bot bot locked as resolved and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
topic: cookies 🍪 topic: network type: bug type: regression A bug that didn't appear until a specific Cy version release v9.0.0 🐛 Issue present since 9.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants