Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is a host only cookie?

I would like to know what is a host only cookie.

While retrieving a form auth, browser gets in the headers a JSESSIONID cookie shown as host only.

like image 633
jacktrades Avatar asked Sep 12 '12 11:09

jacktrades


People also ask

What is a session only cookie?

Session only cookies, on the other hand, stores information in the browser memory, and is available for the duration of the browser session. In other words, the data stored inside a session cookie is available from the time of storage until the browser is closed.

Are session cookies safe?

Session cookies store information about a user session after the user logs in to an application. This information is very sensitive, since an attacker can use a session cookie to impersonate the victim (see more about Session Hijacking).

What is a server cookie?

An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. The browser may store the cookie and send it back to the same server with later requests.

How do I read HttpOnly cookies?

An HttpOnly cookie cannot be accessed by client-side APIs, such as JavaScript. This restriction eliminates the threat of cookie theft via cross-site scripting (XSS). If the browser allowed you to access it then it would be a defect in the browser.


2 Answers

First of all, it is not possible for foo.com to set a cookie that can be read by bar.com. Host-only only protects example.com cookies from being read by bar.example.com.

From RFC 6265 regarding setting a cookie and its Domain attribute:

If the domain-attribute is non-empty:    If the canonicalized request-host does not domain-match the domain-attribute:      Ignore the cookie entirely and abort these steps.    Otherwise:      Set the cookie's host-only-flag to false.      Set the cookie's domain to the domain-attribute.  Otherwise:    Set the cookie's host-only-flag to true.    Set the cookie's domain to the canonicalized request-host. 

What this means

The above can be summed up by "Host-only is the default". That is, if Domain is not specified, the cookie can only be read by the exact domain that has set the cookie. This can be loosened by setting the Domain attribute when setting a cookie.

For example, if the cookie is set by www.example.com and the Domain attribute is not specified, the cookie will be set with domain www.example.com and the cookie will be a host only cookie.

Another example: If the cookie is set by www.example.com and the Domain attribute is specified as example.com (so the cookie will be sent to foo.example.com too), the cookie will be set with domain example.com (or possibly .example.com by some browsers that use the dot from the previous RFC 2109 to denote not host-only) and the cookie will not be a host only cookie.

Sending of cookies is covered in section 5.4 regarding the when the cookie header is sent by the browser:

         The cookie's host-only-flag is true and the canonicalized          request-host is identical to the cookie's domain.       Or:          The cookie's host-only-flag is false and the canonicalized          request-host domain-matches the cookie's domain. 

So a cookie with domain example.com and host-only as false is sent to foo.example.com . If host-only is true, the example.com cookie is sent to example.com only.

like image 134
SilverlightFox Avatar answered Oct 06 '22 04:10

SilverlightFox


Host Only cookie means that the cookie should be handled by the browser to the server only to the same host/server that firstly sent it to the browser.

You don't want to send this host only cookie for ad campaigns, as it might contain sensitive information.

like image 36
jacktrades Avatar answered Oct 06 '22 03:10

jacktrades