Cookie 可以在不同服务器上通过 SSL 在子域之间共享吗?

Can cookies be shared between subdomains over SSL on different servers?

我们正在评估以下单点登录解决方案的可行性。

场景。 网站域名。 https://www.example.com

其他门户。 https://portal.example.com

解决方法: 目的是在 www.example.com 和 portal.example.com 子域之间共享一个 cookie,但是,为此,SSL 协议需要满足以下要求:

问题是:在私钥或 SSL 协议本身方面是否有任何限制会使上述解决方案不可行?

谢谢,

是的,如果客户端浏览器信任您购买证书的 CA,您的解决方案将有效并减轻大多数 MITM 攻击。

如果 cookie 设置域 example.com,它将在 www.example.comportal.example.com 之间共享。还建议设置安全标志以确保它不能通过纯 HTTP 传输。我假设 www.example.comportal.example.com 都有一个服务器端机制来验证 cookie 值以授权每个请求。

RFC 6265 状态:

The Domain attribute specifies those hosts to which the cookie will be sent. For example, if the value of the Domain attribute is "example.com", the user agent will include the cookie in the Cookie header when making HTTP requests to example.com, www.example.com, and www.corp.example.com.

旧的 RFC 2109 指定您需要在域前添加 .,但是 6265 覆盖了它。这意味着如果您想共享 cookie 并使其与 非常旧的 浏览器兼容,您应该将 cookie 设置为域 .example.com 而不是 example.com。执行前者不会有任何损失,因为较新的浏览器会简单地忽略该点。

在您的解决方案中,服务器 1 和服务器 2 都将接收并能够解密 cookie。请注意,不需要两个服务器都具有相同的证书 - 它们都将使用它们安装的私钥(或者更确切地说是使用它们安装的私钥传输的共享对称密钥 - 准确地说)独立地解密 SSL 会话。

但是,为 *.example.com 使用通配符证书会更便宜,因为可以在两台服务器上安装相同的证书。