|
| 1 | +From b594c5ceaca38e1ac215f916538fb128e3526a36 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Illia Volochii < [email protected]> |
| 3 | +Date: Tue, 17 Oct 2023 19:35:39 +0300 |
| 4 | +Subject: [PATCH] Merge pull request from GHSA-g4mx-q9vg-27p4 |
| 5 | +Upstream Patch Reference: https://github.com/urllib3/urllib3/commit/b594c5ceaca38e1ac215f916538fb128e3526a36.patch |
| 6 | +--- |
| 7 | + pip/_vendor/urllib3/_collections.py | 18 ++++++++++++++++++ |
| 8 | + pip/_vendor/urllib3/connectionpool.py | 5 +++++ |
| 9 | + pip/_vendor/urllib3/poolmanager.py | 6 +++++- |
| 10 | + 3 files changed, 28 insertions(+), 1 deletion(-) |
| 11 | + |
| 12 | +diff --git a/pip/_vendor/urllib3/_collections.py b/pip/_vendor/urllib3/_collections.py |
| 13 | +index da9857e..bceb845 100644 |
| 14 | +--- a/pip/_vendor/urllib3/_collections.py |
| 15 | ++++ b/pip/_vendor/urllib3/_collections.py |
| 16 | +@@ -268,6 +268,24 @@ class HTTPHeaderDict(MutableMapping): |
| 17 | + else: |
| 18 | + return vals[1:] |
| 19 | + |
| 20 | ++ def _prepare_for_method_change(self): |
| 21 | ++ """ |
| 22 | ++ Remove content-specific header fields before changing the request |
| 23 | ++ method to GET or HEAD according to RFC 9110, Section 15.4. |
| 24 | ++ """ |
| 25 | ++ content_specific_headers = [ |
| 26 | ++ "Content-Encoding", |
| 27 | ++ "Content-Language", |
| 28 | ++ "Content-Location", |
| 29 | ++ "Content-Type", |
| 30 | ++ "Content-Length", |
| 31 | ++ "Digest", |
| 32 | ++ "Last-Modified", |
| 33 | ++ ] |
| 34 | ++ for header in content_specific_headers: |
| 35 | ++ self.discard(header) |
| 36 | ++ return self |
| 37 | ++ |
| 38 | + # Backwards compatibility for httplib |
| 39 | + getheaders = getlist |
| 40 | + getallmatchingheaders = getlist |
| 41 | +diff --git a/pip/_vendor/urllib3/connectionpool.py b/pip/_vendor/urllib3/connectionpool.py |
| 42 | +index 7087392..d954e4b 100644 |
| 43 | +--- a/pip/_vendor/urllib3/connectionpool.py |
| 44 | ++++ b/pip/_vendor/urllib3/connectionpool.py |
| 45 | +@@ -9,6 +9,7 @@ import warnings |
| 46 | + from socket import error as SocketError |
| 47 | + from socket import timeout as SocketTimeout |
| 48 | + |
| 49 | ++from ._collections import HTTPHeaderDict |
| 50 | + from .connection import ( |
| 51 | + BaseSSLError, |
| 52 | + BrokenPipeError, |
| 53 | +@@ -832,7 +833,11 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods): |
| 54 | + redirect_location = redirect and response.get_redirect_location() |
| 55 | + if redirect_location: |
| 56 | + if response.status == 303: |
| 57 | ++ # Change the method according to RFC 9110, Section 15.4.4. |
| 58 | + method = "GET" |
| 59 | ++ # And lose the body not to transfer anything sensitive. |
| 60 | ++ body = None |
| 61 | ++ headers = HTTPHeaderDict(headers)._prepare_for_method_change() |
| 62 | + |
| 63 | + try: |
| 64 | + retries = retries.increment(method, url, response=response, _pool=self) |
| 65 | +diff --git a/pip/_vendor/urllib3/poolmanager.py b/pip/_vendor/urllib3/poolmanager.py |
| 66 | +index 0e56754..3da5074 100644 |
| 67 | +--- a/pip/_vendor/urllib3/poolmanager.py |
| 68 | ++++ b/pip/_vendor/urllib3/poolmanager.py |
| 69 | +@@ -4,7 +4,7 @@ import collections |
| 70 | + import functools |
| 71 | + import logging |
| 72 | + |
| 73 | +-from ._collections import RecentlyUsedContainer |
| 74 | ++from ._collections import HTTPHeaderDict, RecentlyUsedContainer |
| 75 | + from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool, port_by_scheme |
| 76 | + from .exceptions import ( |
| 77 | + LocationValueError, |
| 78 | +@@ -400,7 +400,11 @@ class PoolManager(RequestMethods): |
| 79 | + |
| 80 | + # RFC 7231, Section 6.4.4 |
| 81 | + if response.status == 303: |
| 82 | ++ # Change the method according to RFC 9110, Section 15.4.4. |
| 83 | + method = "GET" |
| 84 | ++ # And lose the body not to transfer anything sensitive. |
| 85 | ++ kw["body"] = None |
| 86 | ++ kw["headers"] = HTTPHeaderDict(kw["headers"])._prepare_for_method_change() |
| 87 | + |
| 88 | + retries = kw.get("retries", response.retries) |
| 89 | + if not isinstance(retries, Retry): |
| 90 | +-- |
| 91 | +2.34.1 |
| 92 | + |
0 commit comments