summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcel Hellkamp <marc@gsites.de>2014-04-25 22:21:58 +0200
committerMarcel Hellkamp <marc@gsites.de>2014-04-29 15:22:04 +0200
commitbfb685b17bddd83dac399dd7d5cf8767aefc1b9f (patch)
tree5d6290672736983c1f2dc227ca0378190f7f626e
parentbaf8079216ad358ebca73beac82ec90cdde534e5 (diff)
downloadbottle-bfb685b17bddd83dac399dd7d5cf8767aefc1b9f.tar.gz
fix #616: Json content-type not restrictive enough
Possible security issue. See https://github.com/defnull/bottle/issues/616 for details.
-rwxr-xr-xbottle.py3
-rwxr-xr-xtest/test_environ.py9
2 files changed, 11 insertions, 1 deletions
diff --git a/bottle.py b/bottle.py
index eb07679..cb52a5f 100755
--- a/bottle.py
+++ b/bottle.py
@@ -985,7 +985,8 @@ class BaseRequest(DictMixin):
property holds the parsed content of the request body. Only requests
smaller than :attr:`MEMFILE_MAX` are processed to avoid memory
exhaustion. '''
- if 'application/json' in self.environ.get('CONTENT_TYPE', '') \
+ ctype = self.environ.get('CONTENT_TYPE', '').lower().split(';')[0]
+ if ctype == 'application/json' \
and 0 < self.content_length < self.MEMFILE_MAX:
return json_loads(self.body.read(self.MEMFILE_MAX))
return None
diff --git a/test/test_environ.py b/test/test_environ.py
index 56bb7a1..e35bcbf 100755
--- a/test/test_environ.py
+++ b/test/test_environ.py
@@ -330,6 +330,15 @@ class TestRequest(unittest.TestCase):
e['CONTENT_LENGTH'] = str(len(json_dumps(test)))
self.assertEqual(BaseRequest(e).json, test)
+ def test_json_forged_header_issue616(self):
+ test = dict(a=5, b='test', c=[1,2,3])
+ e = {'CONTENT_TYPE': 'text/plain;application/json'}
+ wsgiref.util.setup_testing_defaults(e)
+ e['wsgi.input'].write(tob(json_dumps(test)))
+ e['wsgi.input'].seek(0)
+ e['CONTENT_LENGTH'] = str(len(json_dumps(test)))
+ self.assertEqual(BaseRequest(e).json, None)
+
def test_isajax(self):
e = {}
wsgiref.util.setup_testing_defaults(e)