HTTP cookies
The IETF HTTP State Management Mechanism defines the Set-Cookie response header field, which stores a name-value pair at the user agent, and the Cookie request header field, which returns it. RFC 6265 is the published standard; draft-ietf-httpbis-rfc6265bis will obsolete it and adds SameSite, the cookie name prefixes and stricter limits. With this skill the agent writes and reviews server-side cookie handling: the exact Set-Cookie strings, how to read Cookie, and the security posture of each cookie.
Follow the workflow below step by step. Every rule here comes from a source in Sources, with the section it cites. When a rule and the pinned source disagree, the source wins; when the source has a newer revision than the pin, follow the refresh steps.
Section numbers without a prefix are RFC 6265bis-22. "6265 §" marks RFC 6265.
Inputs (fill in, or ask before starting)
- Role: cookie producer (a server, framework or API that sends
Set-Cookie), cookie reader (a server that parsesCookie), or both. User agent implementers follow § 5 of the draft directly; this skill targets servers (§ 3.2.1). - Target version: RFC 6265 is current, and every cookie must stay valid under it. RFC 6265bis is a preview (posture: build): emit its SameSite attribute and name prefixes now, because browsers implement them and RFC 6265 user agents ignore unrecognized attributes (6265 § 4.1.2). RFC 2965 and RFC 2109 are legacy: read and upgrade from them, never emit
Set-Cookie2or$Version. Seereferences/versions.md. - Revision: the pinned revision in Sources, unless the user names another.
- Deployment: the hosts that set and read each cookie, whether every one of them is HTTPS-only, and whether any sibling subdomain is run by a less trusted party.
- Cross-site needs: does any cookie have to be sent in an iframe, a cross-site
fetch, or a cross-sitePOST(single sign-on, embedded widgets)? - Sources: when refreshing this skill or when a rule looks out of date, re-read every URL in Sources first, check the datatracker for a new draft revision or a
became_rfcrelation, and update the pins.
Invariants
- One cookie per
Set-Cookiefield. Never fold severalSet-Cookiefields into one with commas (6265 § 3: SHOULD NOT; § 3: MUST NOT), and send at most oneSet-Cookieper cookie-name in a response (6265 § 4.1.1; § 4.1.1). - Follow the server grammar.
cookie-nameis a non-empty token andcookie-valueuses onlycookie-octet(no whitespace,",,,;or\), optionally inside double quotes that stay part of the value (6265 § 4.1.1; § 4.1.1). Encode arbitrary data, for example with Base64 (6265 § 4.1.1). - No duplicate attributes in one
set-cookie-string(6265 § 4.1.1: SHOULD NOT; § 4.1.1: MUST NOT). - Dates are
IMF-fixdatewith a four-digit year, such asWed, 09 Jun 2027 10:18:14 GMT(6265 § 4.1.1rfc1123-date; § 4.1.1).Max-Agewins overExpires(6265 § 4.1.2.2). Secureon every cookie served over HTTPS (6265 § 8.3; § 8.3). Without it the secure channel's protection is "largely moot".SameSite=NonerequiresSecure. User agents drop aSameSite=Nonecookie without it (§ 5.7 step 19).- Prefixes carry their conditions.
__Secure-needsSecure;__Host-needsSecure,Path=/and noDomain, and is set from a secure origin (§ 4.1.3, § 5.7 steps 20 and 21). - Size. The name plus the value must be at most 4096 octets, and each attribute value at most 1024 octets, or the user agent drops it (§ 5.6, § 5.7 step 4). Keep the whole
Cookieheader under the server's field limit, often 8192 octets (§ 4.2.1). - Delete with the same scope. A deletion
Set-Cookierepeats the original name,PathandDomainand setsExpiresto a date in the past (§ 3.1, § 4.1.2).Max-Age=0also expires the cookie at the user agent (§ 5.6.2), but the server grammar only allows aMax-Agethat starts with 1 to 9 (§ 4.1.1). - The
Cookieheader carries names and values only. Do not infer attributes, expiry or origin from it, and do not rely on the order of cookies, even two with the same name (6265 § 4.2.2; § 4.2.2). Tolerate severalCookiefields in one request (§ 4.2.1: MUST). - Cookies can disappear. Degrade gracefully when one is missing, because user agents evict at any time (6265 § 6.1, § 8.6; § 6.1, § 8.6).
- Cookies are not an isolation boundary between ports, schemes, paths or sibling subdomains (6265 § 8.5, § 8.6; § 8.5, § 8.6). Do not share a host, or a parent domain cookie, with a mutually distrusting service.
- Store a session identifier, not session data, and avoid session fixation (6265 § 8.4; § 8.4).
Workflow
- Pick the version. Target RFC 6265 plus the RFC 6265bis server profile, which is a strict subset of what RFC 6265 user agents accept. Upgrade any
Set-Cookie2or$Versioncode. ->references/versions.md✓ No legacy header is emitted, and every cookie parses under both RFC 6265 and RFC 6265bis. - Inventory cookies. For each cookie, record its purpose, the hosts and paths that need it, whether script needs to read it, whether it must travel cross-site, and how long it must live.
->
references/storage-and-limits.md✓ Every cookie has an owner, a scope and a lifetime, and the set is as few and as small as possible (§ 6.1). - Choose the scope. Prefer host-only (no
Domain) andPath=/; addDomainonly when sibling hosts must receive the cookie, knowing every subdomain can then read and overwrite it (§ 4.1.2.3, § 8.6).Pathis not a security boundary (§ 4.1.2.4). ->references/set-cookie-attributes.md✓ EveryDomainis justified, and no security cookie depends onPathfor isolation. - Choose the protections.
Secureon all HTTPS cookies;HttpOnlyunless script must read the value; an explicitSameSite(StrictorLaxby default,NonewithSecureonly for cross-site use);__Host-for session cookies, or__Secure-whenDomainis needed. ->references/same-site-and-prefixes.md✓ Each cookie's flags match its inventory row, and every prefixed cookie meets its prefix rules. - Choose the lifetime. Session cookie (no
ExpiresorMax-Age) or a purpose-basedMax-Age; nothing past 400 days, which user agents cap anyway (§ 5.5, § 7.4). ->references/storage-and-limits.md✓ No cookie asks for more than 400 days, and none relies on being kept until expiry. - Serialize
Set-Cookie. Build the string with a structured API rather than string concatenation (§ 6.2), one field per cookie. ->references/set-cookie-attributes.md✓ Each header matches the § 4.1.1 grammar, with no repeated attribute and no repeated name in one response. - Read
Cookie. Split on"; ", accept severalCookiefields, treat names case-sensitively, and handle duplicate names without relying on order. ->references/set-cookie-attributes.md✓ The parser handles a missing cookie, a duplicate name and a split header. - Harden. Check sessions against fixation, state-changing endpoints against CSRF with a defense beyond SameSite, and sibling subdomains against cookie tossing.
->
references/security.md✓ Every item in the security checklist is answered. - Upgrade (only when asked). Follow the path in versions.md: RFC 2109 or RFC 2965 to RFC 6265, then RFC 6265 to the RFC 6265bis profile.
->
references/versions.md✓ The same cookies reach the same hosts and paths, and no new cookie is rejected by a user agent.
Verify before done
- Every
Set-Cookiematches the § 4.1.1 grammar: non-empty token name,cookie-octetvalue, no repeated attribute, one field per cookie. - Every cookie set over HTTPS has
Secure; everySameSite=Nonecookie hasSecure. - Every cookie has an explicit
SameSitevalue chosen for its cross-site needs, not the user agent default. - Every
__Host-cookie hasSecure; Path=/and noDomain; every__Secure-cookie hasSecure. - Session and authentication cookies are
HttpOnly, hold an opaque identifier, and are re-issued when the session's privilege changes. - No cookie requests a lifetime above 400 days; name plus value stay under 4096 octets; attribute values under 1024.
- Deletions repeat the original
DomainandPath. - The
Cookieparser tolerates several fields, duplicate names and missing cookies. - Nothing emits
Set-Cookie2,Cookie2,$Version,Comment,CommentURL,DiscardorPort.
Reference index
references/versions.md: RFC 6265, RFC 6265bis, RFC 2965 and RFC 2109 with status, what changed, the upgrade steps and the preview's posture. Load for steps 1 and 9.references/set-cookie-attributes.md: theSet-CookieandCookiegrammars, each attribute with server rules and user agent handling, deletion and examples. Load for steps 3, 6 and 7.references/same-site-and-prefixes.md: same-site and cross-site requests,Strict,Lax,None, Lax-by-default and Lax-allowing-unsafe, and the__Secure-and__Host-prefixes. Load for step 4.references/storage-and-limits.md: the user agent's storage model, replacement and eviction, size and count limits, the 400-day cap, session cookies and the public suffix list. Load for steps 2 and 5.references/security.md: ambient authority and CSRF, clear text, session identifiers and fixation, weak confidentiality and integrity, subdomain attacks, SameSite caveats and privacy. Load for step 8.
Related skills
http-semanticsfor header field syntax,IMF-fixdateand safe methods:npx skills add ScaleDockHQ/scaledock-skills --skill http-semantics.hststo stop the HTTP downgrade that lets an active attacker read or inject cookies:npx skills add ScaleDockHQ/scaledock-skills --skill hsts.content-security-policyto reduce the cross-site scripting that defeats SameSite and reads non-HttpOnlycookies:npx skills add ScaleDockHQ/scaledock-skills --skill content-security-policy.owasp-asvsfor session management and CSRF verification requirements:npx skills add ScaleDockHQ/scaledock-skills --skill owasp-asvs.
Sources
Status uses the publishing body's own maturity term. Checked is the date the source was last read.
- RFC 6265: HTTP State Management Mechanism: RFC (Proposed Standard), RFC 6265 (April 2011), checked 2026-10-05.
- draft-ietf-httpbis-rfc6265bis-22: Cookies: HTTP State Management Mechanism: Internet-Draft (HTTPBIS WG, intended Proposed Standard), revision 22 (1 December 2025), checked 2026-10-05.
- draft-ietf-httpbis-rfc6265bis datatracker entry: IESG state RFC Ed Queue, no
became_rfcrelation, latest revision 22, checked 2026-10-05. - RFC 2965: HTTP State Management Mechanism: RFC (Historic, obsoleted by RFC 6265), RFC 2965 (October 2000), checked 2026-10-05.
- RFC 2109: HTTP State Management Mechanism: RFC (Historic, obsoleted by RFC 2965), RFC 2109 (February 1997), checked 2026-10-05.
- HTML Living Standard: sites and same site: WHATWG Living Standard, the
[SAMESITE]reference of RFC 6265bis, checked 2026-10-05.