summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNyiro Gergo <gergo.nyiro@balabit.com>2015-07-22 12:32:16 +0200
committerNyiro Gergo <gergo.nyiro@balabit.com>2015-07-22 12:32:16 +0200
commit4a3ff5dca5225d6ed0c19498ba01012f1b97f535 (patch)
tree7552c1820051134282250dbbfe0445a871a6b90f
parent0411fd7fe7b724e63f0a440a952235d54212fad3 (diff)
downloadcherrypy-4a3ff5dca5225d6ed0c19498ba01012f1b97f535.tar.gz
wsgiserver HTTPRequest read_request_line: check path is not None
The parse_request_uri method handles the uri as authority if it doesn't contain "://" or start with "/". The path will be set to None in this case, but its type was not tested. read_request_line got an extra check for the type of the path.
-rw-r--r--cherrypy/test/test_request_obj.py16
-rw-r--r--cherrypy/wsgiserver/wsgiserver2.py4
-rw-r--r--cherrypy/wsgiserver/wsgiserver3.py4
3 files changed, 22 insertions, 2 deletions
diff --git a/cherrypy/test/test_request_obj.py b/cherrypy/test/test_request_obj.py
index d9989e97..64ac0e26 100644
--- a/cherrypy/test/test_request_obj.py
+++ b/cherrypy/test/test_request_obj.py
@@ -377,15 +377,27 @@ class RequestObjectTests(helper.CPWebCase):
self.getPage(uri)
self.assertStatus(200)
- # query string parameters are part of the URI, so if they are wrong
- # for a particular handler, the status MUST be a 404.
error_msgs = [
'Missing parameters',
'Nothing matches the given URI',
'Multiple values for parameters',
'Unexpected query string parameters',
'Unexpected body parameters',
+ 'No valid path in Request-URI',
+ 'Illegal #fragment in Request-URI',
]
+
+ # uri should be tested for valid absolute path, the status must be 400.
+ for uri, error_idx in (
+ ('invalid/path/without/leading/slash', 5),
+ ('/valid/path#invalid=fragment', 6),
+ ):
+ self.getPage(uri)
+ self.assertStatus(400)
+ self.assertInBody(error_msgs[error_idx])
+
+ # query string parameters are part of the URI, so if they are wrong
+ # for a particular handler, the status MUST be a 404.
for uri, msg in (
('/paramerrors/one_positional', error_msgs[0]),
('/paramerrors/one_positional?foo=foo', error_msgs[0]),
diff --git a/cherrypy/wsgiserver/wsgiserver2.py b/cherrypy/wsgiserver/wsgiserver2.py
index 47ee8081..ff3337bf 100644
--- a/cherrypy/wsgiserver/wsgiserver2.py
+++ b/cherrypy/wsgiserver/wsgiserver2.py
@@ -674,6 +674,10 @@ class HTTPRequest(object):
# uri may be an abs_path (including "http://host.domain.tld");
scheme, authority, path = self.parse_request_uri(uri)
+ if path is None:
+ self.simple_response("400 Bad Request",
+ "No valid path in Request-URI.")
+ return False
if NUMBER_SIGN in path:
self.simple_response("400 Bad Request",
"Illegal #fragment in Request-URI.")
diff --git a/cherrypy/wsgiserver/wsgiserver3.py b/cherrypy/wsgiserver/wsgiserver3.py
index 300e8381..6a6a65e2 100644
--- a/cherrypy/wsgiserver/wsgiserver3.py
+++ b/cherrypy/wsgiserver/wsgiserver3.py
@@ -650,6 +650,10 @@ class HTTPRequest(object):
# uri may be an abs_path (including "http://host.domain.tld");
scheme, authority, path = self.parse_request_uri(uri)
+ if path is None:
+ self.simple_response("400 Bad Request",
+ "No valid path in Request-URI.")
+ return False
if NUMBER_SIGN in path:
self.simple_response("400 Bad Request",
"Illegal #fragment in Request-URI.")