Reputation: 338
Let's assume I'm on sub.example.org
, how can I get the cookies of .example.org
from there? If that's not possible, is there a workaround like an hack or whatever that redirects to .example.org
and then stores the cookies?
Upvotes: 3
Views: 11951
Reputation: 338
The cookie was set as HttpOnly
flag, and the browser made me not able to get the cookie for JavaScript.
Upvotes: 3
Reputation: 782407
A web page only has visibility to the cookie with the most specific domain that matches its URL.
So if both example.org
and sub.example.org
both have a cookie named mycookie
, a web page in sub.example.org
can only access the one in the subdomain. It hides the cookie in the example.org
domain, and there's no way to access it.
But if there's only a cookie in example.org
, it will be visible to both example.org
and sub.example.org
pages.
When creating a cookie, it defaults to the full domain of the page, but the code can specify a less specific domain. So if sub.example.org
creates a cookie, it will default to domain=sub.example.org
. But the code can override this by putting domain=.example.org
in the cookie explicitly.
More details can be found in The Definitive Guide to Cookie Domains.
Upvotes: 11