Skip to content

Commit f02b5ff

Browse files
authored
RFC 6265bis: Specify handling of CTL characters in set-cookie-string (#1420)
Addresses #1399
1 parent 743ca92 commit f02b5ff

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

draft-ietf-httpbis-rfc6265bis.md

+44-25
Original file line numberDiff line numberDiff line change
@@ -1098,14 +1098,27 @@ set-cookie-string (defined below).
10981098
NOTE: The algorithm below is more permissive than the grammar in {{sane-set-cookie}}.
10991099
For example, the algorithm strips leading and trailing whitespace from the
11001100
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.
11041110

11051111
A user agent MUST use an algorithm equivalent to the following algorithm to
11061112
parse a set-cookie-string:
11071113

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:
11091122

11101123
1. The name-value-pair string consists of the characters up to, but not
11111124
including, the first %x3B (";"), and the unparsed-attributes consist of
@@ -1118,17 +1131,17 @@ parse a set-cookie-string:
11181131
the set-cookie-string, and the unparsed-attributes is the empty
11191132
string.
11201133

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
11221135
string is empty, and the value string is the value of name-value-pair.
11231136

11241137
Otherwise, the name string consists of the characters up to, but not
11251138
including, the first %x3D ("=") character, and the (possibly empty) value
11261139
string consists of the characters after the first %x3D ("=") character.
11271140

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
11291142
value string.
11301143

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.
11321145

11331146
The user agent MUST use an algorithm equivalent to the following algorithm to
11341147
parse the unparsed-attributes:
@@ -1336,10 +1349,13 @@ user agent MUST process the cookie as follows:
13361349
2. If cookie-name is empty and cookie-value is empty, abort these steps and
13371350
ignore the cookie entirely.
13381351

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
13401356
creation-time and the last-access-time to the current date and time.
13411357

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
13431359
of "Max-Age":
13441360

13451361
1. Set the cookie's persistent-flag to true.
@@ -1364,7 +1380,7 @@ user agent MUST process the cookie as follows:
13641380

13651381
2. Set the cookie's expiry-time to the latest representable date.
13661382

1367-
5. If the cookie-attribute-list contains an attribute with an
1383+
6. If the cookie-attribute-list contains an attribute with an
13681384
attribute-name of "Domain":
13691385

13701386
1. Let the domain-attribute be the attribute-value of the last
@@ -1375,7 +1391,7 @@ user agent MUST process the cookie as follows:
13751391

13761392
1. Let the domain-attribute be the empty string.
13771393

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
13791395
domain-attribute is a public suffix:
13801396

13811397
1. If the domain-attribute is identical to the canonicalized
@@ -1390,7 +1406,7 @@ user agent MUST process the cookie as follows:
13901406
NOTE: This step prevents `attacker.example` from disrupting the integrity of
13911407
`site.example` by setting a cookie with a Domain attribute of "example".
13921408

1393-
7. If the domain-attribute is non-empty:
1409+
8. If the domain-attribute is non-empty:
13941410

13951411
1. If the canonicalized request-host does not domain-match the
13961412
domain-attribute:
@@ -1409,28 +1425,28 @@ user agent MUST process the cookie as follows:
14091425

14101426
2. Set the cookie's domain to the canonicalized request-host.
14111427

1412-
8. If the cookie-attribute-list contains an attribute with an
1428+
9. If the cookie-attribute-list contains an attribute with an
14131429
attribute-name of "Path", set the cookie's path to attribute-value of
14141430
the last attribute in the cookie-attribute-list with an attribute-name
14151431
of "Path". Otherwise, set the cookie's path to the default-path of the
14161432
request-uri.
14171433

1418-
9. If the cookie-attribute-list contains an attribute with an
1434+
10. If the cookie-attribute-list contains an attribute with an
14191435
attribute-name of "Secure", set the cookie's secure-only-flag to true.
14201436
Otherwise, set the cookie's secure-only-flag to false.
14211437

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"
14231439
protocol (as defined by the user agent), and the cookie's secure-only-flag
14241440
is true, then abort these steps and ignore the cookie entirely.
14251441

1426-
11. If the cookie-attribute-list contains an attribute with an
1442+
12. If the cookie-attribute-list contains an attribute with an
14271443
attribute-name of "HttpOnly", set the cookie's http-only-flag to true.
14281444
Otherwise, set the cookie's http-only-flag to false.
14291445

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
14311447
http-only-flag is true, abort these steps and ignore the cookie entirely.
14321448

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
14341450
request-uri does not denote a "secure" protocol, then abort these steps and
14351451
ignore the cookie entirely if the cookie store contains one or more cookies
14361452
that meet all of the following criteria:
@@ -1452,13 +1468,13 @@ user agent MUST process the cookie as follows:
14521468
non-secure cookie named 'a' could be set for a path of '/' or '/foo', but
14531469
not for a path of '/login' or '/login/en'.
14541470

1455-
14. If the cookie-attribute-list contains an attribute with an
1471+
15. If the cookie-attribute-list contains an attribute with an
14561472
attribute-name of "SameSite", and an attribute-value of "Strict", "Lax", or
14571473
"None", set the cookie's same-site-flag to the attribute-value of the last
14581474
attribute in the cookie-attribute-list with an attribute-name of "SameSite".
14591475
Otherwise, set the cookie's same-site-flag to "Default".
14601476

1461-
15. If the cookie's `same-site-flag` is not "None":
1477+
16. If the cookie's `same-site-flag` is not "None":
14621478

14631479
1. If the cookie was received from a "non-HTTP" API, and the API was called
14641480
from a browsing context's active document whose "site for cookies" is
@@ -1481,14 +1497,14 @@ user agent MUST process the cookie as follows:
14811497

14821498
4. Abort these steps and ignore the newly created cookie entirely.
14831499

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
14851501
cookie entirely unless the cookie's secure-only-flag is true.
14861502

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
14881504
"__Secure-", abort these steps and ignore the cookie entirely unless the
14891505
cookie's secure-only-flag is true.
14901506

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
14921508
"__Host-", abort these steps and ignore the cookie entirely unless the
14931509
cookie meets all the following criteria:
14941510

@@ -1499,7 +1515,7 @@ user agent MUST process the cookie as follows:
14991515
3. The cookie-attribute-list contains an attribute with an attribute-name
15001516
of "Path", and the cookie's path is `/`.
15011517

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,
15031519
host-only-flag, and path as the newly-created cookie:
15041520

15051521
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:
15161532

15171533
4. Remove the old-cookie from the cookie store.
15181534

1519-
20. Insert the newly-created cookie into the cookie store.
1535+
21. Insert the newly-created cookie into the cookie store.
15201536

15211537
A cookie is "expired" if the cookie has an expiry date in the past.
15221538

@@ -2244,6 +2260,9 @@ The "Cookie Attribute Registry" will be updated with the registrations below:
22442260
* Align on using HTML terminology for origins:
22452261
<https://github.com/httpwg/http-extensions/pull/1416>
22462262

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>
22472266

22482267
# Acknowledgements
22492268
{:numbered="false"}

0 commit comments

Comments
 (0)