roadrunner_cookie (roadrunner v0.11.1)
View SourceHTTP cookie codec (RFC 6265).
Provides parse/1 for the request-side Cookie header and
serialize/3 for the response-side Set-Cookie header.
Summary
Types
Optional attributes for the Set-Cookie header per RFC 6265 §4.1.
Functions
Parse a Cookie header value into a list of {Name, Value} pairs in
the order they appear on the wire.
Build a Set-Cookie header value as iodata.
Types
-type serialize_opts() :: #{domain => binary(), path => binary(), max_age => non_neg_integer(), expires => binary(), secure => boolean(), http_only => boolean(), same_site => strict | lax | none}.
Optional attributes for the Set-Cookie header per RFC 6265 §4.1.
domain— explicitDomainattribute. Default is the response host (noDomainattribute emitted), which limits the cookie to that exact host.path— explicitPathattribute. Default is noPathattribute, so the browser scopes the cookie to the request path's directory (RFC 6265 §5.1.4). Setpath => ~"/"for a site-wide cookie.max_age— seconds until the cookie expires.0deletes the cookie. Browsers preferMax-AgeoverExpireswhen both are present (RFC 6265 §5.3 step 3).expires— IMF-fixdate string for clients that ignoreMax-Age(useroadrunner_http:format_http_date/1).secure— restrict transmission to HTTPS.http_only— hide from JavaScript (document.cookie).same_site— cross-site request policy:strict,lax, ornone.nonerequiressecure => true.
Functions
Parse a Cookie header value into a list of {Name, Value} pairs in
the order they appear on the wire.
OWS (SP and HTAB) around each pair is trimmed. Pairs missing = or
with an empty name are silently skipped (cowboy parity); empty values
are accepted. Only the first = in a pair separates name from value,
so a cookie like sid=a=b=c parses as a single pair with value a=b=c.
-spec serialize(Name :: binary(), Value :: binary(), serialize_opts()) -> iodata().
Build a Set-Cookie header value as iodata.
Attributes are appended in this fixed order: Domain, Path,
Max-Age, Expires, Secure, HttpOnly, SameSite. Boolean flags
(secure, http_only) appear only when set to true; setting them
to false is equivalent to omitting them. same_site accepts
strict, lax, or none.
Each user-supplied binary is validated against the RFC 6265 §4.1.1 grammar before any iodata is produced; on a violation the call crashes with one of:
{invalid_cookie_name, Bin}—Nameis empty or has a byte outside RFC 7230 §3.2.6token{invalid_cookie_value, Bin}—Valuehas a byte outsidecookie-octet(CTL, SP, DQUOTE,,,;,\\){invalid_cookie_attr, AttrName, Bin}—Domain,Path, orExpirescontains a CTL or;(the bytes that would let a malicious caller smuggle attributes or split the header line)
Crashing matches the discipline applied elsewhere in the framework: a programmer bug echoing user input into a cookie turns into a 500, not a wire-level vulnerability.