Improve target url validation

In addition to checking for scheme='http', we should also check that
netloc has a value. There are many meaningless URLs that pass the
current check. For instance:

```
In [5]: urlparse("http://")
Out[5]: ParseResult(scheme='http', netloc='', path='', params='',
query='', fragment='')

In [6]: urlparse("http:///")
Out[6]: ParseResult(scheme='http', netloc='', path='/', params='',
query='', fragment='')
```

netloc should always have a value.
This commit is contained in:
Vangelis Banos 2019-05-06 21:23:10 +00:00
parent 38d6e4337d
commit 16489b99d9

View File

@ -233,7 +233,7 @@ class MitmProxyHandler(http_server.BaseHTTPRequestHandler):
else:
self.url = self.path
u = urllib_parse.urlparse(self.url)
if u.scheme != 'http':
if u.scheme != 'http' or u.netloc == '':
raise Exception(
'unable to parse request %r as a proxy request' % (
self.requestline))