0

According to MDN, cookies set with a path of '/' are available anywhere in the same domain. This is corroborated by several different sources.

However, I just haven't found this to be the case. I ran the following test on (nonexistent) directories on google.com using firefox:

> window.location = 'https://google.com/dir/file.html'
Navigated to https://google.com/dir/file.html
"https://google.com/dir/file.html"
> document.cookie
""
> document.cookie = 'key1=value1,path=/'
"key1=value1,path=/"
> document.cookie
"key1=value1,path=/"
> window.location = '/dir2/file.html'
Navigated to https://google.com/dir2/file.html
"/dir2/file.html"
> document.cookie
""

Am I misunderstanding something? What am I doing wrong? I tried similar tests on Chrome with the same result.

Joshua Nelson
  • 333
  • 3
  • 13

1 Answers1

0

Figured it out. I was setting path with a comma delimiter, not a semicolon delimiter. It was writing the cookie literally as I typed it, instead of interpreting the path and domain.

The correct way to write the cookie would have been document.cookie = 'key1=value1;path=/'.

Joshua Nelson
  • 333
  • 3
  • 13