Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cross subdomain cookie handling for session?

Is it possible to set an auth cookie that would be valid on:

  • sub1.domain.com
  • sub2.domain.com

Or will each subdomain always require it's own cookie?

like image 341
cjm2671 Avatar asked Dec 10 '11 16:12

cjm2671


People also ask

Are cookies available across subdomains?

Please everyone note that you can set a cookie from a subdomain on a domain. But you CAN'T set a cookie from a domain on a subdomain.

Is subdomain first party cookie?

Seems to have worked, so ASP.NET session cookies on different subdomains still count as first party. A cookie set on a website that is loaded in an iframe of a different website is considered to be a third party cookie to the parent website.

Does SameSite work for subdomains?

The concept of site is more difficult to apprehend than meets the eye. Some requests are cross-origin but same-site. SameSite only has effects on cross-site requests. SameSite paints a target on your subdomains' back.

Can a website set a cookie for another domain?

You cannot set cookies for another domain.


1 Answers

You can use cookies across sub domains if you specify the cookie to be attached to the domain:

.domain.com

note the dot in front.

See here for reference:

http://www.jotlab.com/2008/04/08/howto-get-cookies-across-subdomains-php/

like image 63
Richard Avatar answered Sep 20 '22 21:09

Richard