Are HTTP cookies port specific?

前端 未结 8 1882
傲寒
傲寒 2020-11-22 04:14

I have two HTTP services running on one machine. I just want to know if they share their cookies or whether the browser distinguishes between the two server sockets.

相关标签:
8条回答
  • 2020-11-22 05:13

    The current cookie specification is RFC 6265, which replaces RFC 2109 and RFC 2965 (both RFCs are now marked as "Historic") and formalizes the syntax for real-world usages of cookies. It clearly states:

    1. Introduction

    ...

    For historical reasons, cookies contain a number of security and privacy infelicities. For example, a server can indicate that a given cookie is intended for "secure" connections, but the Secure attribute does not provide integrity in the presence of an active network attacker. Similarly, cookies for a given host are shared across all the ports on that host, even though the usual "same-origin policy" used by web browsers isolates content retrieved via different ports.

    And also:

    8.5. Weak Confidentiality

    Cookies do not provide isolation by port. If a cookie is readable by a service running on one port, the cookie is also readable by a service running on another port of the same server. If a cookie is writable by a service on one port, the cookie is also writable by a service running on another port of the same server. For this reason, servers SHOULD NOT both run mutually distrusting services on different ports of the same host and use cookies to store security sensitive information.

    0 讨论(0)
  • 2020-11-22 05:14

    This is a big gray area in cookie SOP (Same Origin Policy).

    Theoretically, you can specify port number in the domain and the cookie will not be shared. In practice, this doesn't work with several browsers and you will run into other issues. So this is only feasible if your sites are not for general public and you can control what browsers to use.

    The better approach is to get 2 domain names for the same IP and not relying on port numbers for cookies.

    0 讨论(0)
提交回复
热议问题