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.

Redirect to subdomain has incorrect cookie value.

See original GitHub issue

Current behavior

When redirecting from web server (dev.mydomain.com) to api server (api-dev.mydomain.com) and setting baseUrl in the run command then the cookies for the redirect have the incorrect subdomain and thus get stripped from the request to the api server.

Desired behavior

Don’t touch my cookies.

Test code to reproduce

baseUrl is set to dev.mydomain.com

	cy.getCookie('mycookie').then(c => {
		const mycookie = c.value;
		cy.log(mycookie);
		cy.setCookie('mycookie', mycookie, { domain: '.mydomain.com' }).then(() => {
			cy.getCookie('mycookie').then(cookie => {
				expect(cookie.domain).to.eq('.mydomain.com');
                              // at this point the code fails because the domain is 'dev.mydomain.com'
			});
		});
	});

image

Versions

Worked in 5.x. Doesn’t in 6.x

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5

github_iconTop GitHub Comments

1reaction
jwagoncommented, Feb 4, 2021

Another update is that yesterday we downgraded Cypress to v5.6, and things work as expected, even with baseUrl set. Hope the additional context is helpful . . .

0reactions
jwagoncommented, Feb 4, 2021

@Qarj I’d add to @jkyoutsey 's last sentence, that “against localhost” means that we are running our front-end app on localhost and Cypress is running its test against that app; and that app is configured to proxy API requests to dev.* or api-dev.* as appropriate. So the server end of this equation seems to be working as it should. It’s only when we point Cypress at the front-end app deployed to dev.* through the baseUrl parameter that things break down.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Creating a subdomain Auth cookie then redirecting to ...
Store the subdomain in the cookie value itself. Create a secure document container that lists the subdomains to which the user is granted...
Read more >
Problems with settings cookies in case of redirect to subdomain.
This is a problem, if in any case, you are using domain example.com as main domain, but do not set up correct redirection...
Read more >
Using redirects - AWS Amplify Hosting
Redirects enable a web server to reroute navigation from one URL to another. Common reasons for using redirects include: to customize the appearance...
Read more >
RFC 6265: HTTP State Management Mechanism
Although cookies have many historical infelicities that degrade their ... Using the Set-Cookie header field, an HTTP server can pass name/value pairs and ......
Read more >
Cookies, document.cookie - The Modern JavaScript Tutorial
By default, a cookie is accessible only at the domain that set it. Please note, by default a cookie is also not shared...
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