简体   繁体   中英

Access parent domain cookies from an application running on a subdomain

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM