|
|
761e7f |
From b40eb0f43daecc6e2e3ce47b0be49cf570d02adc Mon Sep 17 00:00:00 2001
|
|
|
761e7f |
From: Lumir Balhar <lbalhar@redhat.com>
|
|
|
761e7f |
Date: Thu, 9 Jan 2020 11:14:58 +0100
|
|
|
761e7f |
Subject: [PATCH] CVE-2019-9740
|
|
|
761e7f |
|
|
|
761e7f |
---
|
|
|
761e7f |
util/url.py | 7 +++++++
|
|
|
761e7f |
1 file changed, 7 insertions(+)
|
|
|
761e7f |
|
|
|
761e7f |
diff --git a/util/url.py b/util/url.py
|
|
|
761e7f |
index 6b6f996..2784c85 100644
|
|
|
761e7f |
--- a/util/url.py
|
|
|
761e7f |
+++ b/util/url.py
|
|
|
761e7f |
@@ -1,5 +1,6 @@
|
|
|
761e7f |
from __future__ import absolute_import
|
|
|
761e7f |
from collections import namedtuple
|
|
|
761e7f |
+import re
|
|
|
761e7f |
|
|
|
761e7f |
from ..exceptions import LocationParseError
|
|
|
761e7f |
|
|
|
761e7f |
@@ -10,6 +11,8 @@ url_attrs = ['scheme', 'auth', 'host', 'port', 'path', 'query', 'fragment']
|
|
|
761e7f |
# urllib3 infers URLs without a scheme (None) to be http.
|
|
|
761e7f |
NORMALIZABLE_SCHEMES = ('http', 'https', None)
|
|
|
761e7f |
|
|
|
761e7f |
+_contains_disallowed_url_pchar_re = re.compile('[\x00-\x20\x7f]')
|
|
|
761e7f |
+from ..packages.six.moves.urllib.parse import quote
|
|
|
761e7f |
|
|
|
761e7f |
class Url(namedtuple('Url', url_attrs)):
|
|
|
761e7f |
"""
|
|
|
761e7f |
@@ -155,6 +158,10 @@ def parse_url(url):
|
|
|
761e7f |
# Empty
|
|
|
761e7f |
return Url()
|
|
|
761e7f |
|
|
|
761e7f |
+ # Prevent CVE-2019-9740.
|
|
|
761e7f |
+ # adapted from https://github.com/python/cpython/pull/12755
|
|
|
761e7f |
+ url = _contains_disallowed_url_pchar_re.sub(lambda match: quote(match.group()), url)
|
|
|
761e7f |
+
|
|
|
761e7f |
scheme = None
|
|
|
761e7f |
auth = None
|
|
|
761e7f |
host = None
|
|
|
761e7f |
--
|
|
|
761e7f |
2.24.1
|
|
|
761e7f |
|