diff options
author | Richard van der Hoff <richard@matrix.org> | 2017-11-10 09:15:39 +0000 |
---|---|---|
committer | Richard van der Hoff <richard@matrix.org> | 2017-11-10 09:15:39 +0000 |
commit | f90649eb2b0988c771fa329ba7a0a5ba81fe2396 (patch) | |
tree | 363a7733c8ac9fde637b754c75eca6874ea003d8 /synapse/http/servlet.py | |
parent | Merge pull request #2659 from matrix-org/rav/apparently_we_dont_follow_our_ow... (diff) | |
download | synapse-f90649eb2b0988c771fa329ba7a0a5ba81fe2396.tar.xz |
Fix 500 on invalid utf-8 in request
If somebody sends us a request where the the body is invalid utf-8, we should return a 400 rather than a 500. (json.loads throws a UnicodeError in this situation) We might as well catch all Exceptions here: it seems very unlikely that we would get a request that *isn't caused by invalid json.
Diffstat (limited to 'synapse/http/servlet.py')
-rw-r--r-- | synapse/http/servlet.py | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/synapse/http/servlet.py b/synapse/http/servlet.py index 8118ee7cc2..71420e54db 100644 --- a/synapse/http/servlet.py +++ b/synapse/http/servlet.py @@ -167,7 +167,8 @@ def parse_json_value_from_request(request): try: content = simplejson.loads(content_bytes) - except simplejson.JSONDecodeError: + except Exception as e: + logger.warn("Unable to parse JSON: %s", e) raise SynapseError(400, "Content not JSON.", errcode=Codes.NOT_JSON) return content |