@@ -1098,14 +1098,27 @@ set-cookie-string (defined below).
1098
1098
NOTE : The algorithm below is more permissive than the grammar in {{sane-set-cookie}}.
1099
1099
For example, the algorithm strips leading and trailing whitespace from the
1100
1100
cookie name and value (but maintains internal whitespace), whereas the grammar
1101
- in {{sane-set-cookie}} forbids whitespace in these positions. User agents use this
1102
- algorithm so as to interoperate with servers that do not follow the
1103
- recommendations in {{sane-profile}}.
1101
+ in {{sane-set-cookie}} forbids whitespace in these positions. In addition, the
1102
+ algorithm below accommodates some characters that are not cookie-octets
1103
+ according to the grammar in {{sane-set-cookie}}. User agents use this algorithm
1104
+ so as to interoperate with servers that do not follow the recommendations in
1105
+ {{sane-profile}}.
1106
+
1107
+ NOTE : As set-cookie-string may originate from a non-HTTP API, it is not
1108
+ guaranteed to be free of CTL characters, so this algorithm handles them
1109
+ explicitly.
1104
1110
1105
1111
A user agent MUST use an algorithm equivalent to the following algorithm to
1106
1112
parse a set-cookie-string :
1107
1113
1108
- 1. If the set-cookie-string contains a %x3B (";") character :
1114
+ 1. If the set-cookie-string contains a %x0D (CR), %x0A (LF), or %x00 (NUL)
1115
+ octet, then set the set-cookie-string equal to all the characters of
1116
+ set-cookie-string up to, but not including, the first such octet.
1117
+
1118
+ 2. If the set-cookie-string contains a %x00-1F / %x7F (CTL) character :
1119
+ Abort these steps and ignore the set-cookie-string entirely.
1120
+
1121
+ 3. If the set-cookie-string contains a %x3B (";") character :
1109
1122
1110
1123
1. The name-value-pair string consists of the characters up to, but not
1111
1124
including, the first %x3B (";"), and the unparsed-attributes consist of
@@ -1118,17 +1131,17 @@ parse a set-cookie-string:
1118
1131
the set-cookie-string, and the unparsed-attributes is the empty
1119
1132
string.
1120
1133
1121
- 2 . If the name-value-pair string lacks a %x3D ("=") character, then the name
1134
+ 4 . If the name-value-pair string lacks a %x3D ("=") character, then the name
1122
1135
string is empty, and the value string is the value of name-value-pair.
1123
1136
1124
1137
Otherwise, the name string consists of the characters up to, but not
1125
1138
including, the first %x3D ("=") character, and the (possibly empty) value
1126
1139
string consists of the characters after the first %x3D ("=") character.
1127
1140
1128
- 3 . Remove any leading or trailing WSP characters from the name string and the
1141
+ 5 . Remove any leading or trailing WSP characters from the name string and the
1129
1142
value string.
1130
1143
1131
- 4 . The cookie-name is the name string, and the cookie-value is the value string.
1144
+ 6 . The cookie-name is the name string, and the cookie-value is the value string.
1132
1145
1133
1146
The user agent MUST use an algorithm equivalent to the following algorithm to
1134
1147
parse the unparsed-attributes :
@@ -1336,10 +1349,13 @@ user agent MUST process the cookie as follows:
1336
1349
2. If cookie-name is empty and cookie-value is empty, abort these steps and
1337
1350
ignore the cookie entirely.
1338
1351
1339
- 3. Create a new cookie with name cookie-name, value cookie-value. Set the
1352
+ 3. If the cookie-name or the cookie-value contains a %x00-1F / %x7F (CTL)
1353
+ character, abort these steps and ignore the cookie entirely.
1354
+
1355
+ 4. Create a new cookie with name cookie-name, value cookie-value. Set the
1340
1356
creation-time and the last-access-time to the current date and time.
1341
1357
1342
- 4 . If the cookie-attribute-list contains an attribute with an attribute-name
1358
+ 5 . If the cookie-attribute-list contains an attribute with an attribute-name
1343
1359
of "Max-Age" :
1344
1360
1345
1361
1. Set the cookie's persistent-flag to true.
@@ -1364,7 +1380,7 @@ user agent MUST process the cookie as follows:
1364
1380
1365
1381
2. Set the cookie's expiry-time to the latest representable date.
1366
1382
1367
- 5 . If the cookie-attribute-list contains an attribute with an
1383
+ 6 . If the cookie-attribute-list contains an attribute with an
1368
1384
attribute-name of "Domain" :
1369
1385
1370
1386
1. Let the domain-attribute be the attribute-value of the last
@@ -1375,7 +1391,7 @@ user agent MUST process the cookie as follows:
1375
1391
1376
1392
1. Let the domain-attribute be the empty string.
1377
1393
1378
- 6 . If the user agent is configured to reject "public suffixes" and the
1394
+ 7 . If the user agent is configured to reject "public suffixes" and the
1379
1395
domain-attribute is a public suffix :
1380
1396
1381
1397
1. If the domain-attribute is identical to the canonicalized
@@ -1390,7 +1406,7 @@ user agent MUST process the cookie as follows:
1390
1406
NOTE : This step prevents `attacker.example` from disrupting the integrity of
1391
1407
` site.example` by setting a cookie with a Domain attribute of "example".
1392
1408
1393
- 7 . If the domain-attribute is non-empty :
1409
+ 8 . If the domain-attribute is non-empty :
1394
1410
1395
1411
1. If the canonicalized request-host does not domain-match the
1396
1412
domain-attribute :
@@ -1409,28 +1425,28 @@ user agent MUST process the cookie as follows:
1409
1425
1410
1426
2. Set the cookie's domain to the canonicalized request-host.
1411
1427
1412
- 8 . If the cookie-attribute-list contains an attribute with an
1428
+ 9 . If the cookie-attribute-list contains an attribute with an
1413
1429
attribute-name of "Path", set the cookie's path to attribute-value of
1414
1430
the last attribute in the cookie-attribute-list with an attribute-name
1415
1431
of "Path". Otherwise, set the cookie's path to the default-path of the
1416
1432
request-uri.
1417
1433
1418
- 9. If the cookie-attribute-list contains an attribute with an
1434
+ 10. If the cookie-attribute-list contains an attribute with an
1419
1435
attribute-name of "Secure", set the cookie's secure-only-flag to true.
1420
1436
Otherwise, set the cookie's secure-only-flag to false.
1421
1437
1422
- 10 . If the scheme component of the request-uri does not denote a "secure"
1438
+ 11 . If the scheme component of the request-uri does not denote a "secure"
1423
1439
protocol (as defined by the user agent), and the cookie's secure-only-flag
1424
1440
is true, then abort these steps and ignore the cookie entirely.
1425
1441
1426
- 11 . If the cookie-attribute-list contains an attribute with an
1442
+ 12 . If the cookie-attribute-list contains an attribute with an
1427
1443
attribute-name of "HttpOnly", set the cookie's http-only-flag to true.
1428
1444
Otherwise, set the cookie's http-only-flag to false.
1429
1445
1430
- 12 . If the cookie was received from a "non-HTTP" API and the cookie's
1446
+ 13 . If the cookie was received from a "non-HTTP" API and the cookie's
1431
1447
http-only-flag is true, abort these steps and ignore the cookie entirely.
1432
1448
1433
- 13 . If the cookie's secure-only-flag is false, and the scheme component of
1449
+ 14 . If the cookie's secure-only-flag is false, and the scheme component of
1434
1450
request-uri does not denote a "secure" protocol, then abort these steps and
1435
1451
ignore the cookie entirely if the cookie store contains one or more cookies
1436
1452
that meet all of the following criteria :
@@ -1452,13 +1468,13 @@ user agent MUST process the cookie as follows:
1452
1468
non-secure cookie named 'a' could be set for a path of '/' or '/foo', but
1453
1469
not for a path of '/login' or '/login/en'.
1454
1470
1455
- 14 . If the cookie-attribute-list contains an attribute with an
1471
+ 15 . If the cookie-attribute-list contains an attribute with an
1456
1472
attribute-name of "SameSite", and an attribute-value of "Strict", "Lax", or
1457
1473
" None" , set the cookie's same-site-flag to the attribute-value of the last
1458
1474
attribute in the cookie-attribute-list with an attribute-name of "SameSite".
1459
1475
Otherwise, set the cookie's same-site-flag to "Default".
1460
1476
1461
- 15 . If the cookie's `same-site-flag` is not "None" :
1477
+ 16 . If the cookie's `same-site-flag` is not "None" :
1462
1478
1463
1479
1. If the cookie was received from a "non-HTTP" API, and the API was called
1464
1480
from a browsing context's active document whose "site for cookies" is
@@ -1481,14 +1497,14 @@ user agent MUST process the cookie as follows:
1481
1497
1482
1498
4. Abort these steps and ignore the newly created cookie entirely.
1483
1499
1484
- 16 . If the cookie's "same-site-flag" is "None", abort these steps and ignore the
1500
+ 17 . If the cookie's "same-site-flag" is "None", abort these steps and ignore the
1485
1501
cookie entirely unless the cookie's secure-only-flag is true.
1486
1502
1487
- 17 . If the cookie-name begins with a case-sensitive match for the string
1503
+ 18 . If the cookie-name begins with a case-sensitive match for the string
1488
1504
" __Secure-" , abort these steps and ignore the cookie entirely unless the
1489
1505
cookie's secure-only-flag is true.
1490
1506
1491
- 18 . If the cookie-name begins with a case-sensitive match for the string
1507
+ 19 . If the cookie-name begins with a case-sensitive match for the string
1492
1508
" __Host-" , abort these steps and ignore the cookie entirely unless the
1493
1509
cookie meets all the following criteria :
1494
1510
@@ -1499,7 +1515,7 @@ user agent MUST process the cookie as follows:
1499
1515
3. The cookie-attribute-list contains an attribute with an attribute-name
1500
1516
of "Path", and the cookie's path is `/`.
1501
1517
1502
- 19 . If the cookie store contains a cookie with the same name, domain,
1518
+ 20 . If the cookie store contains a cookie with the same name, domain,
1503
1519
host-only-flag, and path as the newly-created cookie :
1504
1520
1505
1521
1. Let old-cookie be the existing cookie with the same name, domain,
@@ -1516,7 +1532,7 @@ user agent MUST process the cookie as follows:
1516
1532
1517
1533
4. Remove the old-cookie from the cookie store.
1518
1534
1519
- 20 . Insert the newly-created cookie into the cookie store.
1535
+ 21 . Insert the newly-created cookie into the cookie store.
1520
1536
1521
1537
A cookie is "expired" if the cookie has an expiry date in the past.
1522
1538
@@ -2244,6 +2260,9 @@ The "Cookie Attribute Registry" will be updated with the registrations below:
2244
2260
* Align on using HTML terminology for origins:
2245
2261
<https://github.com/httpwg/http-extensions/pull/1416>
2246
2262
2263
+ * Modify cookie parsing and creation algorithms in {{set-cookie}} and
2264
+ {{storage-model}} to explicitly handle control characters:
2265
+ <https://github.com/httpwg/http-extensions/pull/1420>
2247
2266
2248
2267
# Acknowledgements
2249
2268
{:numbered="false"}
0 commit comments