Skip to content

Commit 11d8daf

Browse files
committed
Fix httpwg#1399 - RFC6265bis: Add a grammar corresponding to the parsing algorithm
1 parent 6635979 commit 11d8daf

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
@@ -1112,7 +1114,8 @@ in {{sane-set-cookie}} forbids whitespace in these positions. In addition, the
11121114
algorithm below accommodates some characters that are not cookie-octets
11131115
according to the grammar in {{sane-set-cookie}}. User agents use this algorithm
11141116
so as to interoperate with servers that do not follow the recommendations in
1115-
{{sane-profile}}.
1117+
{{sane-profile}}. See {{ua-set-cookie}} for a grammar that corresponds to
1118+
the algorithm.
11161119

11171120
NOTE: As set-cookie-string may originate from a non-HTTP API, it is not
11181121
guaranteed to be free of CTL characters, so this algorithm handles them
@@ -1378,6 +1381,62 @@ with
13781381
elapsed since the cookie's creation-time is at most a duration of the
13791382
user agent's choosing.
13801383

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

13831442
The user agent stores the following fields about each cookie: name, value,
@@ -2238,7 +2297,7 @@ reference detailing how the attribute is to be processed and stored.
22382297

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

22442303
### Registration

0 commit comments

Comments
 (0)