Skip to content

Commit d5d068c

Browse files
authored
parse cookie expires date as ascii-only (aio-libs#13278)
1 parent 58bae08 commit d5d068c

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

CHANGES/13278.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Restricted cookie ``Expires`` date parsing to ASCII digits -- by :user:`dxbjavid`.

aiohttp/cookiejar.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@
4444
class CookieJar(AbstractCookieJar):
4545
"""Implements cookie storage adhering to RFC 6265."""
4646

47+
# https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.1
4748
DATE_TOKENS_RE = re.compile(
4849
r"[\x09\x20-\x2F\x3B-\x40\x5B-\x60\x7B-\x7E]*"
49-
r"(?P<token>[\x00-\x08\x0A-\x1F\d:a-zA-Z\x7F-\xFF]+)"
50+
r"(?P<token>[\x00-\x08\x0A-\x1F\d:a-zA-Z\x7F-\xFF]+)",
51+
re.ASCII,
5052
)
5153

52-
DATE_HMS_TIME_RE = re.compile(r"(\d{1,2}):(\d{1,2}):(\d{1,2})")
54+
DATE_HMS_TIME_RE = re.compile(r"(\d{1,2}):(\d{1,2}):(\d{1,2})", re.ASCII)
5355

54-
DATE_DAY_OF_MONTH_RE = re.compile(r"(\d{1,2})")
56+
DATE_DAY_OF_MONTH_RE = re.compile(r"(\d{1,2})", re.ASCII)
5557

5658
DATE_MONTH_RE = re.compile(
5759
"(jan)|(feb)|(mar)|(apr)|(may)|(jun)|(jul)|(aug)|(sep)|(oct)|(nov)|(dec)",
58-
re.I,
60+
re.I | re.ASCII,
5961
)
6062

61-
DATE_YEAR_RE = re.compile(r"(\d{2,4})")
63+
DATE_YEAR_RE = re.compile(r"(\d{2,4})", re.ASCII)
6264

6365
# calendar.timegm() fails for timestamps after datetime.datetime.max
6466
# Minus one as a loss of precision occurs when timestamp() is called.

tests/test_cookiejar.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ def test_date_parsing() -> None:
141141
# Invalid time
142142
assert parse_func("Tue, 1 Jan 1970 77:88:99 GMT") is None
143143

144+
# Invalid digits
145+
# https://datatracker.ietf.org/doc/html/rfc6265#section-5.1.1
146+
assert parse_func("Tue, ١ Jan ١٩٧٠ ٠٠:٠٠:٠٠ GMT") is None
147+
assert parse_func("Tue, 1 Jan 1970 00:00:00 GMT") is None
148+
assert parse_func("Tue, 1 Jan 1970 ٠٠:٠٠:٠٠ GMT") is None
149+
144150

145151
def test_domain_matching() -> None:
146152
test_func = CookieJar._is_domain_match

0 commit comments

Comments
 (0)