RFC 6265: HTTP cookies: State on the web
Summary
In April 2011, Adam Barth described HTTP cookies in RFC 6265 as browsers and servers actually use them, rather than as earlier standards would have liked. The document specifies syntax, storage and return of cookies and openly names the historical weaknesses in confidentiality, integrity and isolation. It replaces RFC 2965 and declares its Cookie2 and Set-Cookie2 headers obsolete.
Describing what really happens
Cookies went back to an informal Netscape specification. Two earlier standardisation attempts, RFC 2109 and RFC 2965, never caught on in browsers. RFC 6265 therefore takes a different path and describes real behaviour, including its quirks. A server sets a name-value pair with Set-Cookie, and the browser automatically returns it in the Cookie header with matching requests.
Attributes limit the scope: Domain and Path determine where the cookie is sent, Expires and Max-Age its lifetime. Secure allows sending only over encrypted connections, and HttpOnly hides it from JavaScript. Browsers should be able to store at least 4,096 bytes per cookie, 50 cookies per domain and 3,000 cookies in total.
Honest about the weaknesses
The security section is unusually clear: cookies are a form of ambient authority because the browser attaches them automatically, and this encourages cross-site request forgery. They do not separate by port, and a subdomain can set or overwrite cookies for the parent domain, which weakens integrity.
The attribute SameSite against cross-site requests, so important today, is not in RFC 6265. It was added later through browsers and the revision rfc6265bis.
Ideas
- Servers set cookies via Set-Cookie, browsers send them back automatically.
- Domain and Path determine where a cookie goes.
- Secure restricts sending to encrypted connections.
- HttpOnly keeps cookies away from JavaScript.
- Cookies do not isolate by port.
- Automatically attached cookies encourage cross-site request forgery.
Insights
- A standard that describes what is actually implemented is more likely to catch on than one that prescribes what should be.
- Convenient automatic state is at the same time the root of many web security problems; protection must therefore be set explicitly.
Facts
- RFC 6265 appeared in April 2011 and replaces RFC 2965.
- Browsers should store at least 4,096 bytes per cookie, 50 cookies per domain and 3,000 in total.
- RFC 6265 declares Cookie2 and Set-Cookie2 obsolete.
- The SameSite attribute is not part of RFC 6265.
References
- RFC 6265: HTTP State Management Mechanism
- RFC 2965: HTTP State Management Mechanism (2000)
- RFC 6797: HTTP Strict Transport Security (HSTS) (2012)
Remarks
- RFC 6265 does not address privacy questions around tracking cookies; they were tackled later through browser settings and laws such as the ePrivacy rules.
Recommendations
- Always set session cookies with Secure, HttpOnly and SameSite=Lax or Strict.
- Omit the Domain attribute if a cookie should only apply to your own host.
- Use cookie prefixes such as __Host-, which modern browsers evaluate for additional protection rules.
Read the RFC at the RFC Editor
Found a mistake or have something to add? Get in touch.
Links to the original source and the Web Archive open in a new tab.