问题
I have a cookie set in the path of the parent domain ( which I have no control over). But I have an application running in one of the subdomains (I have access to this). How can I access the cookies set against the parent domain?
For instance, say I have the cookies:
Name Value Domain (not https)
ABC 1 .example.com
XYZ 0 foo.bar.example.com
The app is running on foo.bar.example.com and the cookie is set at .example.com It's a Java application. I tried to debug but I can only see the cookies set for the subdomain, not the primary domain.
Here's the source
Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (Cookie cookie : cookies) {
//Here I only see cookies set for the sub domain but not the parent domain. The cookies collection has no parent domain cookies.
}
}
Also according to this stackoverflow answer maybe the browser is not sending the parent domain cookies to the app?
I feel like I'm missing something elementary here. Any suggestions?
回答1:
The problem in my case was an external Proxy server (SSO server in my case) was filtering the cookies. So it was an environmental problem. I'm sure that parent domain cookies are available in normal environments.
来源:https://stackoverflow.com/questions/23018531/access-parent-domain-cookies-from-an-application-running-on-a-subdomain