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

Redirects do not honor set-cookie header #20476

Closed
kentcdodds opened this issue Mar 3, 2022 · 7 comments
Closed

Redirects do not honor set-cookie header #20476

kentcdodds opened this issue Mar 3, 2022 · 7 comments
Labels
E2E Issue related to end-to-end testing stale no activity on this issue for a long period topic: cookies 🍪 topic: cy.request Issues related to cy.request command type: bug

Comments

@kentcdodds
Copy link

kentcdodds commented Mar 3, 2022

Current behavior

I have a cy.request that ends up doing several redirects (as intended). In one of them a cookie is set along with the redirect location. The next request to follow the redirect does not include the cookie header:

image

Here's my cy.request call that starts this chain of redirects:

cy.request('POST', '/__tests/login', {email, firstName, team, role})

Desired behavior

Cypress should behave as a browser does when following redirects for a cy.request call.

Test code to reproduce

My repository is open source, you can follow the instructions here to get it set up: https://github.com/kentcdodds/kentcdodds.com/blob/main/CONTRIBUTING.md#project-setup

This is the test I ran to get the screenshot above: https://github.com/kentcdodds/kentcdodds.com/blob/main/cypress/e2e/contact.cy.ts

Cypress Version

9.5.1 (latest at the time of this report)

Other

I've experienced this in another (non-public) project and had to workaround it using cy.setCookie manually. I'd love to not have to do that here.

@davidmunechika davidmunechika added topic: cy.request Issues related to cy.request command type: enhancement Requested enhancement of existing feature labels Mar 4, 2022
@cypress-bot cypress-bot bot added stage: investigating Someone from Cypress is looking into this stage: routed to e2e-core and removed stage: new issues stage: investigating Someone from Cypress is looking into this labels Jun 24, 2022
@tbiethman tbiethman added type: bug stage: investigating Someone from Cypress is looking into this and removed type: enhancement Requested enhancement of existing feature stage: routed to e2e-core labels Jun 27, 2022
@tbiethman tbiethman removed their assignment Jun 27, 2022
@tbiethman tbiethman added E2E-core and removed stage: investigating Someone from Cypress is looking into this labels Jun 27, 2022
@mschile mschile added triage and removed triage labels Aug 18, 2022
@AtofStryker
Copy link
Contributor

Almost wondering if there is a slight delay in the automation API setting cookies on http:request in the server socket? The cookie looks to be eventually set and sent with subsequent requests except for the one immediately proceeding it

@jonasraoni
Copy link

Hey @kentcdodds, this looks similar to: #19800, which has a temporary workaround available (changing the SameSite setting).

@wilsonpage
Copy link

wilsonpage commented Nov 1, 2022

I had a similar issue with cy.visit(), here's my workaround 👇

// HACK: cypress seems to drop cookies that have 'Secure;' and 'SameSite=None';
// when used w/ localhost and redirects. As a workaround we intercept the redirect
// response and remove the `Secure` and `SameSite` flags from the cookie values.
// https://github.com/cypress-io/cypress/issues/20476
cy.intercept('/your-endpoint-that-redirects', (req) => {
  req.continue((res) => {
      const value = res.headers['set-cookie'];
      const setCookie = Array.isArray(value) ? value : [value];

      res.headers['set-cookie'] = setCookie.map((value) =>
        value.replace(/ ?Secure;?/, '').replace(/ ?SameSite=None;?/, '')
      );
   });
});

cy.visit('/your-endpoint-that-redirects');

@nagash77 nagash77 added E2E Issue related to end-to-end testing and removed E2E-core labels Nov 8, 2022
@Deop
Copy link

Deop commented Dec 29, 2022

Haven't tried a workaround yet, but would be nice to have this fixed/implemented in Cypress.

@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 Jun 28, 2023
@AtofStryker AtofStryker removed the stale no activity on this issue for a long period label Jun 28, 2023
@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 Dec 26, 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 Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E2E Issue related to end-to-end testing stale no activity on this issue for a long period topic: cookies 🍪 topic: cy.request Issues related to cy.request command type: bug
Projects
None yet
Development

No branches or pull requests