Skip to content

Commit d6d071b

Browse files
committed
Fix httpwg#1399 - Add a grammar corresponding to the parsing algorithm
1 parent 3955196 commit d6d071b

File tree

1 file changed

+64
-5
lines changed

1 file changed

+64
-5
lines changed

draft-ietf-httpbis-rfc6265bis.md

+64-5
Original file line numberDiff line numberDiff line change
@@ -478,12 +478,14 @@ Cookie and Set-Cookie header fields.
478478
The Set-Cookie HTTP response header field is used to send cookies from the server to
479479
the user agent.
480480

481-
### Syntax {#abnf-syntax}
481+
### Syntax {#sane-abnf-syntax}
482482

483483
Informally, the Set-Cookie response header field contains a cookie, which begins with a
484484
name-value-pair, followed by zero or more attribute-value pairs. Servers
485-
SHOULD NOT send Set-Cookie header fields that fail to conform to the following
486-
grammar:
485+
SHOULD NOT send Set-Cookie header fields that fail to conform to the grammar below.
486+
487+
Note that the grammar used by the user agent when processing Set-Cookie header fields
488+
is more permissive than this grammar. (See {{ua-abnf-syntax}} for more details.)
487489

488490
~~~ abnf
489491
set-cookie = set-cookie-string
@@ -1121,7 +1123,8 @@ in {{sane-set-cookie}} forbids whitespace in these positions. In addition, the
11211123
algorithm below accommodates some characters that are not cookie-octets
11221124
according to the grammar in {{sane-set-cookie}}. User agents use this algorithm
11231125
so as to interoperate with servers that do not follow the recommendations in
1124-
{{sane-profile}}.
1126+
{{sane-profile}}. See {{ua-set-cookie}} for a grammar that corresponds to
1127+
the algorithm.
11251128

11261129
NOTE: As set-cookie-string may originate from a non-HTTP API, it is not
11271130
guaranteed to be free of CTL characters, so this algorithm handles them
@@ -1394,6 +1397,62 @@ with
13941397
elapsed since the cookie's creation-time is at most a duration of the
13951398
user agent's choosing.
13961399

1400+
## Syntax {#ua-abnf-syntax}
1401+
1402+
Based on the parsing algorithms defined above, the following grammar defines
1403+
the syntax requirements enforced by user agents when parsing specific
1404+
subcomponents of the Cookie and Set-Cookie header fields:
1405+
1406+
~~~ abnf
1407+
set-cookie = set-cookie-string
1408+
set-cookie-string = cookie-pair *( BWS ";" OWS cookie-av)
1409+
cookie-pair = *1(BWS cookie-name BWS "=") BWS cookie-value BWS
1410+
; cookie-name plus cookie-value must be less than
1411+
; or equal to 4096 octets
1412+
1413+
cookie-name = *4096(cookie-name-octet)
1414+
cookie-value = *4096(cookie-value-octet)
1415+
cookie-name-octet = %x09 / %x20-3A / %x3C / %x3E-7E / %x80-FF
1416+
; octets excluding non-whitespace CTLs,
1417+
; semicolon, and equals
1418+
cookie-value-octet = %x09 / %x20-3A / %x3C-7E / %x80-FF
1419+
; octets excluding non-whitespace CTLs and
1420+
; semicolon
1421+
1422+
cookie-av = expires-av / max-age-av / domain-av /
1423+
path-av / secure-av / httponly-av /
1424+
samesite-av / extension-av
1425+
; attributes that don't conform to the grammars
1426+
; below are ignored
1427+
1428+
expires-av = "Expires" BWS "=" BWS cookie-date BWS
1429+
; cookie-date is defined in separate grammar
1430+
; in a previous section
1431+
1432+
max-age-av = "Max-Age" BWS "=" BWS max-age-value BWS
1433+
max-age-value = 1*1024(DIGIT) / "-" 1*1023(DIGIT)
1434+
1435+
domain-av = "Domain" BWS "=" BWS domain-value BWS
1436+
domain-value = 1*1024(cookie-value-octet)
1437+
; a leading dot in domain-value will be removed
1438+
; if present
1439+
1440+
path-av = "Path" BWS "=" BWS path-value BWS
1441+
path-value = 1*1024(cookie-value-octet)
1442+
1443+
secure-av = "Secure" BWS *ignored-value
1444+
1445+
httponly-av = "HttpOnly" BWS *ignored-value
1446+
1447+
samesite-av = "SameSite" BWS "=" BWS samesite-value BWS
1448+
samesite-value = "Strict" / "Lax" / "None"
1449+
1450+
extension-av = 1*cookie-name-octet BWS *optional-value
1451+
1452+
ignored-value = "=" BWS *1024(cookie-value-octet) BWS
1453+
optional-value = ignored-value
1454+
~~~
1455+
13971456
## Storage Model {#storage-model}
13981457

13991458
The user agent stores the following fields about each cookie: name, value,
@@ -2255,7 +2314,7 @@ reference detailing how the attribute is to be processed and stored.
22552314

22562315
New registrations happen on a "RFC Required" basis (see Section 4.7 of
22572316
{{RFC8126}}). The attribute to be registered MUST match the `extension-av`
2258-
syntax defined in {{abnf-syntax}}. Note that attribute names are generally
2317+
syntax defined in {{sane-abnf-syntax}}. Note that attribute names are generally
22592318
defined in CamelCase, but technically accepted case-insensitively.
22602319

22612320
### Registration

0 commit comments

Comments
 (0)