The answer to this question about how cookies are potentially vulnerable between sub-domains sparked my curiosity.
As far as I know, if a cookie is set on a sub-path of the same domain (www.example.com/dogs
), then it is not accessible to any other path, unless it's a sub-folder of the path. i.e. neither www.example.com/cats
nor www.example.com/
should have access to those cookies, but www.example.com/dogs/labrador
would.
Reading further, I see it's possible to get the cookies from different paths:
It is important to note that the path restriction does not protect against unauthorized reading of the cookie from a different path. It can easily be bypassed with simple DOM (for example by creating a hidden iframe element with the path of the cookie, then accessing this iframe's contentDocument.cookie property). The only way to protect cookie access is by using a different domain or subdomain, due to the same origin policy.
If that's the case, then what security (or even functionality) does the cookie-path provide? And if it can be read using an iframe, why isn't it accessible directly in javascript? Does this "restriction" actually give a false sense of security?