如何从子域获取 cookie?

How can I get the cookies from a subdomain?

假设我在 sub.example.org,如何从那里获取 .example.org 的 cookie?如果那不可能,是否有像 hack 或任何重定向到 .example.org 然后存储 cookie 的解决方法?

一个网页只能看到具有与其 URL 相匹配的最具体域的 cookie。

所以如果example.orgsub.example.org都有一个名为mycookie的cookie,sub.example.org中的网页只能访问子域中的网页。它将 cookie 隐藏在 example.org 域中,无法访问它。

但是如果 example.org 中只有一个 cookie,它对 example.orgsub.example.org 页面都可见。

创建 cookie 时,它​​默认为页面的完整域,但代码可以指定一个不太具体的域。因此,如果 sub.example.org 创建一个 cookie,它将默认为 domain=sub.example.org。但是代码可以通过明确地将 domain=.example.org 放入 cookie 中来覆盖它。

可以在 The Definitive Guide to Cookie Domains 中找到更多详细信息。

cookie 被设置为 HttpOnly 标志,浏览器让我无法获取 JavaScript 的 cookie。