0

We have 2 test environments, which are:

Below is the cookie that is written on "test.example.com" domain. The user will reach the page where the cookie is written to their computer and then they will click a link that will take them to "test-example", which is our internal testing domain. I observed when they leave "test.example.com" and are taken to our internal testing domain "test-example" the cookie does not follow therefor I'm not able to read the cookie.

Would anyone be able to help with my code to allow the cookie to be read across our internal testing domain?

<script type="text/javascript">
var cookieName = 'HelloWorld';
var cookieValue = 'HelloWorld';
var myDate = new Date();
myDate.setMonth(myDate.getMonth() + 12);
document.cookie = cookieName +"=" + cookieValue + ";expires=" + myDate 
                  + ";domain=.example.com;path=/";
</script>
Evan
  • 3,111
  • 7
  • 32
  • 52

2 Answers2

3

Cookies cannot be shared across domains. This is a tenant of internet security.

Here's what you can do:

Elad
  • 3,085
  • 2
  • 18
  • 17
  • testing the flash cookie, that was pretty fun! this should work for us just fine, but ultimately, we should have our dev environments in the sub domains as you listed. great suggestion!! – Evan Apr 15 '11 at 20:50
  • @Evan glad you enjoyed it :) I agree that the subdomain is the better solution long-term. – Elad Apr 15 '11 at 20:58
1

This is impossible. The sites don't share a TLD and it would be incredibly inefficient (and somewhat risky from a security point of view) for a site to be able to say "Send my cookies to every site you visit".

Move the internal testing site to internal.test.example.com and see setting cross-subdomain cookie with javascript.

Community
  • 1
  • 1
Quentin
  • 800,325
  • 104
  • 1,079
  • 1,205