diff options
author | Zach Seils (seils) <seils@cisco.com> | 2018-04-20 15:19:48 -0400 |
---|---|---|
committer | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2018-05-28 19:50:16 +0200 |
commit | 913b189515539f4915db2a3d722d4e2bcab67b3e (patch) | |
tree | 6726446a3f3923c22761a2cd2d1f387dcc739ed2 | |
parent | 967acb7b3cac0f9b60ba6b0430383fa341d8748b (diff) | |
download | cherrypy-git-913b189515539f4915db2a3d722d4e2bcab67b3e.tar.gz |
Fixes #1370
Return for requests with malformed Accept-Charset quality values.
-rw-r--r-- | cherrypy/lib/httputil.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/cherrypy/lib/httputil.py b/cherrypy/lib/httputil.py index 66ba0114..bfc3db3e 100644 --- a/cherrypy/lib/httputil.py +++ b/cherrypy/lib/httputil.py @@ -18,6 +18,7 @@ import six from six.moves import range, builtins from six.moves.BaseHTTPServer import BaseHTTPRequestHandler +import cherrypy from cherrypy._cpcompat import ntob, ntou from cherrypy._cpcompat import text_or_bytes from cherrypy._cpcompat import unquote_qs @@ -202,7 +203,12 @@ class AcceptElement(HeaderElement): val = self.params.get('q', '1') if isinstance(val, HeaderElement): val = val.value - return float(val) + try: + return float(val) + # Fail client requests with invalid quality value + # https://github.com/cherrypy/cherrypy/issues/1370 + except ValueError: + raise cherrypy.HTTPError(400) def __cmp__(self, other): diff = builtins.cmp(self.qvalue, other.qvalue) |