CINXE.COM
RFC 6265 - HTTP State Management Mechanism
<!DOCTYPE html SYSTEM "about:legacy-compat"> <html lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>RFC 6265 - HTTP State Management Mechanism</title><script> function getMeta(rfcno, container) { var xhr = new XMLHttpRequest(); xhr.open("GET", "https://www.rfc-editor.org/rfc/rfc" + rfcno + ".json", true); xhr.onload = function (e) { if (xhr.readyState === 4) { if (xhr.status === 200) { var data = JSON.parse(xhr.response); var cont = document.getElementById(container); // empty the container while (cont.firstChild) { cont.removeChild(myNode.firstChild); } var c = data.status; if (c) { var bld = newElementWithText("b", c); cont.appendChild(bld); } else { cont.appendChild(newElementWithText("i", "(document status unknown)")); } c = data.updated_by; if (c && c.length > 0 && c[0] !== null && c[0].length > 0) { cont.appendChild(newElement("br")); cont.appendChild(newText("Updated by: ")); appendRfcLinks(cont, c); } c = data.obsoleted_by; if (c && c.length > 0 && c[0] !== null && c[0].length > 0) { cont.appendChild(newElement("br")); cont.appendChild(newText("Obsoleted by: ")); appendRfcLinks(cont, c); } c = data.errata_url; if (c) { cont.appendChild(newElement("br")); var link = newElementWithText("a", "errata"); link.setAttribute("href", c); var errata = newElementWithText("i", "This document has "); errata.appendChild(link); errata.appendChild(newText(".")); cont.appendChild(errata); } cont.style.display = "block"; } else { console.error(xhr.statusText); } } }; xhr.onerror = function (e) { console.error(xhr.status + " " + xhr.statusText); }; xhr.send(null); } function appendRfcLinks(parent, updates) { var template = "https://www.rfc-editor.org/rfc/rfc{rfc}.html"; for (var i = 0; i < updates.length; i++) { var rfc = updates[i].trim().toLowerCase(); if (rfc.substring(0, 3) == "rfc") { var no = parseInt(rfc.substring(3), 10); var link = newElement("a"); link.setAttribute("href", template.replace("{rfc}", no)); link.appendChild(newText(no)); parent.appendChild(link); } else { parent.appendChild(newText(rfc)); } if (i != updates.length - 1) { parent.appendChild(newText(", ")); } } } // DOM helpers function newElement(name) { return document.createElement(name); } function newElementWithText(name, txt) { var e = document.createElement(name); e.appendChild(newText(txt)); return e; } function newText(text) { return document.createTextNode(text); } </script><script> function anchorRewrite() { map = { }; if (window.location.hash.length >= 1) { var fragid = window.location.hash.substr(1); if (fragid) { if (! document.getElementById(fragid)) { var prefix = "rfc."; var mapped = map[fragid]; if (mapped) { window.location.hash = mapped; } else if (fragid.indexOf("section-") == 0) { window.location.hash = prefix + "section." + fragid.substring(8).replace("-",".p."); } else if (fragid.indexOf("appendix-") == 0) { window.location.hash = prefix + "section." + fragid.substring(9).replace("-",".p."); } else if (fragid.indexOf("s-") == 0) { var postfix = fragid.substring(2); if (postfix.startsWith("abstract")) { window.location.hash = prefix + postfix; } else if (postfix.startsWith("note-")) { window.location.hash = prefix + "note." + postfix.substring(5).replace("-",".p."); } else { window.location.hash = prefix + "section." + postfix.replace("-",".p."); } } else if (fragid.indexOf("p-") == 0) { var r = fragid.substring(2); var p = r.indexOf("-"); if (p >= 0) { window.location.hash = prefix + "section." + r.substring(0, p) + ".p." + r.substring(p + 1); } } } } } } window.addEventListener('hashchange', anchorRewrite); window.addEventListener('DOMContentLoaded', anchorRewrite); </script><meta name="viewport" content="width=device-width, initial-scale=1"><meta property="og:type" content="article"><meta property="og:title" content="RFC6265"><meta property="og:description" content="HTTP State Management Mechanism"><meta property="og:url" content="https://httpwg.org/specs/rfc6265.html"><meta property="og:site_name" content="IETF HTTP Working Group Specifications"><meta property="og:image" content="https://httpwg.org/assets/favicon/apple-icon-180x180.png"><link rel="stylesheet" type="text/css" href="/assets/node_modules/bootstrap/dist/css/bootstrap.min.css"><style type="text/css"> body { padding-top: 80px; padding-bottom: 80px; position: relative; } .table.header th, .table.header td { border-top: none; padding: 0; } #sidebar { margin-top: -10px; height: 90%; overflow-y: auto; font-size: 90%; } #rfc\.meta { width: 40%; float: right } .toc ul { list-style: none; } .filename { color: rgb(119, 119, 119); font-size: 23px; font-weight: normal; height: auto; line-height: 23px; } dl { margin-left: 1em; } dl.dl-horizontal: { margin-left: 0; } dl > dt { float: left; margin-right: 1em; } dl.nohang > dt { float: none; } dl > dd { margin-bottom: .5em; } dl.compact > dd { margin-bottom: 0em; } dl > dd > dl { margin-top: 0.5em; margin-bottom: 0em; } ul.empty { list-style-type: none; } ul.empty li { margin-top: .5em; } td.reference { padding-right: 1em; vertical-align: top; } .feedback { position: fixed; bottom: 5px; right: 5px; } .fbbutton { margin-left: 5px; } h1 a, h2 a, h3 a, h4 a, h5 a, h6 a { color: rgb(51, 51, 51); } span.tt { font: 11pt consolas, monospace; font-size-adjust: none; } </style><link rel="stylesheet" type="text/css" href="/assets/site.css"><link rel="Contents" href="#rfc.toc"><link rel="Author" href="#rfc.authors"><link rel="License" href="#rfc.copyrightnotice"><link rel="Chapter" title="1 Introduction" href="#rfc.section.1"><link rel="Chapter" title="2 Conventions" href="#rfc.section.2"><link rel="Chapter" title="3 Overview" href="#rfc.section.3"><link rel="Chapter" title="4 Server Requirements" href="#rfc.section.4"><link rel="Chapter" title="5 User Agent Requirements" href="#rfc.section.5"><link rel="Chapter" title="6 Implementation Considerations" href="#rfc.section.6"><link rel="Chapter" title="7 Privacy Considerations" href="#rfc.section.7"><link rel="Chapter" title="8 Security Considerations" href="#rfc.section.8"><link rel="Chapter" title="9 IANA Considerations" href="#rfc.section.9"><link rel="Chapter" title="10 References" href="#rfc.section.10"><link rel="Appendix" title="A Acknowledgements" href="#rfc.section.A"><link rel="Alternate" title="Plain Text Version" href="http://www.ietf.org/rfc/rfc6265.txt"><link rel="Help" title="RFC-Editor's Status Page" href="http://www.rfc-editor.org/info/rfc6265"><meta name="viewport" content="initial-scale=1"><meta name="generator" content="https://github.com/mnot/RFCBootstrap XSLT vendor: Saxonica http://www.saxonica.com/"><meta name="keywords" content="Cookie, Set-Cookie, Secure, HttpOnly"><link rel="schema.dcterms" href="http://purl.org/dc/terms/"><meta name="dcterms.creator" content="Barth, A."><meta name="dcterms.identifier" content="urn:ietf:rfc:6265"><meta name="dcterms.issued" content="2011-04"><meta name="dct.replaces" content="urn:ietf:rfc:2965"><meta name="dcterms.abstract" content="This document defines the HTTP Cookie and Set-Cookie header fields. These header fields can be used by HTTP servers to store state (called cookies) at HTTP user agents, letting the servers maintain a stateful session over the mostly stateless HTTP protocol. Although cookies have many historical infelicities that degrade their security and privacy, the Cookie and Set-Cookie header fields are widely used on the Internet. This document obsoletes RFC 2965."><meta name="dcterms.isPartOf" content="urn:issn:2070-1721"><meta name="description" content="This document defines the HTTP Cookie and Set-Cookie header fields. These header fields can be used by HTTP servers to store state (called cookies) at HTTP user agents, letting the servers maintain a stateful session over the mostly stateless HTTP protocol. Although cookies have many historical infelicities that degrade their security and privacy, the Cookie and Set-Cookie header fields are widely used on the Internet. This document obsoletes RFC 2965."></head><body onload="getMeta(6265,"rfc.meta");"><nav class="navbar navbar-dark bg-dark d-print-none navbar-expand-lg fixed-top ps-3 pe-3" role="navigation"> <!-- Brand and toggle get grouped for better mobile display --> <div class="navbar-header"> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbar-collapse" aria-controls="navbarToggler" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <a class="navbar-brand" href="https://httpwg.org/"><img src="https://httpwg.org/assets/http.svg" height="23"></a> </div> <div class="collapse navbar-collapse" id="navbar-collapse"> <div class="navbar-nav me-auto"> <a class="nav-item ms-1 text-white" href="https://httpwg.org/specs/">📄 Documentation</a> <div class="dropdown ms-4"> <a href="#" class="nav-item dropdown-toggle text-white" data-bs-toggle="dropdown">Work in Progress</a> <ul class="dropdown-menu"><li class="dropdown-item"><a href="https://httpwg.org/http-extensions/">HTTP Extensions</a></li><li class="dropdown-item"><a href="https://github.com/httpwg/admin/issues?q=is%3Aissue+is%3Aopen+label%3Aadoption">Future Work</a></li></ul> </div> <div class="dropdown ms-4"> <a href="#" class="nav-item dropdown-toggle text-white" data-bs-toggle="dropdown">Participate</a> <ul class="dropdown-menu"><li class="dropdown-item"><a href="https://httpwg.org/about/">About the HTTP Working Group</a></li><li class="divider"></li><li class="dropdown-item"><a href="https://httpwg.org/CONTRIBUTING.html">Contribution Policy</a></li><li class="dropdown-item"><a href="http://datatracker.ietf.org/wg/httpbis/charter/">WG Charter</a></li><li class="dropdown-item"><a href="http://lists.w3.org/Archives/Public/ietf-http-wg/">Group Mailing List 📨</a></li><li class="dropdown-item"><a href="https://httpwg.org/wg-materials/">Meeting Materials</a></li><li class="dropdown-item"><a href="https://httpwg.org/admin/editors/">Document Editor Resources</a></li></ul> </div> </div> </div> </nav><div class="container" id="top"><div class="row"><div class="col-lg-4 order-last d-none d-lg-block" id="sidebar" role="navigation"><div class="navbar"><div class="navbar-brand"><a href="#top"><strong>RFC </strong>6265</a></div><br clear="all"><div class=""><div class="toc "><ul><li><a href="#rfc.section.1">1.</a> <a href="#intro">Introduction</a></li><li><a href="#rfc.section.2">2.</a> <a href="#conventions">Conventions</a><ul><li><a href="#rfc.section.2.1">2.1.</a> <a href="#conformance-criteria">Conformance Criteria</a></li><li><a href="#rfc.section.2.2">2.2.</a> <a href="#syntax-notation">Syntax Notation</a></li><li><a href="#rfc.section.2.3">2.3.</a> <a href="#terminology">Terminology</a></li></ul></li><li><a href="#rfc.section.3">3.</a> <a href="#overview">Overview</a><ul><li><a href="#rfc.section.3.1">3.1.</a> <a href="#rfc.section.3.1">Examples</a></li></ul></li><li><a href="#rfc.section.4">4.</a> <a href="#sane-profile">Server Requirements</a><ul><li><a href="#rfc.section.4.1">4.1.</a> <a href="#sane-set-cookie">Set-Cookie</a><ul><li><a href="#rfc.section.4.1.1">4.1.1.</a> <a href="#sane-set-cookie-syntax">Syntax</a></li><li><a href="#rfc.section.4.1.2">4.1.2.</a> <a href="#sane-set-cookie-semantics">Semantics (Non-Normative)</a></li></ul></li><li><a href="#rfc.section.4.2">4.2.</a> <a href="#sane-cookie">Cookie</a><ul><li><a href="#rfc.section.4.2.1">4.2.1.</a> <a href="#sane-cookie-syntax">Syntax</a></li><li><a href="#rfc.section.4.2.2">4.2.2.</a> <a href="#sane-cookie-semantics">Semantics</a></li></ul></li></ul></li><li><a href="#rfc.section.5">5.</a> <a href="#ua-requirements">User Agent Requirements</a><ul><li><a href="#rfc.section.5.1">5.1.</a> <a href="#algorithms">Subcomponent Algorithms</a><ul><li><a href="#rfc.section.5.1.1">5.1.1.</a> <a href="#cookie-date">Dates</a></li><li><a href="#rfc.section.5.1.2">5.1.2.</a> <a href="#cookie-domain-canonicalize">Canonicalized Host Names</a></li><li><a href="#rfc.section.5.1.3">5.1.3.</a> <a href="#cookie-domain">Domain Matching</a></li><li><a href="#rfc.section.5.1.4">5.1.4.</a> <a href="#cookie-path">Paths and Path-Match</a></li></ul></li><li><a href="#rfc.section.5.2">5.2.</a> <a href="#set-cookie">The Set-Cookie Header</a><ul><li><a href="#rfc.section.5.2.1">5.2.1.</a> <a href="#expires-attribute">The Expires Attribute</a></li><li><a href="#rfc.section.5.2.2">5.2.2.</a> <a href="#max-age-attribute">The Max-Age Attribute</a></li><li><a href="#rfc.section.5.2.3">5.2.3.</a> <a href="#domain-attribute">The Domain Attribute</a></li><li><a href="#rfc.section.5.2.4">5.2.4.</a> <a href="#path-attribute">The Path Attribute</a></li><li><a href="#rfc.section.5.2.5">5.2.5.</a> <a href="#secure-attribute">The Secure Attribute</a></li><li><a href="#rfc.section.5.2.6">5.2.6.</a> <a href="#httponly-attribute">The HttpOnly Attribute</a></li></ul></li><li><a href="#rfc.section.5.3">5.3.</a> <a href="#storage-model">Storage Model</a></li><li><a href="#rfc.section.5.4">5.4.</a> <a href="#cookie">The Cookie Header</a></li></ul></li><li><a href="#rfc.section.6">6.</a> <a href="#implementation-considerations">Implementation Considerations</a><ul><li><a href="#rfc.section.6.1">6.1.</a> <a href="#implementation-limits">Limits</a></li><li><a href="#rfc.section.6.2">6.2.</a> <a href="#implementation-apis">Application Programming Interfaces</a></li><li><a href="#rfc.section.6.3">6.3.</a> <a href="#idna-migration">IDNA Dependency and Migration</a></li></ul></li><li><a href="#rfc.section.7">7.</a> <a href="#privacy-considerations">Privacy Considerations</a><ul><li><a href="#rfc.section.7.1">7.1.</a> <a href="#third-party-cookies">Third-Party Cookies</a></li><li><a href="#rfc.section.7.2">7.2.</a> <a href="#user-controls">User Controls</a></li><li><a href="#rfc.section.7.3">7.3.</a> <a href="#expiration-dates">Expiration Dates</a></li></ul></li><li><a href="#rfc.section.8">8.</a> <a href="#security-considerations">Security Considerations</a><ul><li><a href="#rfc.section.8.1">8.1.</a> <a href="#section-overview">Overview</a></li><li><a href="#rfc.section.8.2">8.2.</a> <a href="#ambient-authority">Ambient Authority</a></li><li><a href="#rfc.section.8.3">8.3.</a> <a href="#clear-text">Clear Text</a></li><li><a href="#rfc.section.8.4">8.4.</a> <a href="#session-identifiers">Session Identifiers</a></li><li><a href="#rfc.section.8.5">8.5.</a> <a href="#weak-confidentiality">Weak Confidentiality</a></li><li><a href="#rfc.section.8.6">8.6.</a> <a href="#weak-integrity">Weak Integrity</a></li><li><a href="#rfc.section.8.7">8.7.</a> <a href="#reliance-on-dns">Reliance on DNS</a></li></ul></li><li><a href="#rfc.section.9">9.</a> <a href="#iana-considerations">IANA Considerations</a><ul><li><a href="#rfc.section.9.1">9.1.</a> <a href="#rfc.section.9.1">Cookie</a></li><li><a href="#rfc.section.9.2">9.2.</a> <a href="#rfc.section.9.2">Set-Cookie</a></li><li><a href="#rfc.section.9.3">9.3.</a> <a href="#rfc.section.9.3">Cookie2</a></li><li><a href="#rfc.section.9.4">9.4.</a> <a href="#rfc.section.9.4">Set-Cookie2</a></li></ul></li><li><a href="#rfc.section.10">10.</a> <a href="#rfc.references">References</a><ul><li><a href="#rfc.section.10.1">10.1.</a> <a href="#rfc.references.1">Normative References</a></li><li><a href="#rfc.section.10.2">10.2.</a> <a href="#rfc.references.2">Informative References</a></li></ul></li><li><a href="#rfc.section.A">Appendix A.</a> <a href="#rfc.section.A">Acknowledgements</a></li><li><a href="#rfc.authors">Author's Address</a></li></ul></div></div></div></div><div class="col-lg-8 order-first main" role="main"><header><table class="table table-condensed header" id="rfc.headerblock"><tbody><tr><td class="text-left">Internet Engineering Task Force (IETF)</td><td class="text-right">A. Barth</td></tr><tr><td class="text-left">Request for Comments: 6265</td><td class="text-right">U.C. Berkeley</td></tr><tr><td class="text-left">Obsoletes: <a href="#RFC2965">2965</a></td><td class="text-right">April 2011</td></tr><tr><td class="text-left">Category: Standards Track</td><td class="text-right"></td></tr><tr><td class="text-left">ISSN: 2070-1721</td><td class="text-right"></td></tr></tbody></table><div id="rfc.title"><h1>HTTP State Management Mechanism</h1></div></header><hr><h2 id="rfc.abstract"><a href="#rfc.abstract">Abstract</a></h2><div class="lead"><div id="rfc.abstract.p.1"><p>This document defines the HTTP Cookie and Set-Cookie header fields. These header fields can be used by HTTP servers to store state (called cookies) at HTTP user agents, letting the servers maintain a stateful session over the mostly stateless HTTP protocol. Although cookies have many historical infelicities that degrade their security and privacy, the Cookie and Set-Cookie header fields are widely used on the Internet. This document obsoletes RFC 2965.</p></div></div><aside id="rfc.meta" class="alert alert-info"></aside><section id="rfc.status"><h2><a href="#rfc.status">Status of This Memo</a></h2><div id="rfc.boilerplate.1.p.1"><p>This is an Internet Standards Track document.</p></div><div id="rfc.boilerplate.1.p.2"><p>This document is a product of the Internet Engineering Task Force (IETF). It represents the consensus of the IETF community. It has received public review and has been approved for publication by the Internet Engineering Steering Group (IESG). Further information on Internet Standards is available in <a href="https://www.rfc-editor.org/rfc/rfc5741.html#section-2">Section 2 of RFC 5741</a>.</p></div><div id="rfc.boilerplate.1.p.3"><p>Information about the current status of this document, any errata, and how to provide feedback on it may be obtained at <a href="http://www.rfc-editor.org/info/rfc6265">http://www.rfc-editor.org/info/rfc6265</a>.</p></div></section><section id="rfc.copyrightnotice"><h2><a href="#rfc.copyrightnotice">Copyright Notice</a></h2><div id="rfc.boilerplate.2.p.1"><p>Copyright (c) 2011 IETF Trust and the persons identified as the document authors. All rights reserved.</p></div><div id="rfc.boilerplate.2.p.2"><p>This document is subject to BCP 78 and the IETF Trust's Legal Provisions Relating to IETF Documents (<a href="http://trustee.ietf.org/license-info">http://trustee.ietf.org/license-info</a>) in effect on the date of publication of this document. Please review these documents carefully, as they describe your rights and restrictions with respect to this document. Code Components extracted from this document must include Simplified BSD License text as described in Section 4.e of the Trust Legal Provisions and are provided without warranty as described in the Simplified BSD License.</p></div><div id="rfc.boilerplate.2.p.3"><p>This document may contain material from IETF Documents or IETF Contributions published or made publicly available before November 10, 2008. The person(s) controlling the copyright in some of this material may not have granted the IETF Trust the right to allow modifications of such material outside the IETF Standards Process. Without obtaining an adequate license from the person(s) controlling the copyright in such materials, this document may not be modified outside the IETF Standards Process, and derivative works of it may not be created outside the IETF Standards Process, except to format it for publication as an RFC or to translate it into languages other than English.</p></div></section><div class="toc d-lg-none"><ul><li><a href="#rfc.section.1">1.</a> <a href="#intro">Introduction</a></li><li><a href="#rfc.section.2">2.</a> <a href="#conventions">Conventions</a><ul><li><a href="#rfc.section.2.1">2.1.</a> <a href="#conformance-criteria">Conformance Criteria</a></li><li><a href="#rfc.section.2.2">2.2.</a> <a href="#syntax-notation">Syntax Notation</a></li><li><a href="#rfc.section.2.3">2.3.</a> <a href="#terminology">Terminology</a></li></ul></li><li><a href="#rfc.section.3">3.</a> <a href="#overview">Overview</a><ul><li><a href="#rfc.section.3.1">3.1.</a> <a href="#rfc.section.3.1">Examples</a></li></ul></li><li><a href="#rfc.section.4">4.</a> <a href="#sane-profile">Server Requirements</a><ul><li><a href="#rfc.section.4.1">4.1.</a> <a href="#sane-set-cookie">Set-Cookie</a><ul><li><a href="#rfc.section.4.1.1">4.1.1.</a> <a href="#sane-set-cookie-syntax">Syntax</a></li><li><a href="#rfc.section.4.1.2">4.1.2.</a> <a href="#sane-set-cookie-semantics">Semantics (Non-Normative)</a></li></ul></li><li><a href="#rfc.section.4.2">4.2.</a> <a href="#sane-cookie">Cookie</a><ul><li><a href="#rfc.section.4.2.1">4.2.1.</a> <a href="#sane-cookie-syntax">Syntax</a></li><li><a href="#rfc.section.4.2.2">4.2.2.</a> <a href="#sane-cookie-semantics">Semantics</a></li></ul></li></ul></li><li><a href="#rfc.section.5">5.</a> <a href="#ua-requirements">User Agent Requirements</a><ul><li><a href="#rfc.section.5.1">5.1.</a> <a href="#algorithms">Subcomponent Algorithms</a><ul><li><a href="#rfc.section.5.1.1">5.1.1.</a> <a href="#cookie-date">Dates</a></li><li><a href="#rfc.section.5.1.2">5.1.2.</a> <a href="#cookie-domain-canonicalize">Canonicalized Host Names</a></li><li><a href="#rfc.section.5.1.3">5.1.3.</a> <a href="#cookie-domain">Domain Matching</a></li><li><a href="#rfc.section.5.1.4">5.1.4.</a> <a href="#cookie-path">Paths and Path-Match</a></li></ul></li><li><a href="#rfc.section.5.2">5.2.</a> <a href="#set-cookie">The Set-Cookie Header</a><ul><li><a href="#rfc.section.5.2.1">5.2.1.</a> <a href="#expires-attribute">The Expires Attribute</a></li><li><a href="#rfc.section.5.2.2">5.2.2.</a> <a href="#max-age-attribute">The Max-Age Attribute</a></li><li><a href="#rfc.section.5.2.3">5.2.3.</a> <a href="#domain-attribute">The Domain Attribute</a></li><li><a href="#rfc.section.5.2.4">5.2.4.</a> <a href="#path-attribute">The Path Attribute</a></li><li><a href="#rfc.section.5.2.5">5.2.5.</a> <a href="#secure-attribute">The Secure Attribute</a></li><li><a href="#rfc.section.5.2.6">5.2.6.</a> <a href="#httponly-attribute">The HttpOnly Attribute</a></li></ul></li><li><a href="#rfc.section.5.3">5.3.</a> <a href="#storage-model">Storage Model</a></li><li><a href="#rfc.section.5.4">5.4.</a> <a href="#cookie">The Cookie Header</a></li></ul></li><li><a href="#rfc.section.6">6.</a> <a href="#implementation-considerations">Implementation Considerations</a><ul><li><a href="#rfc.section.6.1">6.1.</a> <a href="#implementation-limits">Limits</a></li><li><a href="#rfc.section.6.2">6.2.</a> <a href="#implementation-apis">Application Programming Interfaces</a></li><li><a href="#rfc.section.6.3">6.3.</a> <a href="#idna-migration">IDNA Dependency and Migration</a></li></ul></li><li><a href="#rfc.section.7">7.</a> <a href="#privacy-considerations">Privacy Considerations</a><ul><li><a href="#rfc.section.7.1">7.1.</a> <a href="#third-party-cookies">Third-Party Cookies</a></li><li><a href="#rfc.section.7.2">7.2.</a> <a href="#user-controls">User Controls</a></li><li><a href="#rfc.section.7.3">7.3.</a> <a href="#expiration-dates">Expiration Dates</a></li></ul></li><li><a href="#rfc.section.8">8.</a> <a href="#security-considerations">Security Considerations</a><ul><li><a href="#rfc.section.8.1">8.1.</a> <a href="#section-overview">Overview</a></li><li><a href="#rfc.section.8.2">8.2.</a> <a href="#ambient-authority">Ambient Authority</a></li><li><a href="#rfc.section.8.3">8.3.</a> <a href="#clear-text">Clear Text</a></li><li><a href="#rfc.section.8.4">8.4.</a> <a href="#session-identifiers">Session Identifiers</a></li><li><a href="#rfc.section.8.5">8.5.</a> <a href="#weak-confidentiality">Weak Confidentiality</a></li><li><a href="#rfc.section.8.6">8.6.</a> <a href="#weak-integrity">Weak Integrity</a></li><li><a href="#rfc.section.8.7">8.7.</a> <a href="#reliance-on-dns">Reliance on DNS</a></li></ul></li><li><a href="#rfc.section.9">9.</a> <a href="#iana-considerations">IANA Considerations</a><ul><li><a href="#rfc.section.9.1">9.1.</a> <a href="#rfc.section.9.1">Cookie</a></li><li><a href="#rfc.section.9.2">9.2.</a> <a href="#rfc.section.9.2">Set-Cookie</a></li><li><a href="#rfc.section.9.3">9.3.</a> <a href="#rfc.section.9.3">Cookie2</a></li><li><a href="#rfc.section.9.4">9.4.</a> <a href="#rfc.section.9.4">Set-Cookie2</a></li></ul></li><li><a href="#rfc.section.10">10.</a> <a href="#rfc.references">References</a><ul><li><a href="#rfc.section.10.1">10.1.</a> <a href="#rfc.references.1">Normative References</a></li><li><a href="#rfc.section.10.2">10.2.</a> <a href="#rfc.references.2">Informative References</a></li></ul></li><li><a href="#rfc.section.A">Appendix A.</a> <a href="#rfc.section.A">Acknowledgements</a></li><li><a href="#rfc.authors">Author's Address</a></li></ul></div><section id="intro"><h2 id="rfc.section.1" class="np"><a href="#rfc.section.1">1.</a> <a href="#intro">Introduction</a></h2><div id="rfc.section.1.p.1"><p>This document defines the HTTP Cookie and Set-Cookie header fields. Using the Set-Cookie header field, an HTTP server can pass name/value pairs and associated metadata (called cookies) to a user agent. When the user agent makes subsequent requests to the server, the user agent uses the metadata and other information to determine whether to return the name/value pairs in the Cookie header.</p></div><div id="rfc.section.1.p.2"><p>Although simple on their surface, cookies have a number of complexities. For example, the server indicates a scope for each cookie when sending it to the user agent. The scope indicates the maximum amount of time in which the user agent should return the cookie, the servers to which the user agent should return the cookie, and the URI schemes for which the cookie is applicable.</p></div><div id="rfc.section.1.p.3"><p>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.</p></div><div id="rfc.section.1.p.4"><p>There are two audiences for this specification: developers of cookie-generating servers and developers of cookie-consuming user agents.</p></div><div id="rfc.section.1.p.5"><p>To maximize interoperability with user agents, servers <em class="bcp14">SHOULD</em> limit themselves to the well-behaved profile defined in <a href="#sane-profile" title="Server Requirements">Section 4</a> when generating cookies.</p></div><div id="rfc.section.1.p.6"><p>User agents <em class="bcp14">MUST</em> implement the more liberal processing rules defined in <a href="#ua-requirements" title="User Agent Requirements">Section 5</a>, in order to maximize interoperability with existing servers that do not conform to the well-behaved profile defined in <a href="#sane-profile" title="Server Requirements">Section 4</a>.</p></div><div id="rfc.section.1.p.7"><p>This document specifies the syntax and semantics of these headers as they are actually used on the Internet. In particular, this document does not create new syntax or semantics beyond those in use today. The recommendations for cookie generation provided in <a href="#sane-profile" title="Server Requirements">Section 4</a> represent a preferred subset of current server behavior, and even the more liberal cookie processing algorithm provided in <a href="#ua-requirements" title="User Agent Requirements">Section 5</a> does not recommend all of the syntactic and semantic variations in use today. Where some existing software differs from the recommended protocol in significant ways, the document contains a note explaining the difference.</p></div><div id="rfc.section.1.p.8"><p>Prior to this document, there were at least three descriptions of cookies: the so-called "Netscape cookie specification" <a href="#Netscape"><cite title="Persistent Client State -- HTTP Cookies">[Netscape]</cite></a>, RFC 2109 <a href="#RFC2109"><cite title="HTTP State Management Mechanism">[RFC2109]</cite></a>, and RFC 2965 <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a>. However, none of these documents describe how the Cookie and Set-Cookie headers are actually used on the Internet (see <a href="#Kri2001"><cite title="HTTP Cookies: Standards, Privacy, and Politics">[Kri2001]</cite></a> for historical context). In relation to previous IETF specifications of HTTP state management mechanisms, this document requests the following actions: </p><ol><li>Change the status of <a href="#RFC2109"><cite title="HTTP State Management Mechanism">[RFC2109]</cite></a> to Historic (it has already been obsoleted by <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a>).</li><li>Change the status of <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a> to Historic.</li><li>Indicate that <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a> has been obsoleted by this document.</li></ol><p> In particular, in moving RFC 2965 to Historic and obsoleting it, this document deprecates the use of the Cookie2 and Set-Cookie2 header fields.</p></div></section><section id="conventions"><h2 id="rfc.section.2"><a href="#rfc.section.2">2.</a> <a href="#conventions">Conventions</a></h2><section id="conformance-criteria"><h3 id="rfc.section.2.1"><a href="#rfc.section.2.1">2.1.</a> <a href="#conformance-criteria">Conformance Criteria</a></h3><div id="rfc.section.2.1.p.1"><p>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <a href="#RFC2119"><cite title="Key words for use in RFCs to Indicate Requirement Levels">[RFC2119]</cite></a>.</p></div><div id="rfc.section.2.1.p.2"><p>Requirements phrased in the imperative as part of algorithms (such as "strip any leading space characters" or "return false and abort these steps") are to be interpreted with the meaning of the key word ("MUST", "SHOULD", "MAY", etc.) used in introducing the algorithm.</p></div><div id="rfc.section.2.1.p.3"><p>Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant.</p></div></section><section id="syntax-notation"><h3 id="rfc.section.2.2"><a href="#rfc.section.2.2">2.2.</a> <a href="#syntax-notation">Syntax Notation</a></h3><div id="rfc.section.2.2.p.1"><p>This specification uses the Augmented Backus-Naur Form (ABNF) notation of <a href="#RFC5234"><cite title="Augmented BNF for Syntax Specifications: ABNF">[RFC5234]</cite></a>.</p></div><div id="rfc.section.2.2.p.2"><p>The following core rules are included by reference, as defined in <a href="#RFC5234"><cite title="Augmented BNF for Syntax Specifications: ABNF">[RFC5234]</cite></a>, Appendix B.1: ALPHA (letters), CR (carriage return), CRLF (CR LF), CTLs (controls), DIGIT (decimal 0-9), DQUOTE (double quote), HEXDIG (hexadecimal 0-9/A-F/a-f), LF (line feed), NUL (null octet), OCTET (any 8-bit sequence of data except NUL), SP (space), HTAB (horizontal tab), CHAR (any <a href="#USASCII"><cite title="Coded Character Set -- 7-bit American Standard Code for Information Interchange">[USASCII]</cite></a> character), VCHAR (any visible <a href="#USASCII"><cite title="Coded Character Set -- 7-bit American Standard Code for Information Interchange">[USASCII]</cite></a> character), and WSP (whitespace).</p></div><div id="rfc.section.2.2.p.3"><p>The OWS (optional whitespace) rule is used where zero or more linear whitespace characters <em class="bcp14">MAY</em> appear: </p><span id="rfc.figure.u.1"><span><pre class="inline">OWS = *( [ obs-fold ] WSP ) ; "optional" whitespace obs-fold = CRLF </pre></span></span><p> OWS <em class="bcp14">SHOULD</em> either not be produced or be produced as a single SP character.</p></div></section><section id="terminology"><h3 id="rfc.section.2.3"><a href="#rfc.section.2.3">2.3.</a> <a href="#terminology">Terminology</a></h3><div id="rfc.section.2.3.p.1"><p>The terms user agent, client, server, proxy, and origin server have the same meaning as in the HTTP/1.1 specification (<a href="#RFC2616"><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a>, <a href="https://www.rfc-editor.org/rfc/rfc2616.html#section-1.3">Section 1.3</a>).</p></div><div id="rfc.section.2.3.p.2"><p>The request-host is the name of the host, as known by the user agent, to which the user agent is sending an HTTP request or from which it is receiving an HTTP response (i.e., the name of the host to which it sent the corresponding HTTP request).</p></div><div id="rfc.section.2.3.p.3"><p>The term request-uri is defined in <a href="https://www.rfc-editor.org/rfc/rfc2616.html#section-5.1.2">Section 5.1.2</a> of <a href="#RFC2616"><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a>.</p></div><div id="rfc.section.2.3.p.4"><p>Two sequences of octets are said to case-insensitively match each other if and only if they are equivalent under the i;ascii-casemap collation defined in <a href="#RFC4790"><cite title="Internet Application Protocol Collation Registry">[RFC4790]</cite></a>.</p></div><div id="rfc.section.2.3.p.5"><p>The term string means a sequence of non-NUL octets.</p></div></section></section><section id="overview"><h2 id="rfc.section.3"><a href="#rfc.section.3">3.</a> <a href="#overview">Overview</a></h2><div id="rfc.section.3.p.1"><p>This section outlines a way for an origin server to send state information to a user agent and for the user agent to return the state information to the origin server.</p></div><div id="rfc.section.3.p.2"><p>To store state, the origin server includes a Set-Cookie header in an HTTP response. In subsequent requests, the user agent returns a Cookie request header to the origin server. The Cookie header contains cookies the user agent received in previous Set-Cookie headers. The origin server is free to ignore the Cookie header or use its contents for an application-defined purpose.</p></div><div id="rfc.section.3.p.3"><p>Origin servers <em class="bcp14">MAY</em> send a Set-Cookie response header with any response. User agents <em class="bcp14">MAY</em> ignore Set-Cookie headers contained in responses with 100-level status codes but <em class="bcp14">MUST</em> process Set-Cookie headers contained in other responses (including responses with 400- and 500-level status codes). An origin server can include multiple Set-Cookie header fields in a single response. The presence of a Cookie or a Set-Cookie header field does not preclude HTTP caches from storing and reusing a response.</p></div><div id="rfc.section.3.p.4"><p>Origin servers <em class="bcp14">SHOULD NOT</em> fold multiple Set-Cookie header fields into a single header field. The usual mechanism for folding HTTP headers fields (i.e., as defined in <a href="#RFC2616"><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a>) might change the semantics of the Set-Cookie header field because the %x2C (",") character is used by Set-Cookie in a way that conflicts with such folding.</p></div><section id="n-examples"><h3 id="rfc.section.3.1"><a href="#rfc.section.3.1">3.1.</a> <a href="#n-examples">Examples</a></h3><div id="rfc.section.3.1.p.1"><p>Using the Set-Cookie header, a server can send the user agent a short string in an HTTP response that the user agent will return in future HTTP requests that are within the scope of the cookie. For example, the server can send the user agent a "session identifier" named SID with the value 31d4d96e407aad42. The user agent then returns the session identifier in subsequent requests.</p></div><div id="rfc.figure.u.2"><p>== Server -> User Agent ==</p><div><pre class="text">Set-Cookie: SID=31d4d96e407aad42 </pre></div></div><div id="rfc.figure.u.3"><p>== User Agent -> Server ==</p><div><pre class="text">Cookie: SID=31d4d96e407aad42 </pre></div></div><div id="rfc.section.3.1.p.2"><p>The server can alter the default scope of the cookie using the Path and Domain attributes. For example, the server can instruct the user agent to return the cookie to every path and every subdomain of example.com.</p></div><div id="rfc.figure.u.4"><p>== Server -> User Agent ==</p><div><pre class="text">Set-Cookie: SID=31d4d96e407aad42; Path=/; Domain=example.com </pre></div></div><div id="rfc.figure.u.5"><p>== User Agent -> Server ==</p><div><pre class="text">Cookie: SID=31d4d96e407aad42 </pre></div></div><div id="rfc.section.3.1.p.3"><p>As shown in the next example, the server can store multiple cookies at the user agent. For example, the server can store a session identifier as well as the user's preferred language by returning two Set-Cookie header fields. Notice that the server uses the Secure and HttpOnly attributes to provide additional security protections for the more sensitive session identifier (see <a href="#sane-set-cookie-semantics" title="Semantics (Non-Normative)">Section 4.1.2</a>.)</p></div><div id="rfc.figure.u.6"><p>== Server -> User Agent ==</p><div><pre class="text">Set-Cookie: SID=31d4d96e407aad42; Path=/; Secure; HttpOnly Set-Cookie: lang=en-US; Path=/; Domain=example.com </pre></div></div><div id="rfc.figure.u.7"><p>== User Agent -> Server ==</p><div><pre class="text">Cookie: SID=31d4d96e407aad42; lang=en-US </pre></div></div><div id="rfc.section.3.1.p.4"><p>Notice that the Cookie header above contains two cookies, one named SID and one named lang. If the server wishes the user agent to persist the cookie over multiple "sessions" (e.g., user agent restarts), the server can specify an expiration date in the Expires attribute. Note that the user agent might delete the cookie before the expiration date if the user agent's cookie store exceeds its quota or if the user manually deletes the server's cookie.</p></div><div id="rfc.figure.u.8"><p>== Server -> User Agent ==</p><div><pre class="text">Set-Cookie: lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT </pre></div></div><div id="rfc.figure.u.9"><p>== User Agent -> Server ==</p><div><pre class="text">Cookie: SID=31d4d96e407aad42; lang=en-US </pre></div></div><div id="rfc.section.3.1.p.5"><p>Finally, to remove a cookie, the server returns a Set-Cookie header with an expiration date in the past. The server will be successful in removing the cookie only if the Path and the Domain attribute in the Set-Cookie header match the values used when the cookie was created.</p></div><div id="rfc.figure.u.10"><p>== Server -> User Agent ==</p><div><pre class="text">Set-Cookie: lang=; Expires=Sun, 06 Nov 1994 08:49:37 GMT </pre></div></div><div id="rfc.figure.u.11"><p>== User Agent -> Server ==</p><div><pre class="text">Cookie: SID=31d4d96e407aad42 </pre></div></div></section></section><section id="sane-profile"><h2 id="rfc.section.4"><a href="#rfc.section.4">4.</a> <a href="#sane-profile">Server Requirements</a></h2><div id="rfc.section.4.p.1"><p>This section describes the syntax and semantics of a well-behaved profile of the Cookie and Set-Cookie headers.</p></div><section id="sane-set-cookie"><h3 id="rfc.section.4.1"><a href="#rfc.section.4.1">4.1.</a> <a href="#sane-set-cookie">Set-Cookie</a></h3><div id="rfc.section.4.1.p.1"><p>The Set-Cookie HTTP response header is used to send cookies from the server to the user agent.</p></div><section id="sane-set-cookie-syntax"><h4 id="rfc.section.4.1.1"><a href="#rfc.section.4.1.1">4.1.1.</a> <a href="#sane-set-cookie-syntax">Syntax</a></h4><div id="rfc.section.4.1.1.p.1" class="avoidbreakafter"><p>Informally, the Set-Cookie response header contains the header name "Set-Cookie" followed by a ":" and a cookie. Each cookie begins with a name-value-pair, followed by zero or more attribute-value pairs. Servers <em class="bcp14">SHOULD NOT</em> send Set-Cookie headers that fail to conform to the following grammar:</p></div><div id="rfc.figure.u.12"><div><pre class="inline">set-cookie-header = "Set-Cookie:" SP set-cookie-string set-cookie-string = cookie-pair *( ";" SP cookie-av ) cookie-pair = cookie-name "=" cookie-value cookie-name = token cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE ) cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E ; US-ASCII characters excluding CTLs, ; whitespace DQUOTE, comma, semicolon, ; and backslash token = <token, defined in <a href="#RFC2616"><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a>, <a href="https://www.rfc-editor.org/rfc/rfc2616.html#section-2.2">Section 2.2</a>> cookie-av = expires-av / max-age-av / domain-av / path-av / secure-av / httponly-av / extension-av expires-av = "Expires=" sane-cookie-date sane-cookie-date = <rfc1123-date, defined in <a href="#RFC2616"><cite title="Hypertext Transfer Protocol -- HTTP/1.1">[RFC2616]</cite></a>, <a href="https://www.rfc-editor.org/rfc/rfc2616.html#section-3.3.1">Section 3.3.1</a>> max-age-av = "Max-Age=" non-zero-digit *DIGIT ; In practice, both expires-av and max-age-av ; are limited to dates representable by the ; user agent. non-zero-digit = %x31-39 ; digits 1 through 9 domain-av = "Domain=" domain-value domain-value = <subdomain> ; defined in <a href="#RFC1034"><cite title="Domain names - concepts and facilities">[RFC1034]</cite></a>, <a href="https://www.rfc-editor.org/rfc/rfc1034.html#section-3.5">Section 3.5</a>, as ; enhanced by <a href="#RFC1123"><cite title="Requirements for Internet Hosts - Application and Support">[RFC1123]</cite></a>, <a href="https://www.rfc-editor.org/rfc/rfc1123.html#section-2.1">Section 2.1</a> path-av = "Path=" path-value path-value = <any CHAR except CTLs or ";"> secure-av = "Secure" httponly-av = "HttpOnly" extension-av = <any CHAR except CTLs or ";"> </pre></div></div><div id="rfc.section.4.1.1.p.2"><p>Note that some of the grammatical terms above reference documents that use different grammatical notations than this document (which uses ABNF from <a href="#RFC5234"><cite title="Augmented BNF for Syntax Specifications: ABNF">[RFC5234]</cite></a>).</p></div><div id="rfc.section.4.1.1.p.3"><p>The semantics of the cookie-value are not defined by this document.</p></div><div id="rfc.section.4.1.1.p.4"><p>To maximize compatibility with user agents, servers that wish to store arbitrary data in a cookie-value <em class="bcp14">SHOULD</em> encode that data, for example, using Base64 <a href="#RFC4648"><cite title="The Base16, Base32, and Base64 Data Encodings">[RFC4648]</cite></a>.</p></div><div id="rfc.section.4.1.1.p.5"><p>The portions of the set-cookie-string produced by the cookie-av term are known as attributes. To maximize compatibility with user agents, servers <em class="bcp14">SHOULD NOT</em> produce two attributes with the same name in the same set-cookie-string. (See <a href="#storage-model" title="Storage Model">Section 5.3</a> for how user agents handle this case.)</p></div><div id="rfc.section.4.1.1.p.6"><p>Servers <em class="bcp14">SHOULD NOT</em> include more than one Set-Cookie header field in the same response with the same cookie-name. (See <a href="#set-cookie" title="The Set-Cookie Header">Section 5.2</a> for how user agents handle this case.)</p></div><div id="rfc.section.4.1.1.p.7"><p>If a server sends multiple responses containing Set-Cookie headers concurrently to the user agent (e.g., when communicating with the user agent over multiple sockets), these responses create a "race condition" that can lead to unpredictable behavior.</p></div><div id="rfc.section.4.1.1.p.8"><p>NOTE: Some existing user agents differ in their interpretation of two-digit years. To avoid compatibility issues, servers <em class="bcp14">SHOULD</em> use the rfc1123-date format, which requires a four-digit year.</p></div><div id="rfc.section.4.1.1.p.9"><p>NOTE: Some user agents store and process dates in cookies as 32-bit UNIX time_t values. Implementation bugs in the libraries supporting time_t processing on some systems might cause such user agents to process dates after the year 2038 incorrectly.</p></div></section><section id="sane-set-cookie-semantics"><h4 id="rfc.section.4.1.2"><a href="#rfc.section.4.1.2">4.1.2.</a> <a href="#sane-set-cookie-semantics">Semantics (Non-Normative)</a></h4><div id="rfc.section.4.1.2.p.1"><p>This section describes simplified semantics of the Set-Cookie header. These semantics are detailed enough to be useful for understanding the most common uses of cookies by servers. The full semantics are described in <a href="#ua-requirements" title="User Agent Requirements">Section 5</a>.</p></div><div id="rfc.section.4.1.2.p.2"><p>When the user agent receives a Set-Cookie header, the user agent stores the cookie together with its attributes. Subsequently, when the user agent makes an HTTP request, the user agent includes the applicable, non-expired cookies in the Cookie header.</p></div><div id="rfc.section.4.1.2.p.3"><p>If the user agent receives a new cookie with the same cookie-name, domain-value, and path-value as a cookie that it has already stored, the existing cookie is evicted and replaced with the new cookie. Notice that servers can delete cookies by sending the user agent a new cookie with an Expires attribute with a value in the past.</p></div><div id="rfc.section.4.1.2.p.4"><p>Unless the cookie's attributes indicate otherwise, the cookie is returned only to the origin server (and not, for example, to any subdomains), and it expires at the end of the current session (as defined by the user agent). User agents ignore unrecognized cookie attributes (but not the entire cookie).</p></div><section id="sane-expires"><h5 id="rfc.section.4.1.2.1"><a href="#rfc.section.4.1.2.1">4.1.2.1.</a> <a href="#sane-expires">The Expires Attribute</a></h5><div id="rfc.section.4.1.2.1.p.1"><p>The Expires attribute indicates the maximum lifetime of the cookie, represented as the date and time at which the cookie expires. The user agent is not required to retain the cookie until the specified date has passed. In fact, user agents often evict cookies due to memory pressure or privacy concerns.</p></div></section><section id="sane-max-age"><h5 id="rfc.section.4.1.2.2"><a href="#rfc.section.4.1.2.2">4.1.2.2.</a> <a href="#sane-max-age">The Max-Age Attribute</a></h5><div id="rfc.section.4.1.2.2.p.1"><p>The Max-Age attribute indicates the maximum lifetime of the cookie, represented as the number of seconds until the cookie expires. The user agent is not required to retain the cookie for the specified duration. In fact, user agents often evict cookies due to memory pressure or privacy concerns. </p><ul class="empty"><li>NOTE: Some existing user agents do not support the Max-Age attribute. User agents that do not support the Max-Age attribute ignore the attribute.</li></ul></div><div id="rfc.section.4.1.2.2.p.2"><p>If a cookie has both the Max-Age and the Expires attribute, the Max-Age attribute has precedence and controls the expiration date of the cookie. If a cookie has neither the Max-Age nor the Expires attribute, the user agent will retain the cookie until "the current session is over" (as defined by the user agent).</p></div></section><section id="sane-domain"><h5 id="rfc.section.4.1.2.3"><a href="#rfc.section.4.1.2.3">4.1.2.3.</a> <a href="#sane-domain">The Domain Attribute</a></h5><div id="rfc.section.4.1.2.3.p.1"><p>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. (Note that a leading %x2E ("."), if present, is ignored even though that character is not permitted, but a trailing %x2E ("."), if present, will cause the user agent to ignore the attribute.) If the server omits the Domain attribute, the user agent will return the cookie only to the origin server. </p><ul class="empty"><li>WARNING: Some existing user agents treat an absent Domain attribute as if the Domain attribute were present and contained the current host name. For example, if example.com returns a Set-Cookie header without a Domain attribute, these user agents will erroneously send the cookie to www.example.com as well.</li></ul></div><div id="rfc.section.4.1.2.3.p.2"><p>The user agent will reject cookies unless the Domain attribute specifies a scope for the cookie that would include the origin server. For example, the user agent will accept a cookie with a Domain attribute of "example.com" or of "foo.example.com" from foo.example.com, but the user agent will not accept a cookie with a Domain attribute of "bar.example.com" or of "baz.foo.example.com".</p></div><div id="rfc.section.4.1.2.3.p.3"><p>NOTE: For security reasons, many user agents are configured to reject Domain attributes that correspond to "public suffixes". For example, some user agents will reject Domain attributes of "com" or "co.uk". (See <a href="#storage-model" title="Storage Model">Section 5.3</a> for more information.)</p></div></section><section id="sane-path"><h5 id="rfc.section.4.1.2.4"><a href="#rfc.section.4.1.2.4">4.1.2.4.</a> <a href="#sane-path">The Path Attribute</a></h5><div id="rfc.section.4.1.2.4.p.1"><p>The scope of each cookie is limited to a set of paths, controlled by the Path attribute. If the server omits the Path attribute, the user agent will use the "directory" of the request-uri's path component as the default value. (See <a href="#cookie-path" title="Paths and Path-Match">Section 5.1.4</a> for more details.)</p></div><div id="rfc.section.4.1.2.4.p.2"><p>The user agent will include the cookie in an HTTP request only if the path portion of the request-uri matches (or is a subdirectory of) the cookie's Path attribute, where the %x2F ("/") character is interpreted as a directory separator.</p></div><div id="rfc.section.4.1.2.4.p.3"><p>Although seemingly useful for isolating cookies between different paths within a given host, the Path attribute cannot be relied upon for security (see <a href="#security-considerations" title="Security Considerations">Section 8</a>).</p></div></section><section id="sane-secure"><h5 id="rfc.section.4.1.2.5"><a href="#rfc.section.4.1.2.5">4.1.2.5.</a> <a href="#sane-secure">The Secure Attribute</a></h5><div id="rfc.section.4.1.2.5.p.1"><p>The Secure attribute limits the scope of the cookie to "secure" channels (where "secure" is defined by the user agent). When a cookie has the Secure attribute, the user agent will include the cookie in an HTTP request only if the request is transmitted over a secure channel (typically HTTP over Transport Layer Security (TLS) <a href="#RFC2818"><cite title="HTTP Over TLS">[RFC2818]</cite></a>).</p></div><div id="rfc.section.4.1.2.5.p.2"><p>Although seemingly useful for protecting cookies from active network attackers, the Secure attribute protects only the cookie's confidentiality. An active network attacker can overwrite Secure cookies from an insecure channel, disrupting their integrity (see <a href="#weak-integrity" title="Weak Integrity">Section 8.6</a> for more details).</p></div></section><section id="sane-httponly"><h5 id="rfc.section.4.1.2.6"><a href="#rfc.section.4.1.2.6">4.1.2.6.</a> <a href="#sane-httponly">The HttpOnly Attribute</a></h5><div id="rfc.section.4.1.2.6.p.1"><p>The HttpOnly attribute limits the scope of the cookie to HTTP requests. In particular, the attribute instructs the user agent to omit the cookie when providing access to cookies via "non-HTTP" APIs (such as a web browser API that exposes cookies to scripts).</p></div><div id="rfc.section.4.1.2.6.p.2"><p>Note that the HttpOnly attribute is independent of the Secure attribute: a cookie can have both the HttpOnly and the Secure attribute.</p></div></section></section></section><section id="sane-cookie"><h3 id="rfc.section.4.2"><a href="#rfc.section.4.2">4.2.</a> <a href="#sane-cookie">Cookie</a></h3><section id="sane-cookie-syntax"><h4 id="rfc.section.4.2.1"><a href="#rfc.section.4.2.1">4.2.1.</a> <a href="#sane-cookie-syntax">Syntax</a></h4><div id="rfc.section.4.2.1.p.1" class="avoidbreakafter"><p>The user agent sends stored cookies to the origin server in the Cookie header. If the server conforms to the requirements in <a href="#sane-set-cookie" title="Set-Cookie">Section 4.1</a> (and the user agent conforms to the requirements in <a href="#ua-requirements" title="User Agent Requirements">Section 5</a>), the user agent will send a Cookie header that conforms to the following grammar:</p></div><div id="rfc.figure.u.13"><div><pre class="inline">cookie-header = "Cookie:" OWS cookie-string OWS cookie-string = cookie-pair *( ";" SP cookie-pair ) </pre></div></div></section><section id="sane-cookie-semantics"><h4 id="rfc.section.4.2.2"><a href="#rfc.section.4.2.2">4.2.2.</a> <a href="#sane-cookie-semantics">Semantics</a></h4><div id="rfc.section.4.2.2.p.1"><p>Each cookie-pair represents a cookie stored by the user agent. The cookie-pair contains the cookie-name and cookie-value the user agent received in the Set-Cookie header.</p></div><div id="rfc.section.4.2.2.p.2"><p>Notice that the cookie attributes are not returned. In particular, the server cannot determine from the Cookie header alone when a cookie will expire, for which hosts the cookie is valid, for which paths the cookie is valid, or whether the cookie was set with the Secure or HttpOnly attributes.</p></div><div id="rfc.section.4.2.2.p.3"><p>The semantics of individual cookies in the Cookie header are not defined by this document. Servers are expected to imbue these cookies with application-specific semantics.</p></div><div id="rfc.section.4.2.2.p.4"><p>Although cookies are serialized linearly in the Cookie header, servers <em class="bcp14">SHOULD NOT</em> rely upon the serialization order. In particular, if the Cookie header contains two cookies with the same name (e.g., that were set with different Path or Domain attributes), servers <em class="bcp14">SHOULD NOT</em> rely upon the order in which these cookies appear in the header.</p></div></section></section></section><section id="ua-requirements"><h2 id="rfc.section.5"><a href="#rfc.section.5">5.</a> <a href="#ua-requirements">User Agent Requirements</a></h2><div id="rfc.section.5.p.1"><p>This section specifies the Cookie and Set-Cookie headers in sufficient detail that a user agent implementing these requirements precisely can interoperate with existing servers (even those that do not conform to the well-behaved profile described in <a href="#sane-profile" title="Server Requirements">Section 4</a>).</p></div><div id="rfc.section.5.p.2"><p>A user agent could enforce more restrictions than those specified herein (e.g., for the sake of improved security); however, experiments have shown that such strictness reduces the likelihood that a user agent will be able to interoperate with existing servers.</p></div><section id="algorithms"><h3 id="rfc.section.5.1"><a href="#rfc.section.5.1">5.1.</a> <a href="#algorithms">Subcomponent Algorithms</a></h3><div id="rfc.section.5.1.p.1"><p>This section defines some algorithms used by user agents to process specific subcomponents of the Cookie and Set-Cookie headers.</p></div><section id="cookie-date"><h4 id="rfc.section.5.1.1"><a href="#rfc.section.5.1.1">5.1.1.</a> <a href="#cookie-date">Dates</a></h4><div id="rfc.section.5.1.1.p.1"><p>The user agent <em class="bcp14">MUST</em> use an algorithm equivalent to the following algorithm to parse a cookie-date. Note that the various boolean flags defined as a part of the algorithm (i.e., found-time, found-day-of-month, found-month, found-year) are initially "not set". </p><ol><li>Using the grammar below, divide the cookie-date into date-tokens. <span id="rfc.figure.u.14"><span><pre class="inline">cookie-date = *delimiter date-token-list *delimiter date-token-list = date-token *( 1*delimiter date-token ) date-token = 1*non-delimiter delimiter = %x09 / %x20-2F / %x3B-40 / %x5B-60 / %x7B-7E non-delimiter = %x00-08 / %x0A-1F / DIGIT / ":" / ALPHA / %x7F-FF non-digit = %x00-2F / %x3A-FF day-of-month = 1*2DIGIT ( non-digit *OCTET ) month = ( "jan" / "feb" / "mar" / "apr" / "may" / "jun" / "jul" / "aug" / "sep" / "oct" / "nov" / "dec" ) *OCTET year = 2*4DIGIT ( non-digit *OCTET ) time = hms-time ( non-digit *OCTET ) hms-time = time-field ":" time-field ":" time-field time-field = 1*2DIGIT </pre></span></span> </li><li>Process each date-token sequentially in the order the date-tokens appear in the cookie-date: <ol><li>If the found-time flag is not set and the token matches the time production, set the found-time flag and set the hour-value, minute-value, and second-value to the numbers denoted by the digits in the date-token, respectively. Skip the remaining sub-steps and continue to the next date-token.</li><li>If the found-day-of-month flag is not set and the date-token matches the day-of-month production, set the found-day-of-month flag and set the day-of-month-value to the number denoted by the date-token. Skip the remaining sub-steps and continue to the next date-token.</li><li>If the found-month flag is not set and the date-token matches the month production, set the found-month flag and set the month-value to the month denoted by the date-token. Skip the remaining sub-steps and continue to the next date-token.</li><li>If the found-year flag is not set and the date-token matches the year production, set the found-year flag and set the year-value to the number denoted by the date-token. Skip the remaining sub-steps and continue to the next date-token.</li></ol> </li><li>If the year-value is greater than or equal to 70 and less than or equal to 99, increment the year-value by 1900.</li><li>If the year-value is greater than or equal to 0 and less than or equal to 69, increment the year-value by 2000. <ol><li>NOTE: Some existing user agents interpret two-digit years differently.</li></ol> </li><li>Abort these steps and fail to parse the cookie-date if: <ul><li>at least one of the found-day-of-month, found-month, found-year, or found-time flags is not set,</li><li>the day-of-month-value is less than 1 or greater than 31,</li><li>the year-value is less than 1601,</li><li>the hour-value is greater than 23,</li><li>the minute-value is greater than 59, or</li><li>the second-value is greater than 59.</li></ul> (Note that leap seconds cannot be represented in this syntax.)</li><li>Let the parsed-cookie-date be the date whose day-of-month, month, year, hour, minute, and second (in UTC) are the day-of-month-value, the month-value, the year-value, the hour-value, the minute-value, and the second-value, respectively. If no such date exists, abort these steps and fail to parse the cookie-date.</li><li>Return the parsed-cookie-date as the result of this algorithm.</li></ol></div></section><section id="cookie-domain-canonicalize"><h4 id="rfc.section.5.1.2"><a href="#rfc.section.5.1.2">5.1.2.</a> <a href="#cookie-domain-canonicalize">Canonicalized Host Names</a></h4><div id="rfc.section.5.1.2.p.1"><p>A canonicalized host name is the string generated by the following algorithm: </p><ol><li>Convert the host name to a sequence of individual domain name labels.</li><li>Convert each label that is not a Non-Reserved LDH (NR-LDH) label, to an A-label (see <a href="https://www.rfc-editor.org/rfc/rfc5890.html#section-2.3.2.1">Section 2.3.2.1</a> of <a href="#RFC5890"><cite title="Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework">[RFC5890]</cite></a> for the former and latter), or to a "punycode label" (a label resulting from the "ToASCII" conversion in <a href="https://www.rfc-editor.org/rfc/rfc3490.html#section-4">Section 4</a> of <a href="#RFC3490"><cite title="Internationalizing Domain Names in Applications (IDNA)">[RFC3490]</cite></a>), as appropriate (see <a href="#idna-migration" title="IDNA Dependency and Migration">Section 6.3</a> of this specification).</li><li>Concatenate the resulting labels, separated by a %x2E (".") character.</li></ol></div></section><section id="cookie-domain"><h4 id="rfc.section.5.1.3"><a href="#rfc.section.5.1.3">5.1.3.</a> <a href="#cookie-domain">Domain Matching</a></h4><div id="rfc.section.5.1.3.p.1"><p>A string domain-matches a given domain string if at least one of the following conditions hold: </p><ul><li>The domain string and the string are identical. (Note that both the domain string and the string will have been canonicalized to lower case at this point.)</li><li>All of the following conditions hold: <ul><li>The domain string is a suffix of the string.</li><li>The last character of the string that is not included in the domain string is a %x2E (".") character.</li><li>The string is a host name (i.e., not an IP address).</li></ul> </li></ul></div></section><section id="cookie-path"><h4 id="rfc.section.5.1.4"><a href="#rfc.section.5.1.4">5.1.4.</a> <a href="#cookie-path">Paths and Path-Match</a></h4><div id="rfc.section.5.1.4.p.1"><p>The user agent <em class="bcp14">MUST</em> use an algorithm equivalent to the following algorithm to compute the default-path of a cookie: </p><ol><li>Let uri-path be the path portion of the request-uri if such a portion exists (and empty otherwise). For example, if the request-uri contains just a path (and optional query string), then the uri-path is that path (without the %x3F ("?") character or query string), and if the request-uri contains a full absoluteURI, the uri-path is the path component of that URI.</li><li>If the uri-path is empty or if the first character of the uri-path is not a %x2F ("/") character, output %x2F ("/") and skip the remaining steps.</li><li>If the uri-path contains no more than one %x2F ("/") character, output %x2F ("/") and skip the remaining step.</li><li>Output the characters of the uri-path from the first character up to, but not including, the right-most %x2F ("/").</li></ol></div><div id="rfc.section.5.1.4.p.2"><p>A request-path path-matches a given cookie-path if at least one of the following conditions holds: </p><ul><li>The cookie-path and the request-path are identical.</li><li>The cookie-path is a prefix of the request-path, and the last character of the cookie-path is %x2F ("/").</li><li>The cookie-path is a prefix of the request-path, and the first character of the request-path that is not included in the cookie-path is a %x2F ("/") character.</li></ul></div></section></section><section id="set-cookie"><h3 id="rfc.section.5.2"><a href="#rfc.section.5.2">5.2.</a> <a href="#set-cookie">The Set-Cookie Header</a></h3><div id="rfc.section.5.2.p.1"><p>When a user agent receives a Set-Cookie header field in an HTTP response, the user agent <em class="bcp14">MAY</em> ignore the Set-Cookie header field in its entirety. For example, the user agent might wish to block responses to "third-party" requests from setting cookies (see <a href="#third-party-cookies" title="Third-Party Cookies">Section 7.1</a>).</p></div><div id="rfc.section.5.2.p.2"><p>If the user agent does not ignore the Set-Cookie header field in its entirety, the user agent <em class="bcp14">MUST</em> parse the field-value of the Set-Cookie header field as a set-cookie-string (defined below).</p></div><div id="rfc.section.5.2.p.3"><p>NOTE: The algorithm below is more permissive than the grammar in <a href="#sane-set-cookie" title="Set-Cookie">Section 4.1</a>. For example, the algorithm strips leading and trailing whitespace from the cookie name and value (but maintains internal whitespace), whereas the grammar in <a href="#sane-set-cookie" title="Set-Cookie">Section 4.1</a> forbids whitespace in these positions. User agents use this algorithm so as to interoperate with servers that do not follow the recommendations in <a href="#sane-profile" title="Server Requirements">Section 4</a>.</p></div><div id="rfc.section.5.2.p.4"><p>A user agent <em class="bcp14">MUST</em> use an algorithm equivalent to the following algorithm to parse a "set-cookie-string": </p><ol><li>If the set-cookie-string contains a %x3B (";") character: <ul class="empty"><li>The name-value-pair string consists of the characters up to, but not including, the first %x3B (";"), and the unparsed-attributes consist of the remainder of the set-cookie-string (including the %x3B (";") in question).</li></ul> Otherwise: <ul class="empty"><li>The name-value-pair string consists of all the characters contained in the set-cookie-string, and the unparsed-attributes is the empty string.</li></ul> </li><li>If the name-value-pair string lacks a %x3D ("=") character, ignore the set-cookie-string entirely.</li><li>The (possibly empty) name string consists of the characters up to, but not including, the first %x3D ("=") character, and the (possibly empty) value string consists of the characters after the first %x3D ("=") character.</li><li>Remove any leading or trailing WSP characters from the name string and the value string.</li><li>If the name string is empty, ignore the set-cookie-string entirely.</li><li>The cookie-name is the name string, and the cookie-value is the value string.</li></ol></div><div id="rfc.section.5.2.p.5"><p>The user agent <em class="bcp14">MUST</em> use an algorithm equivalent to the following algorithm to parse the unparsed-attributes: </p><ol><li>If the unparsed-attributes string is empty, skip the rest of these steps.</li><li>Discard the first character of the unparsed-attributes (which will be a %x3B (";") character).</li><li>If the remaining unparsed-attributes contains a %x3B (";") character: <ul class="empty"><li>Consume the characters of the unparsed-attributes up to, but not including, the first %x3B (";") character.</li></ul> Otherwise: <ul class="empty"><li>Consume the remainder of the unparsed-attributes.</li></ul> Let the cookie-av string be the characters consumed in this step.</li><li>If the cookie-av string contains a %x3D ("=") character: <ul class="empty"><li>The (possibly empty) attribute-name string consists of the characters up to, but not including, the first %x3D ("=") character, and the (possibly empty) attribute-value string consists of the characters after the first %x3D ("=") character.</li></ul> Otherwise: <ul class="empty"><li>The attribute-name string consists of the entire cookie-av string, and the attribute-value string is empty.</li></ul> </li><li>Remove any leading or trailing WSP characters from the attribute-name string and the attribute-value string.</li><li>Process the attribute-name and attribute-value according to the requirements in the following subsections. (Notice that attributes with unrecognized attribute-names are ignored.)</li><li>Return to Step 1 of this algorithm.</li></ol></div><div id="rfc.section.5.2.p.6"><p>When the user agent finishes parsing the set-cookie-string, the user agent is said to "receive a cookie" from the request-uri with name cookie-name, value cookie-value, and attributes cookie-attribute-list. (See <a href="#storage-model" title="Storage Model">Section 5.3</a> for additional requirements triggered by receiving a cookie.)</p></div><section id="expires-attribute"><h4 id="rfc.section.5.2.1"><a href="#rfc.section.5.2.1">5.2.1.</a> <a href="#expires-attribute">The Expires Attribute</a></h4><div id="rfc.section.5.2.1.p.1"><p>If the attribute-name case-insensitively matches the string "Expires", the user agent <em class="bcp14">MUST</em> process the cookie-av as follows.</p></div><div id="rfc.section.5.2.1.p.2"><p>Let the expiry-time be the result of parsing the attribute-value as cookie-date (see <a href="#cookie-date" title="Dates">Section 5.1.1</a>).</p></div><div id="rfc.section.5.2.1.p.3"><p>If the attribute-value failed to parse as a cookie date, ignore the cookie-av.</p></div><div id="rfc.section.5.2.1.p.4"><p>If the expiry-time is later than the last date the user agent can represent, the user agent <em class="bcp14">MAY</em> replace the expiry-time with the last representable date.</p></div><div id="rfc.section.5.2.1.p.5"><p>If the expiry-time is earlier than the earliest date the user agent can represent, the user agent <em class="bcp14">MAY</em> replace the expiry-time with the earliest representable date.</p></div><div id="rfc.section.5.2.1.p.6"><p>Append an attribute to the cookie-attribute-list with an attribute-name of Expires and an attribute-value of expiry-time.</p></div></section><section id="max-age-attribute"><h4 id="rfc.section.5.2.2"><a href="#rfc.section.5.2.2">5.2.2.</a> <a href="#max-age-attribute">The Max-Age Attribute</a></h4><div id="rfc.section.5.2.2.p.1"><p>If the attribute-name case-insensitively matches the string "Max-Age", the user agent <em class="bcp14">MUST</em> process the cookie-av as follows.</p></div><div id="rfc.section.5.2.2.p.2"><p>If the first character of the attribute-value is not a DIGIT or a "-" character, ignore the cookie-av.</p></div><div id="rfc.section.5.2.2.p.3"><p>If the remainder of attribute-value contains a non-DIGIT character, ignore the cookie-av.</p></div><div id="rfc.section.5.2.2.p.4"><p>Let delta-seconds be the attribute-value converted to an integer.</p></div><div id="rfc.section.5.2.2.p.5"><p>If delta-seconds is less than or equal to zero (0), let expiry-time be the earliest representable date and time. Otherwise, let the expiry-time be the current date and time plus delta-seconds seconds.</p></div><div id="rfc.section.5.2.2.p.6"><p>Append an attribute to the cookie-attribute-list with an attribute-name of Max-Age and an attribute-value of expiry-time.</p></div></section><section id="domain-attribute"><h4 id="rfc.section.5.2.3"><a href="#rfc.section.5.2.3">5.2.3.</a> <a href="#domain-attribute">The Domain Attribute</a></h4><div id="rfc.section.5.2.3.p.1"><p>If the attribute-name case-insensitively matches the string "Domain", the user agent <em class="bcp14">MUST</em> process the cookie-av as follows.</p></div><div id="rfc.section.5.2.3.p.2"><p>If the attribute-value is empty, the behavior is undefined. However, the user agent <em class="bcp14">SHOULD</em> ignore the cookie-av entirely.</p></div><div id="rfc.section.5.2.3.p.3"><p>If the first character of the attribute-value string is %x2E ("."): </p><ul class="empty"><li>Let cookie-domain be the attribute-value without the leading %x2E (".") character.</li></ul><p> Otherwise: </p><ul class="empty"><li>Let cookie-domain be the entire attribute-value.</li></ul></div><div id="rfc.section.5.2.3.p.4"><p>Convert the cookie-domain to lower case.</p></div><div id="rfc.section.5.2.3.p.5"><p>Append an attribute to the cookie-attribute-list with an attribute-name of Domain and an attribute-value of cookie-domain.</p></div></section><section id="path-attribute"><h4 id="rfc.section.5.2.4"><a href="#rfc.section.5.2.4">5.2.4.</a> <a href="#path-attribute">The Path Attribute</a></h4><div id="rfc.section.5.2.4.p.1"><p>If the attribute-name case-insensitively matches the string "Path", the user agent <em class="bcp14">MUST</em> process the cookie-av as follows.</p></div><div id="rfc.section.5.2.4.p.2"><p>If the attribute-value is empty or if the first character of the attribute-value is not %x2F ("/"): </p><ul class="empty"><li>Let cookie-path be the default-path.</li></ul><p> Otherwise: </p><ul class="empty"><li>Let cookie-path be the attribute-value.</li></ul></div><div id="rfc.section.5.2.4.p.3"><p>Append an attribute to the cookie-attribute-list with an attribute-name of Path and an attribute-value of cookie-path.</p></div></section><section id="secure-attribute"><h4 id="rfc.section.5.2.5"><a href="#rfc.section.5.2.5">5.2.5.</a> <a href="#secure-attribute">The Secure Attribute</a></h4><div id="rfc.section.5.2.5.p.1"><p>If the attribute-name case-insensitively matches the string "Secure", the user agent <em class="bcp14">MUST</em> append an attribute to the cookie-attribute-list with an attribute-name of Secure and an empty attribute-value.</p></div></section><section id="httponly-attribute"><h4 id="rfc.section.5.2.6"><a href="#rfc.section.5.2.6">5.2.6.</a> <a href="#httponly-attribute">The HttpOnly Attribute</a></h4><div id="rfc.section.5.2.6.p.1"><p>If the attribute-name case-insensitively matches the string "HttpOnly", the user agent <em class="bcp14">MUST</em> append an attribute to the cookie-attribute-list with an attribute-name of HttpOnly and an empty attribute-value.</p></div></section></section><section id="storage-model"><h3 id="rfc.section.5.3"><a href="#rfc.section.5.3">5.3.</a> <a href="#storage-model">Storage Model</a></h3><div id="rfc.section.5.3.p.1"><p>The user agent stores the following fields about each cookie: name, value, expiry-time, domain, path, creation-time, last-access-time, persistent-flag, host-only-flag, secure-only-flag, and http-only-flag.</p></div><div id="rfc.section.5.3.p.2"><p>When the user agent "receives a cookie" from a request-uri with name cookie-name, value cookie-value, and attributes cookie-attribute-list, the user agent <em class="bcp14">MUST</em> process the cookie as follows: </p><ol><li>A user agent <em class="bcp14">MAY</em> ignore a received cookie in its entirety. For example, the user agent might wish to block receiving cookies from "third-party" responses or the user agent might not wish to store cookies that exceed some size.</li><li>Create a new cookie with name cookie-name, value cookie-value. Set the creation-time and the last-access-time to the current date and time.</li><li>If the cookie-attribute-list contains an attribute with an attribute-name of "Max-Age": <ul class="empty"><li>Set the cookie's persistent-flag to true.</li><li>Set the cookie's expiry-time to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Max-Age".</li></ul> Otherwise, if the cookie-attribute-list contains an attribute with an attribute-name of "Expires" (and does not contain an attribute with an attribute-name of "Max-Age"): <ul class="empty"><li>Set the cookie's persistent-flag to true.</li><li>Set the cookie's expiry-time to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Expires".</li></ul> Otherwise: <ul class="empty"><li>Set the cookie's persistent-flag to false.</li><li>Set the cookie's expiry-time to the latest representable date.</li></ul> </li><li>If the cookie-attribute-list contains an attribute with an attribute-name of "Domain": <ul class="empty"><li>Let the domain-attribute be the attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Domain".</li></ul> Otherwise: <ul class="empty"><li>Let the domain-attribute be the empty string.</li></ul> </li><li>If the user agent is configured to reject "public suffixes" and the domain-attribute is a public suffix: <ul class="empty"><li>If the domain-attribute is identical to the canonicalized request-host: <ul class="empty"><li>Let the domain-attribute be the empty string.</li></ul> Otherwise: <ul class="empty"><li>Ignore the cookie entirely and abort these steps.</li></ul> </li><li>NOTE: A "public suffix" is a domain that is controlled by a public registry, such as "com", "co.uk", and "pvt.k12.wy.us". This step is essential for preventing attacker.com from disrupting the integrity of example.com by setting a cookie with a Domain attribute of "com". Unfortunately, the set of public suffixes (also known as "registry controlled domains") changes over time. If feasible, user agents <em class="bcp14">SHOULD</em> use an up-to-date public suffix list, such as the one maintained by the Mozilla project at <<a href="http://publicsuffix.org/">http://publicsuffix.org/</a>>.</li></ul> </li><li>If the domain-attribute is non-empty: <ul class="empty"><li>If the canonicalized request-host does not domain-match the domain-attribute: <ul class="empty"><li>Ignore the cookie entirely and abort these steps.</li></ul> Otherwise: <ul class="empty"><li>Set the cookie's host-only-flag to false.</li><li>Set the cookie's domain to the domain-attribute.</li></ul> </li></ul> Otherwise: <ul class="empty"><li>Set the cookie's host-only-flag to true.</li><li>Set the cookie's domain to the canonicalized request-host.</li></ul> </li><li>If the cookie-attribute-list contains an attribute with an attribute-name of "Path", set the cookie's path to attribute-value of the last attribute in the cookie-attribute-list with an attribute-name of "Path". Otherwise, set the cookie's path to the default-path of the request-uri.</li><li>If the cookie-attribute-list contains an attribute with an attribute-name of "Secure", set the cookie's secure-only-flag to true. Otherwise, set the cookie's secure-only-flag to false.</li><li>If the cookie-attribute-list contains an attribute with an attribute-name of "HttpOnly", set the cookie's http-only-flag to true. Otherwise, set the cookie's http-only-flag to false.</li><li>If the cookie was received from a "non-HTTP" API and the cookie's http-only-flag is set, abort these steps and ignore the cookie entirely.</li><li>If the cookie store contains a cookie with the same name, domain, and path as the newly created cookie: <ol><li>Let old-cookie be the existing cookie with the same name, domain, and path as the newly created cookie. (Notice that this algorithm maintains the invariant that there is at most one such cookie.)</li><li>If the newly created cookie was received from a "non-HTTP" API and the old-cookie's http-only-flag is set, abort these steps and ignore the newly created cookie entirely.</li><li>Update the creation-time of the newly created cookie to match the creation-time of the old-cookie.</li><li>Remove the old-cookie from the cookie store.</li></ol> </li><li>Insert the newly created cookie into the cookie store.</li></ol></div><div id="rfc.section.5.3.p.3"><p>A cookie is "expired" if the cookie has an expiry date in the past.</p></div><div id="rfc.section.5.3.p.4"><p>The user agent <em class="bcp14">MUST</em> evict all expired cookies from the cookie store if, at any time, an expired cookie exists in the cookie store.</p></div><div id="rfc.section.5.3.p.5"><p>At any time, the user agent <em class="bcp14">MAY</em> "remove excess cookies" from the cookie store if the number of cookies sharing a domain field exceeds some implementation-defined upper bound (such as 50 cookies).</p></div><div id="rfc.section.5.3.p.6"><p>At any time, the user agent <em class="bcp14">MAY</em> "remove excess cookies" from the cookie store if the cookie store exceeds some predetermined upper bound (such as 3000 cookies).</p></div><div id="rfc.section.5.3.p.7"><p>When the user agent removes excess cookies from the cookie store, the user agent <em class="bcp14">MUST</em> evict cookies in the following priority order: </p><ol><li>Expired cookies.</li><li>Cookies that share a domain field with more than a predetermined number of other cookies.</li><li>All cookies.</li></ol></div><div id="rfc.section.5.3.p.8"><p>If two cookies have the same removal priority, the user agent <em class="bcp14">MUST</em> evict the cookie with the earliest last-access date first.</p></div><div id="rfc.section.5.3.p.9"><p>When "the current session is over" (as defined by the user agent), the user agent <em class="bcp14">MUST</em> remove from the cookie store all cookies with the persistent-flag set to false.</p></div></section><section id="cookie"><h3 id="rfc.section.5.4"><a href="#rfc.section.5.4">5.4.</a> <a href="#cookie">The Cookie Header</a></h3><div id="rfc.section.5.4.p.1"><p>The user agent includes stored cookies in the Cookie HTTP request header.</p></div><div id="rfc.section.5.4.p.2"><p>When the user agent generates an HTTP request, the user agent <em class="bcp14">MUST NOT</em> attach more than one Cookie header field.</p></div><div id="rfc.section.5.4.p.3"><p>A user agent <em class="bcp14">MAY</em> omit the Cookie header in its entirety. For example, the user agent might wish to block sending cookies during "third-party" requests from setting cookies (see <a href="#third-party-cookies" title="Third-Party Cookies">Section 7.1</a>).</p></div><div id="rfc.section.5.4.p.4"><p>If the user agent does attach a Cookie header field to an HTTP request, the user agent <em class="bcp14">MUST</em> send the cookie-string (defined below) as the value of the header field.</p></div><div id="rfc.section.5.4.p.5"><p>The user agent <em class="bcp14">MUST</em> use an algorithm equivalent to the following algorithm to compute the "cookie-string" from a cookie store and a request-uri: </p><ol><li>Let cookie-list be the set of cookies from the cookie store that meets all of the following requirements: <ul><li>Either: <ul class="empty"><li>The cookie's host-only-flag is true and the canonicalized request-host is identical to the cookie's domain.</li></ul> Or: <ul class="empty"><li>The cookie's host-only-flag is false and the canonicalized request-host domain-matches the cookie's domain.</li></ul> </li><li>The request-uri's path path-matches the cookie's path.</li><li>If the cookie's secure-only-flag is true, then the request-uri's scheme must denote a "secure" protocol (as defined by the user agent). <ul class="empty"><li>NOTE: The notion of a "secure" protocol is not defined by this document. Typically, user agents consider a protocol secure if the protocol makes use of transport-layer security, such as SSL or TLS. For example, most user agents consider "https" to be a scheme that denotes a secure protocol.</li></ul> </li><li>If the cookie's http-only-flag is true, then exclude the cookie if the cookie-string is being generated for a "non-HTTP" API (as defined by the user agent).</li></ul> </li><li>The user agent <em class="bcp14">SHOULD</em> sort the cookie-list in the following order: <ul><li>Cookies with longer paths are listed before cookies with shorter paths.</li><li>Among cookies that have equal-length path fields, cookies with earlier creation-times are listed before cookies with later creation-times.</li></ul> NOTE: Not all user agents sort the cookie-list in this order, but this order reflects common practice when this document was written, and, historically, there have been servers that (erroneously) depended on this order.</li><li>Update the last-access-time of each cookie in the cookie-list to the current date and time.</li><li>Serialize the cookie-list into a cookie-string by processing each cookie in the cookie-list in order: <ol><li>Output the cookie's name, the %x3D ("=") character, and the cookie's value.</li><li>If there is an unprocessed cookie in the cookie-list, output the characters %x3B and %x20 ("; ").</li></ol> </li></ol><p> NOTE: Despite its name, the cookie-string is actually a sequence of octets, not a sequence of characters. To convert the cookie-string (or components thereof) into a sequence of characters (e.g., for presentation to the user), the user agent might wish to try using the UTF-8 character encoding <a href="#RFC3629"><cite title="UTF-8, a transformation format of ISO 10646">[RFC3629]</cite></a> to decode the octet sequence. This decoding might fail, however, because not every sequence of octets is valid UTF-8.</p></div></section></section><section id="implementation-considerations"><h2 id="rfc.section.6"><a href="#rfc.section.6">6.</a> <a href="#implementation-considerations">Implementation Considerations</a></h2><section id="implementation-limits"><h3 id="rfc.section.6.1"><a href="#rfc.section.6.1">6.1.</a> <a href="#implementation-limits">Limits</a></h3><div id="rfc.section.6.1.p.1"><p>Practical user agent implementations have limits on the number and size of cookies that they can store. General-use user agents <em class="bcp14">SHOULD</em> provide each of the following minimum capabilities: </p><ul><li>At least 4096 bytes per cookie (as measured by the sum of the length of the cookie's name, value, and attributes).</li><li>At least 50 cookies per domain.</li><li>At least 3000 cookies total.</li></ul></div><div id="rfc.section.6.1.p.2"><p>Servers <em class="bcp14">SHOULD</em> use as few and as small cookies as possible to avoid reaching these implementation limits and to minimize network bandwidth due to the Cookie header being included in every request.</p></div><div id="rfc.section.6.1.p.3"><p>Servers <em class="bcp14">SHOULD</em> gracefully degrade if the user agent fails to return one or more cookies in the Cookie header because the user agent might evict any cookie at any time on orders from the user.</p></div></section><section id="implementation-apis"><h3 id="rfc.section.6.2"><a href="#rfc.section.6.2">6.2.</a> <a href="#implementation-apis">Application Programming Interfaces</a></h3><div id="rfc.section.6.2.p.1"><p>One reason the Cookie and Set-Cookie headers use such esoteric syntax is that many platforms (both in servers and user agents) provide a string-based application programming interface (API) to cookies, requiring application-layer programmers to generate and parse the syntax used by the Cookie and Set-Cookie headers, which many programmers have done incorrectly, resulting in interoperability problems.</p></div><div id="rfc.section.6.2.p.2"><p>Instead of providing string-based APIs to cookies, platforms would be well-served by providing more semantic APIs. It is beyond the scope of this document to recommend specific API designs, but there are clear benefits to accepting an abstract "Date" object instead of a serialized date string.</p></div></section><section id="idna-migration"><h3 id="rfc.section.6.3"><a href="#rfc.section.6.3">6.3.</a> <a href="#idna-migration">IDNA Dependency and Migration</a></h3><div id="rfc.section.6.3.p.1"><p>IDNA2008 <a href="#RFC5890"><cite title="Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework">[RFC5890]</cite></a> supersedes IDNA2003 <a href="#RFC3490"><cite title="Internationalizing Domain Names in Applications (IDNA)">[RFC3490]</cite></a>. However, there are differences between the two specifications, and thus there can be differences in processing (e.g., converting) domain name labels that have been registered under one from those registered under the other. There will be a transition period of some time during which IDNA2003-based domain name labels will exist in the wild. User agents <em class="bcp14">SHOULD</em> implement IDNA2008 <a href="#RFC5890"><cite title="Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework">[RFC5890]</cite></a> and <em class="bcp14">MAY</em> implement <a href="#UTS46"><cite title="Unicode IDNA Compatibility Processing">[UTS46]</cite></a> or <a href="#RFC5895"><cite title="Mapping Characters for Internationalized Domain Names in Applications (IDNA) 2008">[RFC5895]</cite></a> in order to facilitate their IDNA transition. If a user agent does not implement IDNA2008, the user agent <em class="bcp14">MUST</em> implement IDNA2003 <a href="#RFC3490"><cite title="Internationalizing Domain Names in Applications (IDNA)">[RFC3490]</cite></a>.</p></div></section></section><section id="privacy-considerations"><h2 id="rfc.section.7"><a href="#rfc.section.7">7.</a> <a href="#privacy-considerations">Privacy Considerations</a></h2><div id="rfc.section.7.p.1"><p>Cookies are often criticized for letting servers track users. For example, a number of "web analytics" companies use cookies to recognize when a user returns to a web site or visits another web site. Although cookies are not the only mechanism servers can use to track users across HTTP requests, cookies facilitate tracking because they are persistent across user agent sessions and can be shared between hosts.</p></div><section id="third-party-cookies"><h3 id="rfc.section.7.1"><a href="#rfc.section.7.1">7.1.</a> <a href="#third-party-cookies">Third-Party Cookies</a></h3><div id="rfc.section.7.1.p.1"><p>Particularly worrisome are so-called "third-party" cookies. In rendering an HTML document, a user agent often requests resources from other servers (such as advertising networks). These third-party servers can use cookies to track the user even if the user never visits the server directly. For example, if a user visits a site that contains content from a third party and then later visits another site that contains content from the same third party, the third party can track the user between the two sites.</p></div><div id="rfc.section.7.1.p.2"><p>Some user agents restrict how third-party cookies behave. For example, some of these user agents refuse to send the Cookie header in third-party requests. Others refuse to process the Set-Cookie header in responses to third-party requests. User agents vary widely in their third-party cookie policies. This document grants user agents wide latitude to experiment with third-party cookie policies that balance the privacy and compatibility needs of their users. However, this document does not endorse any particular third-party cookie policy.</p></div><div id="rfc.section.7.1.p.3"><p>Third-party cookie blocking policies are often ineffective at achieving their privacy goals if servers attempt to work around their restrictions to track users. In particular, two collaborating servers can often track users without using cookies at all by injecting identifying information into dynamic URLs.</p></div></section><section id="user-controls"><h3 id="rfc.section.7.2"><a href="#rfc.section.7.2">7.2.</a> <a href="#user-controls">User Controls</a></h3><div id="rfc.section.7.2.p.1"><p>User agents <em class="bcp14">SHOULD</em> provide users with a mechanism for managing the cookies stored in the cookie store. For example, a user agent might let users delete all cookies received during a specified time period or all the cookies related to a particular domain. In addition, many user agents include a user interface element that lets users examine the cookies stored in their cookie store.</p></div><div id="rfc.section.7.2.p.2"><p>User agents <em class="bcp14">SHOULD</em> provide users with a mechanism for disabling cookies. When cookies are disabled, the user agent <em class="bcp14">MUST NOT</em> include a Cookie header in outbound HTTP requests and the user agent <em class="bcp14">MUST</em> NOT process Set-Cookie headers in inbound HTTP responses.</p></div><div id="rfc.section.7.2.p.3"><p>Some user agents provide users the option of preventing persistent storage of cookies across sessions. When configured thusly, user agents <em class="bcp14">MUST</em> treat all received cookies as if the persistent-flag were set to false. Some popular user agents expose this functionality via "private browsing" mode <a href="#Aggarwal2010"><cite title="An Analysis of Private Browsing Modes in Modern Browsers">[Aggarwal2010]</cite></a>.</p></div><div id="rfc.section.7.2.p.4"><p>Some user agents provide users with the ability to approve individual writes to the cookie store. In many common usage scenarios, these controls generate a large number of prompts. However, some privacy-conscious users find these controls useful nonetheless.</p></div></section><section id="expiration-dates"><h3 id="rfc.section.7.3"><a href="#rfc.section.7.3">7.3.</a> <a href="#expiration-dates">Expiration Dates</a></h3><div id="rfc.section.7.3.p.1"><p>Although servers can set the expiration date for cookies to the distant future, most user agents do not actually retain cookies for multiple decades. Rather than choosing gratuitously long expiration periods, servers <em class="bcp14">SHOULD</em> promote user privacy by selecting reasonable cookie expiration periods based on the purpose of the cookie. For example, a typical session identifier might reasonably be set to expire in two weeks.</p></div></section></section><section id="security-considerations"><h2 id="rfc.section.8"><a href="#rfc.section.8">8.</a> <a href="#security-considerations">Security Considerations</a></h2><section id="section-overview"><h3 id="rfc.section.8.1"><a href="#rfc.section.8.1">8.1.</a> <a href="#section-overview">Overview</a></h3><div id="rfc.section.8.1.p.1"><p>Cookies have a number of security pitfalls. This section overviews a few of the more salient issues.</p></div><div id="rfc.section.8.1.p.2"><p>In particular, cookies encourage developers to rely on ambient authority for authentication, often becoming vulnerable to attacks such as cross-site request forgery <a href="#CSRF"><cite title="Robust Defenses for Cross-Site Request Forgery">[CSRF]</cite></a>. Also, when storing session identifiers in cookies, developers often create session fixation vulnerabilities.</p></div><div id="rfc.section.8.1.p.3"><p>Transport-layer encryption, such as that employed in HTTPS, is insufficient to prevent a network attacker from obtaining or altering a victim's cookies because the cookie protocol itself has various vulnerabilities (see "Weak Confidentiality" and "Weak Integrity", below). In addition, by default, cookies do not provide confidentiality or integrity from network attackers, even when used in conjunction with HTTPS.</p></div></section><section id="ambient-authority"><h3 id="rfc.section.8.2"><a href="#rfc.section.8.2">8.2.</a> <a href="#ambient-authority">Ambient Authority</a></h3><div id="rfc.section.8.2.p.1"><p>A server that uses cookies to authenticate users can suffer security vulnerabilities because some user agents let remote parties issue HTTP requests from the user agent (e.g., via HTTP redirects or HTML forms). When issuing those requests, user agents attach cookies even if the remote party does not know the contents of the cookies, potentially letting the remote party exercise authority at an unwary server.</p></div><div id="rfc.section.8.2.p.2"><p>Although this security concern goes by a number of names (e.g., cross-site request forgery, confused deputy), the issue stems from cookies being a form of ambient authority. Cookies encourage server operators to separate designation (in the form of URLs) from authorization (in the form of cookies). Consequently, the user agent might supply the authorization for a resource designated by the attacker, possibly causing the server or its clients to undertake actions designated by the attacker as though they were authorized by the user.</p></div><div id="rfc.section.8.2.p.3"><p>Instead of using cookies for authorization, server operators might wish to consider entangling designation and authorization by treating URLs as capabilities. Instead of storing secrets in cookies, this approach stores secrets in URLs, requiring the remote entity to supply the secret itself. Although this approach is not a panacea, judicious application of these principles can lead to more robust security.</p></div></section><section id="clear-text"><h3 id="rfc.section.8.3"><a href="#rfc.section.8.3">8.3.</a> <a href="#clear-text">Clear Text</a></h3><div id="rfc.section.8.3.p.1"><p>Unless sent over a secure channel (such as TLS), the information in the Cookie and Set-Cookie headers is transmitted in the clear. </p><ol><li>All sensitive information conveyed in these headers is exposed to an eavesdropper.</li><li>A malicious intermediary could alter the headers as they travel in either direction, with unpredictable results.</li><li>A malicious client could alter the Cookie header before transmission, with unpredictable results.</li></ol></div><div id="rfc.section.8.3.p.2"><p>Servers <em class="bcp14">SHOULD</em> encrypt and sign the contents of cookies (using whatever format the server desires) when transmitting them to the user agent (even when sending the cookies over a secure channel). However, encrypting and signing cookie contents does not prevent an attacker from transplanting a cookie from one user agent to another or from replaying the cookie at a later time.</p></div><div id="rfc.section.8.3.p.3"><p>In addition to encrypting and signing the contents of every cookie, servers that require a higher level of security <em class="bcp14">SHOULD</em> use the Cookie and Set-Cookie headers only over a secure channel. When using cookies over a secure channel, servers <em class="bcp14">SHOULD</em> set the Secure attribute (see <a href="#sane-secure" title="The Secure Attribute">Section 4.1.2.5</a>) for every cookie. If a server does not set the Secure attribute, the protection provided by the secure channel will be largely moot.</p></div><div id="rfc.section.8.3.p.4"><p>For example, consider a webmail server that stores a session identifier in a cookie and is typically accessed over HTTPS. If the server does not set the Secure attribute on its cookies, an active network attacker can intercept any outbound HTTP request from the user agent and redirect that request to the webmail server over HTTP. Even if the webmail server is not listening for HTTP connections, the user agent will still include cookies in the request. The active network attacker can intercept these cookies, replay them against the server, and learn the contents of the user's email. If, instead, the server had set the Secure attribute on its cookies, the user agent would not have included the cookies in the clear-text request.</p></div></section><section id="session-identifiers"><h3 id="rfc.section.8.4"><a href="#rfc.section.8.4">8.4.</a> <a href="#session-identifiers">Session Identifiers</a></h3><div id="rfc.section.8.4.p.1"><p>Instead of storing session information directly in a cookie (where it might be exposed to or replayed by an attacker), servers commonly store a nonce (or "session identifier") in a cookie. When the server receives an HTTP request with a nonce, the server can look up state information associated with the cookie using the nonce as a key.</p></div><div id="rfc.section.8.4.p.2"><p>Using session identifier cookies limits the damage an attacker can cause if the attacker learns the contents of a cookie because the nonce is useful only for interacting with the server (unlike non-nonce cookie content, which might itself be sensitive). Furthermore, using a single nonce prevents an attacker from "splicing" together cookie content from two interactions with the server, which could cause the server to behave unexpectedly.</p></div><div id="rfc.section.8.4.p.3"><p>Using session identifiers is not without risk. For example, the server <em class="bcp14">SHOULD</em> take care to avoid "session fixation" vulnerabilities. A session fixation attack proceeds in three steps. First, the attacker transplants a session identifier from his or her user agent to the victim's user agent. Second, the victim uses that session identifier to interact with the server, possibly imbuing the session identifier with the user's credentials or confidential information. Third, the attacker uses the session identifier to interact with server directly, possibly obtaining the user's authority or confidential information.</p></div></section><section id="weak-confidentiality"><h3 id="rfc.section.8.5"><a href="#rfc.section.8.5">8.5.</a> <a href="#weak-confidentiality">Weak Confidentiality</a></h3><div id="rfc.section.8.5.p.1"><p>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 <em class="bcp14">SHOULD NOT</em> both run mutually distrusting services on different ports of the same host and use cookies to store security-sensitive information.</p></div><div id="rfc.section.8.5.p.2"><p>Cookies do not provide isolation by scheme. Although most commonly used with the http and https schemes, the cookies for a given host might also be available to other schemes, such as ftp and gopher. Although this lack of isolation by scheme is most apparent in non-HTTP APIs that permit access to cookies (e.g., HTML's document.cookie API), the lack of isolation by scheme is actually present in requirements for processing cookies themselves (e.g., consider retrieving a URI with the gopher scheme via HTTP).</p></div><div id="rfc.section.8.5.p.3"><p>Cookies do not always provide isolation by path. Although the network-level protocol does not send cookies stored for one path to another, some user agents expose cookies via non-HTTP APIs, such as HTML's document.cookie API. Because some of these user agents (e.g., web browsers) do not isolate resources received from different paths, a resource retrieved from one path might be able to access cookies stored for another path.</p></div></section><section id="weak-integrity"><h3 id="rfc.section.8.6"><a href="#rfc.section.8.6">8.6.</a> <a href="#weak-integrity">Weak Integrity</a></h3><div id="rfc.section.8.6.p.1"><p>Cookies do not provide integrity guarantees for sibling domains (and their subdomains). For example, consider foo.example.com and bar.example.com. The foo.example.com server can set a cookie with a Domain attribute of "example.com" (possibly overwriting an existing "example.com" cookie set by bar.example.com), and the user agent will include that cookie in HTTP requests to bar.example.com. In the worst case, bar.example.com will be unable to distinguish this cookie from a cookie it set itself. The foo.example.com server might be able to leverage this ability to mount an attack against bar.example.com.</p></div><div id="rfc.section.8.6.p.2"><p>Even though the Set-Cookie header supports the Path attribute, the Path attribute does not provide any integrity protection because the user agent will accept an arbitrary Path attribute in a Set-Cookie header. For example, an HTTP response to a request for http://example.com/foo/bar can set a cookie with a Path attribute of "/qux". Consequently, servers <em class="bcp14">SHOULD NOT</em> both run mutually distrusting services on different paths of the same host and use cookies to store security-sensitive information.</p></div><div id="rfc.section.8.6.p.3"><p>An active network attacker can also inject cookies into the Cookie header sent to https://example.com/ by impersonating a response from http://example.com/ and injecting a Set-Cookie header. The HTTPS server at example.com will be unable to distinguish these cookies from cookies that it set itself in an HTTPS response. An active network attacker might be able to leverage this ability to mount an attack against example.com even if example.com uses HTTPS exclusively.</p></div><div id="rfc.section.8.6.p.4"><p>Servers can partially mitigate these attacks by encrypting and signing the contents of their cookies. However, using cryptography does not mitigate the issue completely because an attacker can replay a cookie he or she received from the authentic example.com server in the user's session, with unpredictable results.</p></div><div id="rfc.section.8.6.p.5"><p>Finally, an attacker might be able to force the user agent to delete cookies by storing a large number of cookies. Once the user agent reaches its storage limit, the user agent will be forced to evict some cookies. Servers <em class="bcp14">SHOULD NOT</em> rely upon user agents retaining cookies.</p></div></section><section id="reliance-on-dns"><h3 id="rfc.section.8.7"><a href="#rfc.section.8.7">8.7.</a> <a href="#reliance-on-dns">Reliance on DNS</a></h3><div id="rfc.section.8.7.p.1"><p>Cookies rely upon the Domain Name System (DNS) for security. If the DNS is partially or fully compromised, the cookie protocol might fail to provide the security properties required by applications.</p></div></section></section><section id="iana-considerations"><h2 id="rfc.section.9"><a href="#rfc.section.9">9.</a> <a href="#iana-considerations">IANA Considerations</a></h2><div id="rfc.section.9.p.1"><p>The permanent message header field registry (see <a href="#RFC3864"><cite title="Registration Procedures for Message Header Fields">[RFC3864]</cite></a>) has been updated with the following registrations.</p></div><section id="n-cookie"><h3 id="rfc.section.9.1"><a href="#rfc.section.9.1">9.1.</a> <a href="#n-cookie">Cookie</a></h3><div id="rfc.section.9.1.p.1"><p>Header field name: Cookie</p></div><div id="rfc.section.9.1.p.2"><p>Applicable protocol: http</p></div><div id="rfc.section.9.1.p.3"><p>Status: standard</p></div><div id="rfc.section.9.1.p.4"><p>Author/Change controller: IETF</p></div><div id="rfc.section.9.1.p.5"><p>Specification document: this specification (<a href="#cookie" title="The Cookie Header">Section 5.4</a>)</p></div></section><section id="n-set-cookie"><h3 id="rfc.section.9.2"><a href="#rfc.section.9.2">9.2.</a> <a href="#n-set-cookie">Set-Cookie</a></h3><div id="rfc.section.9.2.p.1"><p>Header field name: Set-Cookie</p></div><div id="rfc.section.9.2.p.2"><p>Applicable protocol: http</p></div><div id="rfc.section.9.2.p.3"><p>Status: standard</p></div><div id="rfc.section.9.2.p.4"><p>Author/Change controller: IETF</p></div><div id="rfc.section.9.2.p.5"><p>Specification document: this specification (<a href="#set-cookie" title="The Set-Cookie Header">Section 5.2</a>)</p></div></section><section id="n-cookie2"><h3 id="rfc.section.9.3"><a href="#rfc.section.9.3">9.3.</a> <a href="#n-cookie2">Cookie2</a></h3><div id="rfc.section.9.3.p.1"><p>Header field name: Cookie2</p></div><div id="rfc.section.9.3.p.2"><p>Applicable protocol: http</p></div><div id="rfc.section.9.3.p.3"><p>Status: obsoleted</p></div><div id="rfc.section.9.3.p.4"><p>Author/Change controller: IETF</p></div><div id="rfc.section.9.3.p.5" class="avoidbreakafter"><p>Specification document: <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a></p></div></section><section id="n-set-cookie2"><h3 id="rfc.section.9.4"><a href="#rfc.section.9.4">9.4.</a> <a href="#n-set-cookie2">Set-Cookie2</a></h3><div id="rfc.section.9.4.p.1"><p>Header field name: Set-Cookie2</p></div><div id="rfc.section.9.4.p.2"><p>Applicable protocol: http</p></div><div id="rfc.section.9.4.p.3"><p>Status: obsoleted</p></div><div id="rfc.section.9.4.p.4"><p>Author/Change controller: IETF</p></div><div id="rfc.section.9.4.p.5" class="avoidbreakafter"><p>Specification document: <a href="#RFC2965"><cite title="HTTP State Management Mechanism">[RFC2965]</cite></a></p></div></section></section><section id="rfc.references"><h2 id="rfc.section.10"><a href="#rfc.section.10">10.</a> References</h2><section><div id="rfc.references.1"><h3 id="rfc.section.10.1"><a href="#rfc.section.10.1">10.1.</a> Normative References</h3><dl class="dl-horizontal"><dt id="RFC1034">[<a href="#RFC1034" class="smpl">RFC1034</a>]</dt><dd>Mockapetris, P., “<a href="https://www.rfc-editor.org/rfc/rfc1034.html">Domain names - concepts and facilities</a>”, <a href="https://www.rfc-editor.org/info/std13">STD 13</a>, RFC 1034, November 1987.</dd><dt id="RFC1123">[<a href="#RFC1123" class="smpl">RFC1123</a>]</dt><dd><a href="mailto:Braden@ISI.EDU">Braden, R.</a>, “<a href="https://www.rfc-editor.org/rfc/rfc1123.html">Requirements for Internet Hosts - Application and Support</a>”, <a href="https://www.rfc-editor.org/info/std3">STD 3</a>, RFC 1123, October 1989.</dd><dt id="RFC2119">[<a href="#RFC2119" class="smpl">RFC2119</a>]</dt><dd><a href="mailto:sob@harvard.edu">Bradner, S.</a>, “<a href="https://www.rfc-editor.org/rfc/rfc2119.html">Key words for use in RFCs to Indicate Requirement Levels</a>”, <a href="https://www.rfc-editor.org/info/bcp14">BCP 14</a>, RFC 2119, March 1997.</dd><dt id="RFC2616">[<a href="#RFC2616" class="smpl">RFC2616</a>]</dt><dd><a href="mailto:fielding@ics.uci.edu">Fielding, R.</a>, <a href="mailto:jg@w3.org">Gettys, J.</a>, <a href="mailto:mogul@wrl.dec.com">Mogul, J.</a>, <a href="mailto:frystyk@w3.org">Frystyk, H.</a>, <a href="mailto:masinter@parc.xerox.com">Masinter, L.</a>, <a href="mailto:paulle@microsoft.com">Leach, P.</a>, and <a href="mailto:timbl@w3.org">T. Berners-Lee</a>, “<a href="https://www.rfc-editor.org/rfc/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a>”, RFC 2616, June 1999.</dd><dt id="RFC3490">[<a href="#RFC3490" class="smpl">RFC3490</a>]</dt><dd>Faltstrom, P., Hoffman, P., and A. Costello, “<a href="https://www.rfc-editor.org/rfc/rfc3490.html">Internationalizing Domain Names in Applications (IDNA)</a>”, RFC 3490, March 2003.<br>See <a href="#idna-migration" title="IDNA Dependency and Migration">Section 6.3</a> for an explanation why the normative reference to an obsoleted specification is needed.</dd><dt id="RFC4790">[<a href="#RFC4790" class="smpl">RFC4790</a>]</dt><dd>Newman, C., Duerst, M., and A. Gulbrandsen, “<a href="https://www.rfc-editor.org/rfc/rfc4790.html">Internet Application Protocol Collation Registry</a>”, RFC 4790, March 2007.</dd><dt id="RFC5234">[<a href="#RFC5234" class="smpl">RFC5234</a>]</dt><dd><a href="mailto:dcrocker@bbiw.net">Crocker, D., Ed.</a> and <a href="mailto:paul.overell@thus.net">P. Overell</a>, “<a href="https://www.rfc-editor.org/rfc/rfc5234.html">Augmented BNF for Syntax Specifications: ABNF</a>”, <a href="https://www.rfc-editor.org/info/std68">STD 68</a>, RFC 5234, January 2008.</dd><dt id="RFC5890">[<a href="#RFC5890" class="smpl">RFC5890</a>]</dt><dd>Klensin, J., “<a href="https://www.rfc-editor.org/rfc/rfc5890.html">Internationalized Domain Names for Applications (IDNA): Definitions and Document Framework</a>”, RFC 5890, August 2010.</dd><dt id="USASCII">[<a href="#USASCII" class="smpl">USASCII</a>]</dt><dd>American National Standards Institute, “Coded Character Set -- 7-bit American Standard Code for Information Interchange”, ANSI X3.4, 1986.</dd></dl></div></section><section><div id="rfc.references.2"><h3 id="rfc.section.10.2"><a href="#rfc.section.10.2">10.2.</a> Informative References</h3><dl class="dl-horizontal"><dt id="RFC2109">[<a href="#RFC2109" class="smpl">RFC2109</a>]</dt><dd><a href="mailto:dmk@bell-labs.com">Kristol, D.</a> and <a href="mailto:montulli@netscape.com">L. Montulli</a>, “<a href="https://www.rfc-editor.org/rfc/rfc2109.html">HTTP State Management Mechanism</a>”, RFC 2109, February 1997.</dd><dt id="RFC2965">[<a href="#RFC2965" class="smpl">RFC2965</a>]</dt><dd><a href="mailto:dmk@bell-labs.com">Kristol, D.</a> and <a href="mailto:lou@montulli.org">L. Montulli</a>, “<a href="https://www.rfc-editor.org/rfc/rfc2965.html">HTTP State Management Mechanism</a>”, RFC 2965, October 2000.</dd><dt id="RFC2818">[<a href="#RFC2818" class="smpl">RFC2818</a>]</dt><dd>Rescorla, E., “<a href="https://www.rfc-editor.org/rfc/rfc2818.html">HTTP Over TLS</a>”, RFC 2818, May 2000.</dd><dt id="Netscape">[<a href="#Netscape" class="smpl">Netscape</a>]</dt><dd>Netscape Communications Corp., “<a href="http://web.archive.org/web/20020803110822/http://wp.netscape.com/newsref/std/cookie_spec.html">Persistent Client State -- HTTP Cookies</a>”, 1999, <<a href="http://web.archive.org/web/20020803110822/http://wp.netscape.com/newsref/std/cookie_spec.html">http://web.archive.org/web/20020803110822/http://wp.netscape.com/newsref/std/cookie_spec.html</a>>.</dd><dt id="Kri2001">[<a href="#Kri2001" class="smpl">Kri2001</a>]</dt><dd>Kristol, D., “<a href="http://arxiv.org/abs/cs.SE/0105018">HTTP Cookies: Standards, Privacy, and Politics</a>”, ACM Transactions on Internet Technology Vol. 1, #2, November 2001, <<a href="http://arxiv.org/abs/cs.SE/0105018">http://arxiv.org/abs/cs.SE/0105018</a>>.</dd><dt id="RFC3629">[<a href="#RFC3629" class="smpl">RFC3629</a>]</dt><dd>Yergeau, F., “<a href="https://www.rfc-editor.org/rfc/rfc3629.html">UTF-8, a transformation format of ISO 10646</a>”, <a href="https://www.rfc-editor.org/info/std63">STD 63</a>, RFC 3629, November 2003.</dd><dt id="RFC4648">[<a href="#RFC4648" class="smpl">RFC4648</a>]</dt><dd>Josefsson, S., “<a href="https://www.rfc-editor.org/rfc/rfc4648.html">The Base16, Base32, and Base64 Data Encodings</a>”, RFC 4648, October 2006.</dd><dt id="RFC3864">[<a href="#RFC3864" class="smpl">RFC3864</a>]</dt><dd>Klyne, G., Nottingham, M., and J. Mogul, “<a href="https://www.rfc-editor.org/rfc/rfc3864.html">Registration Procedures for Message Header Fields</a>”, <a href="https://www.rfc-editor.org/info/bcp90">BCP 90</a>, RFC 3864, September 2004.</dd><dt id="RFC5895">[<a href="#RFC5895" class="smpl">RFC5895</a>]</dt><dd>Resnick, P. and P. Hoffman, “<a href="https://www.rfc-editor.org/rfc/rfc5895.html">Mapping Characters for Internationalized Domain Names in Applications (IDNA) 2008</a>”, RFC 5895, September 2010.</dd><dt id="UTS46">[<a href="#UTS46" class="smpl">UTS46</a>]</dt><dd>Davis, M. and M. Suignard, “<a href="http://unicode.org/reports/tr46/">Unicode IDNA Compatibility Processing</a>”, Unicode Technical Standards # 46, 2010, <<a href="http://unicode.org/reports/tr46/">http://unicode.org/reports/tr46/</a>>.</dd><dt id="CSRF">[<a href="#CSRF" class="smpl">CSRF</a>]</dt><dd>Barth, A., Jackson, C., and J. Mitchell, “<a href="http://portal.acm.org/citation.cfm?id=1455770.1455782">Robust Defenses for Cross-Site Request Forgery</a>”, 2008, <<a href="http://portal.acm.org/citation.cfm?id=1455770.1455782">http://portal.acm.org/citation.cfm?id=1455770.1455782</a>>.</dd><dt id="Aggarwal2010">[<a href="#Aggarwal2010" class="smpl">Aggarwal2010</a>]</dt><dd>Aggarwal, G., Burzstein, E., Jackson, C., and D. Boneh, “<a href="http://www.usenix.org/events/sec10/tech/full_papers/Aggarwal.pdf">An Analysis of Private Browsing Modes in Modern Browsers</a>”, 2010, <<a href="http://www.usenix.org/events/sec10/tech/full_papers/Aggarwal.pdf">http://www.usenix.org/events/sec10/tech/full_papers/Aggarwal.pdf</a>>.</dd></dl></div></section></section><section id="n-acknowledgements"><h2 id="rfc.section.A" class="np"><a href="#rfc.section.A">Appendix A.</a> <a href="#n-acknowledgements">Acknowledgements</a></h2><div id="rfc.section.A.p.1"><p>This document borrows heavily from RFC 2109 <a href="#RFC2109"><cite title="HTTP State Management Mechanism">[RFC2109]</cite></a>. We are indebted to David M. Kristol and Lou Montulli for their efforts to specify cookies. David M. Kristol, in particular, provided invaluable advice on navigating the IETF process. We would also like to thank Thomas Broyer, Tyler Close, Alissa Cooper, Bil Corry, corvid, Lisa Dusseault, Roy T. Fielding, Blake Frantz, Anne van Kesteren, Eran Hammer-Lahav, Jeff Hodges, Bjoern Hoehrmann, Achim Hoffmann, Georg Koppen, Dean McNamee, Alexey Melnikov, Mark Miller, Mark Pauley, Yngve N. Pettersen, Julian Reschke, Peter Saint-Andre, Mark Seaborn, Maciej Stachowiak, Daniel Stenberg, Tatsuhiro Tsujikawa, David Wagner, Dan Winship, and Dan Witte for their valuable feedback on this document.</p></div></section><section id="rfc.authors" class="avoidbreakinside"><h2><a href="#rfc.authors">Author's Address</a></h2><address><b>Adam Barth</b><br> University of California, Berkeley <br>Email: <a href="mailto:abarth@eecs.berkeley.edu">abarth@eecs.berkeley.edu</a><br>URI: <a href="http://www.adambarth.com/">http://www.adambarth.com/</a></address></section></div></div></div><script src="/assets/node_modules/jquery/dist/jquery.min.js"></script><script src="/assets/node_modules/bootstrap/dist/js/bootstrap.min.js"></script></body></html>