Skip to content

Commit

Permalink
Process "evil" JSON cookies which contain double quotes
Browse files Browse the repository at this point in the history
Note that such cookies are in violation of RFC 2965 / 2616.

Fixes LP #563229 on this branch.
  • Loading branch information
tseaver committed Apr 16, 2010
1 parent f2640dc commit 06a2a77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Zope Changes

Bugs Fixed

- Process "evil" JSON cookies which contain double quotes in violation
of RFC 2965 / 2616. https://bugs.launchpad.net/zope2/+bug/563229

- Ensure that Acquistion wrapper classes always have a ``__getnewargs__``
method, even if it is not provided by the underlying ExtensionClass.

Expand Down
3 changes: 2 additions & 1 deletion lib/python/ZPublisher/HTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ def parse_cookie(text,
qparmre=re.compile(
'([\x00- ]*([^\x00- ;,="]+)="([^"]*)"([\x00- ]*[;,])?[\x00- ]*)'),
parmre=re.compile(
'([\x00- ]*([^\x00- ;,="]+)=([^;,"]*)([\x00- ]*[;,])?[\x00- ]*)'),
'([\x00- ]*([^\x00- ;,="]+)=([^;]*)([\x00- ]*[;,])?[\x00- ]*)'),
paramlessre=re.compile(
'([\x00- ]*([^\x00- ;,="]+)[\x00- ]*[;,][\x00- ]*)'),

Expand All @@ -1534,6 +1534,7 @@ def parse_cookie(text,

else:
# Match evil MSIE cookies ;)
# as well as json

mo_p = parmre.match(text)

Expand Down
14 changes: 14 additions & 0 deletions lib/python/ZPublisher/tests/testHTTPRequest.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,20 @@ def testCookieParsing(self):
self.assertEquals(req.cookies['multi2'],
'cookie data with unquoted spaces')

def test_parses_json_cookies(self):
# https://bugs.launchpad.net/zope2/+bug/563229
# reports cookies in the wild with embedded double quotes (e.g,
# JSON-encoded data structures.
env = {'SERVER_NAME': 'testingharnas',
'SERVER_PORT': '80',
'HTTP_COOKIE': 'json={"intkey":123,"stringkey":"blah"}; '
'anothercookie=boring; baz'
}
req = self._getHTTPRequest(env)
self.assertEquals(req.cookies['json'],
'{"intkey":123,"stringkey":"blah"}')
self.assertEquals(req.cookies['anothercookie'], 'boring')

TEST_ENVIRON = {
'CONTENT_TYPE': 'multipart/form-data; boundary=12345',
'REQUEST_METHOD': 'POST',
Expand Down

0 comments on commit 06a2a77

Please sign in to comment.