diff options
author | Jiaying Song <jiaying.song.cn@windriver.com> | 2024-12-04 17:28:01 +0800 |
---|---|---|
committer | Steve Sakoman <steve@sakoman.com> | 2024-12-16 05:58:03 -0800 |
commit | e402b2417a0546548772eb5e2ae69fc1f254f69c (patch) | |
tree | 5c365ca39c9186d3a66010a623d66fbc64f6a8fe | |
parent | 2a6fc7fbf2a772464dbf55dc3a645a042e93d866 (diff) | |
download | poky-e402b2417a0546548772eb5e2ae69fc1f254f69c.tar.gz |
python3-requests: fix CVE-2024-35195
Requests is a HTTP library. Prior to 2.32.0, when making requests
through a Requests `Session`, if the first request is made with
`verify=False` to disable cert verification, all subsequent requests to
the same host will continue to ignore cert verification regardless of
changes to the value of `verify`. This behavior will continue for the
lifecycle of the connection in the connection pool. This vulnerability
is fixed in 2.32.0.
References:
https://nvd.nist.gov/vuln/detail/CVE-2024-35195
Upstream patches:
https://github.com/psf/requests/commit/a58d7f2ffb4d00b46dca2d70a3932a0b37e22fac
(From OE-Core rev: 8bc8d316a6e8ac08b4eb2b9e2ec30b1f2309c31c)
Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
-rw-r--r-- | meta/recipes-devtools/python/python3-requests/CVE-2024-35195.patch | 121 | ||||
-rw-r--r-- | meta/recipes-devtools/python/python3-requests_2.27.1.bb | 4 |
2 files changed, 124 insertions, 1 deletions
diff --git a/meta/recipes-devtools/python/python3-requests/CVE-2024-35195.patch b/meta/recipes-devtools/python/python3-requests/CVE-2024-35195.patch new file mode 100644 index 0000000000..4e2605b922 --- /dev/null +++ b/meta/recipes-devtools/python/python3-requests/CVE-2024-35195.patch | |||
@@ -0,0 +1,121 @@ | |||
1 | From 5bedf76da0f76ab2d489972055a5d62066013427 Mon Sep 17 00:00:00 2001 | ||
2 | From: Ian Stapleton Cordasco <graffatcolmingov@gmail.com> | ||
3 | Date: Sun, 3 Mar 2024 07:00:49 -0600 | ||
4 | Subject: [PATCH] Use TLS settings in selecting connection pool | ||
5 | |||
6 | Previously, if someone made a request with `verify=False` then made a | ||
7 | request where they expected verification to be enabled to the same host, | ||
8 | they would potentially reuse a connection where TLS had not been | ||
9 | verified. | ||
10 | |||
11 | This fixes that issue. | ||
12 | |||
13 | Upstream-Status: Backport | ||
14 | [https://github.com/psf/requests/commit/a58d7f2ffb4d00b46dca2d70a3932a0b37e22fac] | ||
15 | |||
16 | CVE: CVE-2024-35195 | ||
17 | |||
18 | Signed-off-by: Jiaying Song <jiaying.song.cn@windriver.com> | ||
19 | --- | ||
20 | requests/adapters.py | 58 +++++++++++++++++++++++++++++++++++++++++++- | ||
21 | 1 file changed, 57 insertions(+), 1 deletion(-) | ||
22 | |||
23 | diff --git a/requests/adapters.py b/requests/adapters.py | ||
24 | index fe22ff4..7ff6998 100644 | ||
25 | --- a/requests/adapters.py | ||
26 | +++ b/requests/adapters.py | ||
27 | @@ -10,6 +10,7 @@ and maintain connections. | ||
28 | |||
29 | import os.path | ||
30 | import socket | ||
31 | +import typing | ||
32 | |||
33 | from urllib3.poolmanager import PoolManager, proxy_from_url | ||
34 | from urllib3.response import HTTPResponse | ||
35 | @@ -47,12 +48,38 @@ except ImportError: | ||
36 | def SOCKSProxyManager(*args, **kwargs): | ||
37 | raise InvalidSchema("Missing dependencies for SOCKS support.") | ||
38 | |||
39 | +if typing.TYPE_CHECKING: | ||
40 | + from .models import PreparedRequest | ||
41 | + | ||
42 | + | ||
43 | DEFAULT_POOLBLOCK = False | ||
44 | DEFAULT_POOLSIZE = 10 | ||
45 | DEFAULT_RETRIES = 0 | ||
46 | DEFAULT_POOL_TIMEOUT = None | ||
47 | |||
48 | |||
49 | +def _urllib3_request_context( | ||
50 | + request: "PreparedRequest", verify: "bool | str | None" | ||
51 | +) -> "(typing.Dict[str, typing.Any], typing.Dict[str, typing.Any])": | ||
52 | + host_params = {} | ||
53 | + pool_kwargs = {} | ||
54 | + parsed_request_url = urlparse(request.url) | ||
55 | + scheme = parsed_request_url.scheme.lower() | ||
56 | + port = parsed_request_url.port | ||
57 | + cert_reqs = "CERT_REQUIRED" | ||
58 | + if verify is False: | ||
59 | + cert_reqs = "CERT_NONE" | ||
60 | + if isinstance(verify, str): | ||
61 | + pool_kwargs["ca_certs"] = verify | ||
62 | + pool_kwargs["cert_reqs"] = cert_reqs | ||
63 | + host_params = { | ||
64 | + "scheme": scheme, | ||
65 | + "host": parsed_request_url.hostname, | ||
66 | + "port": port, | ||
67 | + } | ||
68 | + return host_params, pool_kwargs | ||
69 | + | ||
70 | + | ||
71 | class BaseAdapter(object): | ||
72 | """The Base Transport Adapter""" | ||
73 | |||
74 | @@ -290,6 +317,35 @@ class HTTPAdapter(BaseAdapter): | ||
75 | |||
76 | return response | ||
77 | |||
78 | + def _get_connection(self, request, verify, proxies=None): | ||
79 | + # Replace the existing get_connection without breaking things and | ||
80 | + # ensure that TLS settings are considered when we interact with | ||
81 | + # urllib3 HTTP Pools | ||
82 | + proxy = select_proxy(request.url, proxies) | ||
83 | + try: | ||
84 | + host_params, pool_kwargs = _urllib3_request_context(request, verify) | ||
85 | + except ValueError as e: | ||
86 | + raise InvalidURL(e, request=request) | ||
87 | + if proxy: | ||
88 | + proxy = prepend_scheme_if_needed(proxy, "http") | ||
89 | + proxy_url = parse_url(proxy) | ||
90 | + if not proxy_url.host: | ||
91 | + raise InvalidProxyURL( | ||
92 | + "Please check proxy URL. It is malformed " | ||
93 | + "and could be missing the host." | ||
94 | + ) | ||
95 | + proxy_manager = self.proxy_manager_for(proxy) | ||
96 | + conn = proxy_manager.connection_from_host( | ||
97 | + **host_params, pool_kwargs=pool_kwargs | ||
98 | + ) | ||
99 | + else: | ||
100 | + # Only scheme should be lower case | ||
101 | + conn = self.poolmanager.connection_from_host( | ||
102 | + **host_params, pool_kwargs=pool_kwargs | ||
103 | + ) | ||
104 | + | ||
105 | + return conn | ||
106 | + | ||
107 | def get_connection(self, url, proxies=None): | ||
108 | """Returns a urllib3 connection for the given URL. This should not be | ||
109 | called from user code, and is only exposed for use when subclassing the | ||
110 | @@ -410,7 +466,7 @@ class HTTPAdapter(BaseAdapter): | ||
111 | """ | ||
112 | |||
113 | try: | ||
114 | - conn = self.get_connection(request.url, proxies) | ||
115 | + conn = self._get_connection(request, verify, proxies) | ||
116 | except LocationValueError as e: | ||
117 | raise InvalidURL(e, request=request) | ||
118 | |||
119 | -- | ||
120 | 2.25.1 | ||
121 | |||
diff --git a/meta/recipes-devtools/python/python3-requests_2.27.1.bb b/meta/recipes-devtools/python/python3-requests_2.27.1.bb index 635a6af31f..689a1dffb7 100644 --- a/meta/recipes-devtools/python/python3-requests_2.27.1.bb +++ b/meta/recipes-devtools/python/python3-requests_2.27.1.bb | |||
@@ -3,7 +3,9 @@ HOMEPAGE = "http://python-requests.org" | |||
3 | LICENSE = "Apache-2.0" | 3 | LICENSE = "Apache-2.0" |
4 | LIC_FILES_CHKSUM = "file://LICENSE;md5=34400b68072d710fecd0a2940a0d1658" | 4 | LIC_FILES_CHKSUM = "file://LICENSE;md5=34400b68072d710fecd0a2940a0d1658" |
5 | 5 | ||
6 | SRC_URI += "file://CVE-2023-32681.patch" | 6 | SRC_URI += "file://CVE-2023-32681.patch \ |
7 | file://CVE-2024-35195.patch \ | ||
8 | " | ||
7 | 9 | ||
8 | SRC_URI[sha256sum] = "68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61" | 10 | SRC_URI[sha256sum] = "68d7c56fd5a8999887728ef304a6d12edc7be74f1cfa47714fc8b414525c9a61" |
9 | 11 | ||