fix CVE-2023-45803

(cherry picked from commit 7150ab0917cad588478a481aac29fbf84bdb4846)
This commit is contained in:
chengyechun 2023-11-07 09:20:54 +08:00 committed by openeuler-sync-bot
parent 3037c0a6ae
commit 282eb95f89
3 changed files with 139 additions and 3 deletions

View File

@ -0,0 +1,126 @@
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:test/with_dummyserver/test_poolmanager.py and
test_connectionpool.py has not been modified because it has been deleted
in the pre-phase of the spec file
Reference:https://github.com/urllib3/urllib3/commit/b594c5ceaca38e1ac215f916538fb128e3526a36
---
dummyserver/handlers.py | 7 +++++++
src/urllib3/_collections.py | 18 ++++++++++++++++++
src/urllib3/connectionpool.py | 6 +++++-
src/urllib3/poolmanager.py | 7 +++++--
4 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py
index 696dbab..6b501c7 100644
--- a/dummyserver/handlers.py
+++ b/dummyserver/handlers.py
@@ -182,6 +182,8 @@ class TestingApp(RequestHandler):
status = request.params.get("status", "303 See Other")
if len(status) == 3:
status = "%s Redirect" % status.decode("latin-1")
+ elif isinstance(status, bytes):
+ status = status.decode("latin-1")
headers = [("Location", target)]
return Response(status=status, headers=headers)
@@ -260,6 +262,11 @@ class TestingApp(RequestHandler):
def headers(self, request):
return Response(json.dumps(dict(request.headers)))
+ def headers_and_params(self, request):
+ return Response(
+ json.dumps({"headers": dict(requests.headers), "params": request.params})
+ )
+
def successful_retry(self, request):
""" Handler which will return an error and then success
diff --git a/src/urllib3/_collections.py b/src/urllib3/_collections.py
index 019d151..8b3f0f7 100644
--- a/src/urllib3/_collections.py
+++ b/src/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/urllib3/connectionpool.py b/src/urllib3/connectionpool.py
index 174fe6c..40bf7f6 100644
--- a/src/urllib3/connectionpool.py
+++ b/src/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,
@@ -771,7 +771,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 a23ff11..e60197e 100644
--- a/src/urllib3/poolmanager.py
+++ b/src/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 (
@@ -343,9 +343,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.23.0

View File

@ -3,7 +3,7 @@
Name: python-%{srcname}
Version: 1.25.9
Release: 9
Release: 10
Summary: Sanity-friendly HTTP client for Python
License: MIT
URL: https://urllib3.readthedocs.io
@ -19,7 +19,8 @@ Patch6003: backport-add-server_hostname-to-SSL_KEYWORDS.patch
Patch6004: backport-strip-leading-zeros-form-ports.patch
Patch6005: backport-fixed-issue-with-port-0-returning-None.patch
Patch6006: backport-fix-NRESERVED_PAT-and-_idna_encode.patch
Patch6007: CVE-2023-43804.patch
Patch6007: backport-CVE-2023-43804-added-the-Cookie-to-the-list-of-headers.patch
Patch6008: backport-CVE-2023-45803-Made-body-stripped-from-HTTP-requests.patch
%global _description \
HTTP library with thread-safe connection pooling, file post support,\
@ -121,8 +122,17 @@ PYTHONPATH=%{buildroot}%{python3_sitelib}:%{python3_sitelib} %{__python3} -m pyt
%{python3_sitelib}/urllib3-*.egg-info
%changelog
* Mon Nov 06 2023 chengyechun <chengyechun1@huawei.com> - 1.25.9-10
- Type:CVE
- CVE:CVE-2023-45803
- SUG:NA
- DESC:fix CVE-2023-45803
* Wed Oct 04 2023 Funda Wang <fundawang@yeah.net> - 1.25.9-9
- fix CVE-2023-43804
- Type:CVE
- CVE:CVE-2023-43804
- SUG:NA
- DESC:fix CVE-2023-43804
* Sun Apr 23 2023 xzf1244 <xzff@hust.edu.cn> - 1.25.9-8
- Type:bugfix