Skip to contentSkip to conversation

python3-urllib3: Fix CVE-2026-97687

PATCH New Yogita Urade 1 participant 1 message Nov 5

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 python3-urllib3: Fix CVE-2026-97687

This patch applies the upstream fix as referenced in [3], using the commit shown in [1] and [2].

[1] https://github.com/urllib3/urllib3/commit/b6447295fff7b38fdffc67e0df9712d60cef3cc3
[2] https://github.com/urllib3/urllib3/commit/07408cec79d1856d81bb42c74a904a24fdb9e465
[3] https://nvd.nist.gov/vuln/detail/CVE-2026-97687

---
 .../python3-urllib3/CVE-2026-97687_p1.patch   | 285 +++++++++++
 .../python3-urllib3/CVE-2026-97687_p2.patch   | 482 ++++++++++++++++++
 .../python/python3-urllib3_2.2.2.bb           |   2 +
 3 files changed, 769 insertions(+)
 create mode 100644 meta/recipes-devtools/python/python3-urllib3/CVE-2026-97687_p1.patch
 create mode 100644 meta/recipes-devtools/python/python3-urllib3/CVE-2026-97687_p2.patch
meta/recipes-devtools/python/python3-urllib3/CVE-2026-97687_p1.patch new file +285 -0
new file mode 100644
index 0000000000..241be4adaa
@@ -0,0 +1,285 @@
+From b6447295fff7b38fdffc67e0df9712d60cef3cc3 Mon Sep 17 00:00:00 2001
+From: Dustin Hoeppner <[email protected]>
+Date: Fri, 12 Jun 2026 08:27:08 -0500
+Subject: [PATCH] Fix `proxy_ssl_context` ignored for HTTPS forwarding proxies
+ (#3786)
+
+Co-authored-by: Illia Volochii <[email protected]>
+
+CVE: CVE-2026-97687
+Upstream-Status: Backport [https://github.com/urllib3/urllib3/commit/b6447295fff7b38fdffc67e0df9712d60cef3cc3]
+
+Backport Changes:
+- Shifted the upstream policy-selection block to the target method's
+  indentation so this intermediate patch applies and compiles.
+
+Signed-off-by: Yogita Urade <[email protected]>
+---
+ changelog/2577.bugfix.rst                     |   2 +
+ src/urllib3/connection.py                     |  16 +-
+ src/urllib3/poolmanager.py                    |  15 ++
+ .../test_proxy_poolmanager.py                 | 149 ++++++++++++++++--
+ 4 files changed, 165 insertions(+), 17 deletions(-)
+ create mode 100644 changelog/2577.bugfix.rst
+
+diff --git a/changelog/2577.bugfix.rst b/changelog/2577.bugfix.rst
+new file mode 100644
+index 0000000..57d7f1f
+--- /dev/null
++++ b/changelog/2577.bugfix.rst
+@@ -0,0 +1,2 @@
++Fixed usage of ``proxy_ssl_context`` with ``ProxyManager`` when ``use_forwarding_for_https=True``.
++Passing ``ssl_context`` instead of ``proxy_ssl_context`` for HTTPS proxies in this configuration now emits a ``FutureWarning`` and will raise an error in v3.0.
+diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py
+index 1b16279..b9760c6 100644
+--- a/src/urllib3/connection.py
++++ b/src/urllib3/connection.py
+@@ -649,6 +649,20 @@ class HTTPSConnection(HTTPConnection):
+         # Remove trailing '.' from fqdn hostnames to allow certificate validation
+         server_hostname_rm_dot = server_hostname.rstrip(".")
+ 
++        # Forwarding proxies should use proxy SSL context for
++        # wrapping since that's the connection being established,
++        # whereas tunneling proxies should use the connection's SSL
++        # context.
++        # However, for backwards compatibility reasons, if the proxy
++        # is forwarding but no proxy SSL context is provided, we
++        # fall back to using the connection's SSL context until
++        # urllib3 v3.0. Appropriate warning is emitted in
++        # ``ProxyManager.__init__``.
++        if self.proxy_is_forwarding and self.proxy_config is not None:
++            ssl_context = self.proxy_config.ssl_context
++        else:
++            ssl_context = self.ssl_context
++
+         sock_and_verified = _ssl_wrap_socket_and_match_hostname(
+             sock=sock,
+             cert_reqs=self.cert_reqs,
+@@ -662,7 +676,7 @@ class HTTPSConnection(HTTPConnection):
+             key_file=self.key_file,
+             key_password=self.key_password,
+             server_hostname=server_hostname_rm_dot,
+-            ssl_context=self.ssl_context,
++            ssl_context=ssl_context,
+             tls_in_tls=tls_in_tls,
+             assert_hostname=self.assert_hostname,
+             assert_fingerprint=self.assert_fingerprint,
+diff --git a/src/urllib3/poolmanager.py b/src/urllib3/poolmanager.py
+index 5763fea..290cfe1 100644
+--- a/src/urllib3/poolmanager.py
++++ b/src/urllib3/poolmanager.py
+@@ -581,6 +581,21 @@ class ProxyManager(PoolManager):
+         if proxy.scheme not in ("http", "https"):
+             raise ProxySchemeUnknown(proxy.scheme)
+ 
++        if (
++            use_forwarding_for_https
++            and proxy.scheme == "https"
++            and connection_pool_kw.get("ssl_context") is not None
++        ):
++            warnings.warn(
++                "Passing ssl_context when use_forwarding_for_https=True is deprecated "
++                "and will raise an error in urllib3 v3.0. "
++                "Use proxy_ssl_context to configure the TLS connection to the proxy.",
++                FutureWarning,
++                stacklevel=2,
++            )
++            if proxy_ssl_context is None:
++                proxy_ssl_context = connection_pool_kw.get("ssl_context")
++
+         if not proxy.port:
+             port = port_by_scheme.get(proxy.scheme, 80)
+             proxy = proxy._replace(port=port)
+diff --git a/test/with_dummyserver/test_proxy_poolmanager.py b/test/with_dummyserver/test_proxy_poolmanager.py
+index a0b1172..f116b41 100644
+--- a/test/with_dummyserver/test_proxy_poolmanager.py
++++ b/test/with_dummyserver/test_proxy_poolmanager.py
+@@ -10,6 +10,7 @@ import shutil
+ import socket
+ import ssl
+ import tempfile
++import typing
+ from test import LONG_TIMEOUT, SHORT_TIMEOUT, resolvesLocalhostFQDN, withPyOpenSSL
+ from test.conftest import ServerConfig
+ 
+@@ -24,7 +25,7 @@ from dummyserver.testcase import (
+ )
+ from urllib3 import HTTPResponse
+ from urllib3._collections import HTTPHeaderDict
+-from urllib3.connection import VerifiedHTTPSConnection
++from urllib3.connection import HTTPSConnection, VerifiedHTTPSConnection
+ from urllib3.connectionpool import connection_from_url
+ from urllib3.exceptions import (
+     ConnectTimeoutError,
+@@ -165,6 +166,43 @@ class TestHTTPProxyManager(HypercornDummyProxyTestCase):
+             r = https.request("GET", f"{self.https_url}/")
+             assert r.status == 200
+ 
++    @requires_network()
++    @pytest.mark.parametrize(
++        "proxy_ssl_context_kw",
++        [
++            ("ssl_context",),
++            ("proxy_ssl_context",),
++            ("ssl_context", "proxy_ssl_context"),
++        ],
++    )
++    def test_https_proxy_forwarding_for_https_with_custom_context(
++        self, proxy_ssl_context_kw: tuple[str, ...]
++    ) -> None:
++        """
++        Test that an HTTP request succeeds when using a forwarding HTTPS
++        proxy with an SSL context provided via either
++        ``proxy_ssl_context``, ``ssl_context`` (fallback), or both.
++        """
++
++        proxy_ctx = ssl.create_default_context()
++        proxy_ctx.load_verify_locations(DEFAULT_CA)
++
++        warning_checker: contextlib.AbstractContextManager[typing.Any]
++        if "ssl_context" in proxy_ssl_context_kw:
++            warning_checker = pytest.warns(FutureWarning, match="ssl_context")
++        else:
++            warning_checker = contextlib.nullcontext()
++        with warning_checker:
++            proxy = proxy_from_url(
++                self.https_proxy_url,
++                **{kw: proxy_ctx for kw in proxy_ssl_context_kw},
++                use_forwarding_for_https=True,
++            )
++
++        with proxy:
++            resp = proxy.request("GET", self.https_url)
++            assert resp.status == 200
++
+     def test_nagle_proxy(self) -> None:
+         """Test that proxy connections do not have TCP_NODELAY turned on"""
+         with ProxyManager(self.proxy_url) as http:
+@@ -708,20 +746,8 @@ class TestHTTPProxyManager(HypercornDummyProxyTestCase):
+     # see https://github.com/python/cpython/issues/103472
+     @pytest.mark.filterwarnings("default::ResourceWarning")
+     @requires_network()
+-    @pytest.mark.parametrize(
+-        ["proxy_scheme", "use_forwarding_for_https"],
+-        [
+-            ("http", False),
+-            ("https", False),
+-            ("https", True),
+-        ],
+-    )
+-    def test_proxy_https_target_tls_error(
+-        self, proxy_scheme: str, use_forwarding_for_https: str
+-    ) -> None:
+-        if proxy_scheme == "https" and use_forwarding_for_https:
+-            pytest.skip("Test is expected to fail due to urllib3/urllib3#2577")
+-
++    @pytest.mark.parametrize("proxy_scheme", ["http", "https"])
++    def test_proxy_https_target_tls_error(self, proxy_scheme: str) -> None:
+         proxy_url = self.https_proxy_url if proxy_scheme == "https" else self.proxy_url
+         proxy_ctx = ssl.create_default_context()
+         proxy_ctx.load_verify_locations(DEFAULT_CA)
+@@ -731,12 +757,103 @@ class TestHTTPProxyManager(HypercornDummyProxyTestCase):
+             proxy_url,
+             proxy_ssl_context=proxy_ctx,
+             ssl_context=ctx,
+-            use_forwarding_for_https=use_forwarding_for_https,
+         ) as proxy:
+             with pytest.raises(MaxRetryError) as e:
+                 proxy.request("GET", self.https_url)
+             assert isinstance(e.value.reason, SSLError)
+ 
++    @requires_network()
++    def test_forwarding_proxy_tls_error_with_fallback(self) -> None:
++        """
++        Test that when only ``ssl_context`` is passed to a forwarding
++        HTTPS proxy, a ``FutureWarning`` is emitted and if the TLS
++        handshake with the proxy fails using that context, the error is
++        a ``ProxyError`` wrapping the original TLS error.
++        """
++        ctx = ssl.create_default_context()
++
++        with pytest.warns(FutureWarning, match="ssl_context"):
++            proxy = proxy_from_url(
++                self.https_proxy_url,
++                ssl_context=ctx,
++                use_forwarding_for_https=True,
++            )
++
++        with proxy:
++            with pytest.raises(MaxRetryError) as e:
++                proxy.request("GET", self.https_url)
++            assert isinstance(e.value.reason, ProxyError)
++            assert isinstance(e.value.reason.original_error, SSLError)
++
++    @requires_network()
++    def test_forwarding_proxy_ssl_context_precedence(self) -> None:
++        """
++        Test that when both ``ssl_context`` and ``proxy_ssl_context``
++        are passed to a forwarding HTTPS proxy, ``proxy_ssl_context`` is
++        used for the proxy connection and ``ssl_context`` is ignored
++        (with a warning).
++        """
++        ssl_context = ssl.create_default_context(cafile=DEFAULT_CA)
++        proxy_ssl_context = ssl.create_default_context(cafile=DEFAULT_CA)
++
++        with pytest.warns(FutureWarning, match="ssl_context"):
++            proxy = proxy_from_url(
++                self.https_proxy_url,
++                proxy_ssl_context=proxy_ssl_context,
++                ssl_context=ssl_context,
++                use_forwarding_for_https=True,
++            )
++
++        with proxy:
++            pool = proxy.connection_from_url(self.https_url)
++            with contextlib.closing(pool._new_conn()) as conn:
++                conn = typing.cast(HTTPSConnection, conn)
++                conn.connect()
++                assert isinstance(conn.sock, ssl.SSLSocket)
++                assert conn.sock.context is proxy_ssl_context
++
++    @requires_network()
++    def test_forwarding_proxy_ssl_context_fallback(self) -> None:
++        """
++        Test that when only ``ssl_context`` is passed to a forwarding
++        HTTPS proxy, a ``FutureWarning`` is emitted and ``ssl_context``
++        is used as the proxy TLS context (fallback).
++        """
++        ssl_context = ssl.create_default_context(cafile=DEFAULT_CA)
++
++        with pytest.warns(FutureWarning, match="ssl_context"):
++            proxy = proxy_from_url(
++                self.https_proxy_url,
++                ssl_context=ssl_context,
++                use_forwarding_for_https=True,
++            )
++
++        with proxy:
++            pool = proxy.connection_from_url(self.https_url)
++            with contextlib.closing(pool._new_conn()) as conn:
++                conn = typing.cast(HTTPSConnection, conn)
++                conn.connect()
++                assert isinstance(conn.sock, ssl.SSLSocket)
++                assert conn.sock.context is ssl_context
++
++    @requires_network()
++    def test_forwarding_non_https_proxy_ssl_context_fallback(self) -> None:
++        """
++        Test that when only ``ssl_context`` is passed to a forwarding
++        non-HTTPS proxy, no warning or error is emitted.
++        """
++        ssl_context = ssl.create_default_context(cafile=DEFAULT_CA)
++        # No warning/error should be emitted even when ``ssl_context``
++        # is provided to a non-HTTPS proxy for some reason.
++        proxy = proxy_from_url(
++            self.proxy_url,
++            ssl_context=ssl_context,
++            use_forwarding_for_https=True,
++        )
++        with proxy:
++            resp = proxy.request("GET", self.https_url)
++            assert resp.status == 200
++
+     # stdlib http.client.HTTPConnection._tunnel() causes a ResourceWarning
+     # see https://github.com/python/cpython/issues/103472
+     @pytest.mark.filterwarnings("default::ResourceWarning")
meta/recipes-devtools/python/python3-urllib3/CVE-2026-97687_p2.patch new file +482 -0

482 lines not on this page · raw message

meta/recipes-devtools/python/python3-urllib3_2.2.2.bb +2 -0
index f75a74dc74..1cf45a0e1d 100644
@@ -14,6 +14,8 @@ SRC_URI += " \
     file://CVE-2026-21441.patch \
     file://CVE-2026-44431.patch \
     file://CVE-2026-97689.patch \
+    file://CVE-2026-97687_p1.patch \
+    file://CVE-2026-97687_p2.patch \
 "
 
 RDEPENDS:${PN} += "\
Signature · 1 line
2.35.6