@@ -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
@@ -1121,7 +1123,8 @@ in {{sane-set-cookie}} forbids whitespace in these positions. In addition, the
1121
1123
algorithm below accommodates some characters that are not cookie-octets
1122
1124
according to the grammar in {{sane-set-cookie}}. User agents use this algorithm
1123
1125
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.
1125
1128
1126
1129
NOTE : As set-cookie-string may originate from a non-HTTP API, it is not
1127
1130
guaranteed to be free of CTL characters, so this algorithm handles them
@@ -1394,6 +1397,62 @@ with
1394
1397
elapsed since the cookie's creation-time is at most a duration of the
1395
1398
user agent's choosing.
1396
1399
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
+
1397
1456
# # Storage Model {#storage-model}
1398
1457
1399
1458
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.
2255
2314
2256
2315
New registrations happen on a "RFC Required" basis (see Section 4.7 of
2257
2316
{{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
2259
2318
defined in CamelCase, but technically accepted case-insensitively.
2260
2319
2261
2320
# ## Registration
0 commit comments