Annotation of pkgsrc/lang/python27/patches/patch-Lib_httplib.py, revision 1.1
1.1 ! mgorny 1: $NetBSD$
! 2:
! 3: --- Lib/httplib.py.orig 2020-04-19 21:13:39.000000000 +0000
! 4: +++ Lib/httplib.py
! 5: @@ -257,6 +257,10 @@ _contains_disallowed_url_pchar_re = re.c
! 6: # _is_allowed_url_pchars_re = re.compile(r"^[/!$&'()*+,;=:@%a-zA-Z0-9._~-]+$")
! 7: # We are more lenient for assumed real world compatibility purposes.
! 8:
! 9: +# These characters are not allowed within HTTP method names
! 10: +# to prevent http header injection.
! 11: +_contains_disallowed_method_pchar_re = re.compile('[\x00-\x1f]')
! 12: +
! 13: # We always set the Content-Length header for these methods because some
! 14: # servers will otherwise respond with a 411
! 15: _METHODS_EXPECTING_BODY = {'PATCH', 'POST', 'PUT'}
! 16: @@ -935,6 +939,8 @@ class HTTPConnection:
! 17: else:
! 18: raise CannotSendRequest()
! 19:
! 20: + self._validate_method(method)
! 21: +
! 22: # Save the method for use later in the response phase
! 23: self._method = method
! 24:
! 25: @@ -1020,6 +1026,17 @@ class HTTPConnection:
! 26: # On Python 2, request is already encoded (default)
! 27: return request
! 28:
! 29: + def _validate_method(self, method):
! 30: + """Validate a method name for putrequest."""
! 31: + # prevent http header injection
! 32: + match = _contains_disallowed_method_pchar_re.search(method)
! 33: + if match:
! 34: + msg = (
! 35: + "method can't contain control characters. {method!r} "
! 36: + "(found at least {matched!r})"
! 37: + ).format(matched=match.group(), method=method)
! 38: + raise ValueError(msg)
! 39: +
! 40: def _validate_path(self, url):
! 41: """Validate a url for putrequest."""
! 42: # Prevent CVE-2019-9740.
CVSweb <webmaster@jp.NetBSD.org>