99 lines
3.9 KiB
Diff
99 lines
3.9 KiB
Diff
From b594c5ceaca38e1ac215f916538fb128e3526a36 Mon Sep 17 00:00:00 2001
|
|
From: Illia Volochii <illia.volochii@gmail.com>
|
|
Date: Tue, 17 Oct 2023 19:35:39 +0300
|
|
Subject: [PATCH] Merge pull request from GHSA-g4mx-q9vg-27p4
|
|
|
|
Conflict:Files dummyserver/handlers.py, test/with_dummyserver/test_connectionpool.py
|
|
and test/with_dummyserver/test_poolmanager.py do not exist. Therefore, no dummy server
|
|
and test case is involved.
|
|
Reference:https://github.com/urllib3/urllib3/commit/b594c5ceaca38e1ac215f916538fb128e3526a36
|
|
|
|
---
|
|
src/pip/_vendor/urllib3/_collections.py | 18 ++++++++++++++++++
|
|
src/pip/_vendor/urllib3/connectionpool.py | 6 +++++-
|
|
src/pip/_vendor/urllib3/poolmanager.py | 7 +++++--
|
|
3 files changed, 28 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/src/pip/_vendor/urllib3/_collections.py b/src/pip/_vendor/urllib3/_collections.py
|
|
index 019d151..8b3f0f7 100644
|
|
--- a/src/pip/_vendor/urllib3/_collections.py
|
|
+++ b/src/pip/_vendor/urllib3/_collections.py
|
|
@@ -267,6 +267,24 @@ class HTTPHeaderDict(MutableMapping):
|
|
else:
|
|
return vals[1:]
|
|
|
|
+ def _prepare_for_method_change(self):
|
|
+ """
|
|
+ Remove content-specific header fields before changing the request
|
|
+ method to GET or HEAD according to RFC 9110, Section 15.4.
|
|
+ """
|
|
+ content_specific_headers = [
|
|
+ "Content-Encoding",
|
|
+ "Content-Language",
|
|
+ "Content-Location",
|
|
+ "Content-Type",
|
|
+ "Content-Length",
|
|
+ "Digest",
|
|
+ "Last-Modified",
|
|
+ ]
|
|
+ for header in content_specific_headers:
|
|
+ self.discard(header)
|
|
+ return self
|
|
+
|
|
# Backwards compatibility for httplib
|
|
getheaders = getlist
|
|
getallmatchingheaders = getlist
|
|
diff --git a/src/pip/_vendor/urllib3/connectionpool.py b/src/pip/_vendor/urllib3/connectionpool.py
|
|
index 5f044db..539eb04 100644
|
|
--- a/src/pip/_vendor/urllib3/connectionpool.py
|
|
+++ b/src/pip/_vendor/urllib3/connectionpool.py
|
|
@@ -7,7 +7,7 @@ import warnings
|
|
from socket import error as SocketError, timeout as SocketTimeout
|
|
import socket
|
|
|
|
-
|
|
+from ._collections import HTTPHeaderDict
|
|
from .exceptions import (
|
|
ClosedPoolError,
|
|
ProtocolError,
|
|
@@ -769,7 +769,11 @@ class HTTPConnectionPool(ConnectionPool, RequestMethods):
|
|
redirect_location = redirect and response.get_redirect_location()
|
|
if redirect_location:
|
|
if response.status == 303:
|
|
+ # Change the method according to RFC 9110, Section 15.4.4.
|
|
method = "GET"
|
|
+ # And lose the body not to transfer anything sensitive.
|
|
+ body = None
|
|
+ headers = HTTPHeaderDict(headers)._prepare_for_method_change()
|
|
|
|
try:
|
|
retries = retries.increment(method, url, response=response, _pool=self)
|
|
diff --git a/src/pip/_vendor/urllib3/poolmanager.py b/src/pip/_vendor/urllib3/poolmanager.py
|
|
index e2bd3bd..c30c5e0 100644
|
|
--- a/src/pip/_vendor/urllib3/poolmanager.py
|
|
+++ b/src/pip/_vendor/urllib3/poolmanager.py
|
|
@@ -4,7 +4,7 @@ import functools
|
|
import logging
|
|
import warnings
|
|
|
|
-from ._collections import RecentlyUsedContainer
|
|
+from ._collections import HTTPHeaderDict, RecentlyUsedContainer
|
|
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool
|
|
from .connectionpool import port_by_scheme
|
|
from .exceptions import (
|
|
@@ -342,9 +342,12 @@ class PoolManager(RequestMethods):
|
|
# Support relative URLs for redirecting.
|
|
redirect_location = urljoin(url, redirect_location)
|
|
|
|
- # RFC 7231, Section 6.4.4
|
|
if response.status == 303:
|
|
+ # Change the method according to RFC 9110, Section 15.4.4.
|
|
method = "GET"
|
|
+ # And lose the body not to transfer anything sensitive.
|
|
+ kw["body"] = None
|
|
+ kw["headers"] = HTTPHeaderDict(kw["headers"])._prepare_for_method_change()
|
|
|
|
retries = kw.get("retries")
|
|
if not isinstance(retries, Retry):
|
|
--
|