Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/http/cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@ def __parse_string(self, str, patt=_CookiePattern):
else:
parsed_items.append((TYPE_ATTRIBUTE, key, _unquote(value)))
elif value is not None:
if not _is_legal_key(key):
raise CookieError('Illegal key %r' % (key,))
parsed_items.append((TYPE_KEYVALUE, key, self.value_decode(value)))
morsel_seen = True
else:
Expand Down
6 changes: 6 additions & 0 deletions Lib/test/test_http_cookies.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,12 @@ def test_illegal_chars(self):
with self.assertRaises(cookies.CookieError):
C.load(rawdata)

def test_illegal_key_no_partial_state(self):
C = cookies.SimpleCookie()
with self.assertRaises(cookies.CookieError):
C.load("a=1; b,c=2; d=3")
self.assertEqual(len(C), 0)

def test_comment_quoting(self):
c = cookies.SimpleCookie()
c['foo'] = '\N{COPYRIGHT SIGN}'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Validate cookie key characters during parsing in
:meth:`http.cookies.BaseCookie.load` so that an illegal key raises
:exc:`~http.cookies.CookieError` before any cookies are applied. Patch by
tonghuaroot.
Loading