parent
b90010670f
commit
7288a35585
@ -0,0 +1,39 @@
|
||||
From 24603488c43a7cbaffcff7e69a72ad9bb4604acf Mon Sep 17 00:00:00 2001
|
||||
From: Lumir Balhar <lbalhar@redhat.com>
|
||||
Date: Thu, 12 Oct 2023 14:08:31 +0200
|
||||
Subject: [PATCH] CVE-2023-43804
|
||||
|
||||
---
|
||||
src/urllib3/util/retry.py | 2 +-
|
||||
test/test_retry.py | 2 +-
|
||||
2 files changed, 2 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/urllib3/util/retry.py b/src/urllib3/util/retry.py
|
||||
index 02429ee..c4a687c 100644
|
||||
--- a/src/urllib3/util/retry.py
|
||||
+++ b/src/urllib3/util/retry.py
|
||||
@@ -151,7 +151,7 @@ class Retry(object):
|
||||
|
||||
RETRY_AFTER_STATUS_CODES = frozenset([413, 429, 503])
|
||||
|
||||
- DEFAULT_REDIRECT_HEADERS_BLACKLIST = frozenset(['Authorization'])
|
||||
+ DEFAULT_REDIRECT_HEADERS_BLACKLIST = frozenset(['Cookie', 'Authorization'])
|
||||
|
||||
#: Maximum backoff time.
|
||||
BACKOFF_MAX = 120
|
||||
diff --git a/test/test_retry.py b/test/test_retry.py
|
||||
index 7546c43..b6d52bf 100644
|
||||
--- a/test/test_retry.py
|
||||
+++ b/test/test_retry.py
|
||||
@@ -253,7 +253,7 @@ class TestRetry(object):
|
||||
def test_retry_default_remove_headers_on_redirect(self):
|
||||
retry = Retry()
|
||||
|
||||
- assert list(retry.remove_headers_on_redirect) == ['authorization']
|
||||
+ assert retry.remove_headers_on_redirect == {'authorization', 'cookie'}
|
||||
|
||||
def test_retry_set_remove_headers_on_redirect(self):
|
||||
retry = Retry(remove_headers_on_redirect=['x-api-secret'])
|
||||
--
|
||||
2.41.0
|
||||
|
@ -0,0 +1,94 @@
|
||||
From 6f6011442b255b6c135c294500cf4d404f594d8a Mon Sep 17 00:00:00 2001
|
||||
From: Lumir Balhar <lbalhar@redhat.com>
|
||||
Date: Tue, 12 Dec 2023 10:21:34 +0100
|
||||
Subject: [PATCH] Security fix for CVE-2023-45803
|
||||
|
||||
---
|
||||
src/urllib3/_collections.py | 18 ++++++++++++++++++
|
||||
src/urllib3/connectionpool.py | 5 +++++
|
||||
src/urllib3/poolmanager.py | 7 +++++--
|
||||
3 files changed, 28 insertions(+), 2 deletions(-)
|
||||
|
||||
diff --git a/src/urllib3/_collections.py b/src/urllib3/_collections.py
|
||||
index 34f2381..86fc900 100644
|
||||
--- a/src/urllib3/_collections.py
|
||||
+++ b/src/urllib3/_collections.py
|
||||
@@ -260,6 +260,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/urllib3/connectionpool.py b/src/urllib3/connectionpool.py
|
||||
index f7a8f19..ad6303c 100644
|
||||
--- a/src/urllib3/connectionpool.py
|
||||
+++ b/src/urllib3/connectionpool.py
|
||||
@@ -32,6 +32,7 @@ from .connection import (
|
||||
HTTPConnection, HTTPSConnection, VerifiedHTTPSConnection,
|
||||
HTTPException, BaseSSLError,
|
||||
)
|
||||
+from ._collections import HTTPHeaderDict
|
||||
from .request import RequestMethods
|
||||
from .response import HTTPResponse
|
||||
|
||||
@@ -679,7 +680,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/urllib3/poolmanager.py b/src/urllib3/poolmanager.py
|
||||
index 32bd973..37557f9 100644
|
||||
--- a/src/urllib3/poolmanager.py
|
||||
+++ b/src/urllib3/poolmanager.py
|
||||
@@ -3,7 +3,7 @@ import collections
|
||||
import functools
|
||||
import logging
|
||||
|
||||
-from ._collections import RecentlyUsedContainer
|
||||
+from ._collections import HTTPHeaderDict, RecentlyUsedContainer
|
||||
from .connectionpool import HTTPConnectionPool, HTTPSConnectionPool
|
||||
from .connectionpool import port_by_scheme
|
||||
from .exceptions import LocationValueError, MaxRetryError, ProxySchemeUnknown
|
||||
@@ -330,9 +330,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):
|
||||
--
|
||||
2.43.0
|
||||
|
Loading…
Reference in new issue