Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cookie name length, uniqueness

Tags:

cookies

I want to know what is the maximum value of the cookie name? Is the cookie name unique per domain, and/or path?

like image 337
Ahmed Kamal Avatar asked Sep 27 '11 18:09

Ahmed Kamal


People also ask

How long can a cookie name be?

After the spec change corresponding to this Intent, user agents are now required to limit the sum of the lengths of the cookie's name and value to 4096 bytes, and limit the length of each cookie attribute value to 1024 bytes.

Should cookie names be unique?

A cookie name must be, like Jay said, unique within a path.

Can you have cookies with the same name?

There is nothing wrong with having multiple values for the same name... if you want them. You might even embed additional context in the value.


1 Answers

All those informations are specified in RFC 2965 - HTTP State Management Mechanism.

A cookie name must be, like Jay said, unique within a path.

The RFC also specifies that there should be no maximum length of a cookie's name or value (in ) :

From chapter 5.3 - Implementation Limits

Practical user agent implementations have limits on the number and size of cookies that they can store. In general, user agents' cookie support should have no fixed limits. They should strive to store as many frequently-used cookies as possible. Furthermore, general-use user agents SHOULD provide each of the following minimum capabilities individually, although not necessarily simultaneously:

  1. at least 300 cookies
  2. at least 4096 bytes per cookie (as measured by the characters that comprise the cookie non-terminal in the syntax description of the Set-Cookie2 header, and as received in the Set-Cookie2 header)
  3. at least 20 cookies per unique host or domain name

User agents created for specific purposes or for limited-capacity devices SHOULD provide at least 20 cookies of 4096 bytes, to ensure that the user can interact with a session-based origin server...

In practice, each browsers defines it's own maximum length. For more concrete data on the subject, you can consult the following stackoverflow question : What is the maximum size of a web browser's cookie's key?.

like image 135
Marc Wrobel Avatar answered Oct 11 '22 10:10

Marc Wrobel