@@ -478,12 +478,14 @@ Cookie and Set-Cookie header fields.
478
478
The Set-Cookie HTTP response header field is used to send cookies from the server to
479
479
the user agent.
480
480
481
- # ## Syntax {#abnf-syntax}
481
+ # ## Syntax {#sane- abnf-syntax}
482
482
483
483
Informally, the Set-Cookie response header field contains a cookie, which begins with a
484
484
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.)
487
489
488
490
~~~ abnf
489
491
set-cookie = set-cookie-string
@@ -1112,7 +1114,8 @@ in {{sane-set-cookie}} forbids whitespace in these positions. In addition, the
1112
1114
algorithm below accommodates some characters that are not cookie-octets
1113
1115
according to the grammar in {{sane-set-cookie}}. User agents use this algorithm
1114
1116
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.
1116
1119
1117
1120
NOTE : As set-cookie-string may originate from a non-HTTP API, it is not
1118
1121
guaranteed to be free of CTL characters, so this algorithm handles them
@@ -1378,6 +1381,62 @@ with
1378
1381
elapsed since the cookie's creation-time is at most a duration of the
1379
1382
user agent's choosing.
1380
1383
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
+
1381
1440
# # Storage Model {#storage-model}
1382
1441
1383
1442
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.
2238
2297
2239
2298
New registrations happen on a "RFC Required" basis (see Section 4.7 of
2240
2299
{{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
2242
2301
defined in CamelCase, but technically accepted case-insensitively.
2243
2302
2244
2303
# ## Registration
0 commit comments