diff mbox series

[meta-python,scarthgap,7/9] python3-aiohttp: fix CVE-2026-111063

Message ID 20261125051811.2524271-8-dkelaiya@cisco.com
State New
Headers show
Series python3-aiohttp: backport fixes for ten CVEs | expand

Commit Message

From: Darsh Kelaiya <dkelaiya@cisco.com>

Backport the Secure shared-cookie fix [1] to aiohttp 3.9.5, as
identified by [3]. Check Secure before the shared-cookie branch
adds the cookie to the outgoing set.

Include the trusted-origin correction [2] so per-request cookies
honor the session jar's treat_as_secure_origin policy. Keep the
existing constructor defaults for the temporary cookie jar.

[1] https://github.com/aio-libs/aiohttp/commit/999c356d61e966faffa97b06ab0d0455226d36c5
[2] https://github.com/aio-libs/aiohttp/commit/95081f8a353be2873643ab6dd74904ca413e45e0
[3] https://github.com/aio-libs/aiohttp/security/advisories/GHSA-494j-54xm-rwp3

Signed-off-by: Darsh Kelaiya <dkelaiya@cisco.com>
---
 .../python3-aiohttp/CVE-2026-111063_p1.patch  | 122 +++++++++
 .../python3-aiohttp/CVE-2026-111063_p2.patch  | 257 ++++++++++++++++++
 .../python/python3-aiohttp_3.9.5.bb           |   2 +
 3 files changed, 381 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p1.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p2.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p1.patch b/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p1.patch
new file mode 100644
index 0000000000..417103af7a
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p1.patch
@@ -0,0 +1,122 @@ 
+From 999c356d61e966faffa97b06ab0d0455226d36c5 Mon Sep 17 00:00:00 2001
+From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com>
+Date: Sun, 27 Sep 2026 21:27:34 +0100
+Subject: [PATCH] [PR #13830/e11d2836 backport][3.14] Fix secure shared cookie
+ (#13832)
+
+**This is a backport of PR #13830 as merged into master
+(e11d2836203a21bec59095498e578d37801027e7).**
+
+Co-authored-by: Sam Bull <git@sambull.org>
+
+CVE: CVE-2026-111063
+Upstream-Status: Backport [https://github.com/aio-libs/aiohttp/commit/999c356d61e966faffa97b06ab0d0455226d36c5]
+
+Backport Changes:
+- Guard the existing shared-cookie branch in filter_cookies();
+  aiohttp 3.9.5 does not have a morsel cache.
+- Omit the upstream cache regression because aiohttp 3.9.5 has no
+  morsel cache. This also drops its ordinary HTTPS delivery check.
+
+Signed-off-by: Darsh Kelaiya <dkelaiya@cisco.com>
+---
+ CHANGES/13830.bugfix.rst        |  1 +
+ aiohttp/cookiejar.py            |  2 ++
+ docs/client_reference.rst       |  3 ++-
+ docs/spelling_wordlist.txt      |  1 +
+ tests/test_client_functional.py |  9 +++++++--
+ tests/test_cookiejar.py         | 10 ++++++++++
+ 6 files changed, 23 insertions(+), 3 deletions(-)
+ create mode 100644 CHANGES/13830.bugfix.rst
+
+diff --git a/CHANGES/13830.bugfix.rst b/CHANGES/13830.bugfix.rst
+new file mode 100644
+index 0000000..2a39769
+--- /dev/null
++++ b/CHANGES/13830.bugfix.rst
+@@ -0,0 +1 @@
++Fixed ``CookieJar.filter_cookies()`` sending shared cookies (cookies without a ``Domain`` attribute) marked ``Secure`` over unencrypted connections -- by :user:`Dreamsorcerer`.
+diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py
+index cb5593c..59ace3a 100644
+--- a/aiohttp/cookiejar.py
++++ b/aiohttp/cookiejar.py
+@@ -398,6 +398,8 @@ class CookieJar(AbstractCookieJar):
+ 
+             # Send shared cookies
+             if not domain:
++                if is_not_secure and cookie["secure"]:
++                    continue
+                 filtered[name] = cookie.value
+                 continue
+ 
+diff --git a/docs/client_reference.rst b/docs/client_reference.rst
+index 49a2dfe..38b0833 100644
+--- a/docs/client_reference.rst
++++ b/docs/client_reference.rst
+@@ -1924,7 +1924,8 @@ Utilities
+       :param ~yarl.URL response_url: URL of response, ``None`` for *shared
+          cookies*.  Regular cookies are coupled with server's URL and
+          are sent only to this server, shared ones are sent in every
+-         client request.
++         client request (except that shared cookies marked ``Secure``
++         are only sent over encrypted connections).
+ 
+    .. method:: filter_cookies(request_url)
+ 
+diff --git a/docs/spelling_wordlist.txt b/docs/spelling_wordlist.txt
+index 3fb6d35..e0703d9 100644
+--- a/docs/spelling_wordlist.txt
++++ b/docs/spelling_wordlist.txt
+@@ -331,6 +331,7 @@ UI
+ un
+ unawaited
+ unclosed
++unencrypted
+ unhandled
+ unicode
+ unittest
+diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py
+index d695638..e18348d 100644
+--- a/tests/test_client_functional.py
++++ b/tests/test_client_functional.py
+@@ -2290,12 +2290,17 @@ async def test_morsel_with_attributes(aiohttp_client) -> None:
+     c = http.cookies.Morsel()
+     c.set("test3", "456", "456")
+     c["httponly"] = True
+-    c["secure"] = True
+     c["max-age"] = 1000
+ 
++    # A Secure shared cookie must be withheld entirely: the test server
++    # is plain http, so it must not reach the handler at all.
++    c2: http.cookies.Morsel[str] = http.cookies.Morsel()
++    c2.set("test4", "789", "789")
++    c2["secure"] = True
++
+     app = web.Application()
+     app.router.add_get("/", handler)
+-    client = await aiohttp_client(app, cookies={"test2": c})
++    client = await aiohttp_client(app, cookies={"test2": c, "test4": c2})
+ 
+     async with client.get("/") as resp:
+         assert 200 == resp.status
+diff --git a/tests/test_cookiejar.py b/tests/test_cookiejar.py
+index d9cb5b2..8f852eb 100644
+--- a/tests/test_cookiejar.py
++++ b/tests/test_cookiejar.py
+@@ -1018,6 +1018,16 @@ async def test_save_load_json_roundtrip(
+     assert saved_cookies == loaded_cookies
+ 
+ 
++async def test_treat_as_secure_origin_sends_secure_shared_cookie() -> None:
++    endpoint = URL("http://127.0.0.1/")
++
++    jar = CookieJar(unsafe=True, treat_as_secure_origin=[endpoint])
++    jar.update_cookies(SimpleCookie("shared-secure-cookie=first; Secure;"))
++
++    filtered_cookies = jar.filter_cookies(request_url=endpoint)
++    assert "shared-secure-cookie" in filtered_cookies
++
++
+ async def test_save_load_json_preserves_host_only_scope(tmp_path: Path) -> None:
+     """Verify save/load keeps host-only cookies off subdomains."""
+     file_path = tmp_path / "host_only.json"
diff --git a/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p2.patch b/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p2.patch
new file mode 100644
index 0000000000..0d8e90eea0
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-aiohttp/CVE-2026-111063_p2.patch
@@ -0,0 +1,257 @@ 
+From 95081f8a353be2873643ab6dd74904ca413e45e0 Mon Sep 17 00:00:00 2001
+From: Sam Bull <git@sambull.org>
+Date: Mon, 28 Sep 2026 00:38:13 +0100
+Subject: [PATCH] Fix treat_as_secure_origin on request cookies (#13833)
+ (#13836)
+
+(cherry picked from commit 6bc84990f2a6429667f741d97f5da22884b8a8d3)
+
+CVE: CVE-2026-111063
+Upstream-Status: Backport [https://github.com/aio-libs/aiohttp/commit/95081f8a353be2873643ab6dd74904ca413e45e0]
+
+Backport Changes:
+- Keep Union annotations and drop the unused List import. Pass only
+  trusted origins to the temporary jar. The 3.9.5 API has no public
+  unsafe or quote_cookie properties.
+- Place the property beside existing methods and documentation;
+  the newer public cookie-inspection sections do not exist.
+- Import the existing AiohttpServer test fixture type.
+
+Signed-off-by: Darsh Kelaiya <dkelaiya@cisco.com>
+---
+ CHANGES/13833.bugfix.rst        |  1 +
+ aiohttp/abc.py                  |  5 ++++
+ aiohttp/client.py               |  6 +++-
+ aiohttp/cookiejar.py            | 27 ++++++++++-------
+ docs/client_reference.rst       | 13 +++++++--
+ tests/test_client_functional.py | 51 ++++++++++++++++++++++++++++++++-
+ tests/test_cookiejar.py         |  3 +-
+ 7 files changed, 91 insertions(+), 15 deletions(-)
+ create mode 100644 CHANGES/13833.bugfix.rst
+
+diff --git a/CHANGES/13833.bugfix.rst b/CHANGES/13833.bugfix.rst
+new file mode 100644
+index 0000000..2d0f96c
+--- /dev/null
++++ b/CHANGES/13833.bugfix.rst
+@@ -0,0 +1 @@
++Fixed per-request cookies (the ``cookies`` argument of a request method) marked ``Secure`` not being sent to origins listed in ``CookieJar``'s ``treat_as_secure_origin`` -- by :user:`Dreamsorcerer`.
+diff --git a/aiohttp/abc.py b/aiohttp/abc.py
+index ee83899..7dfbf5c 100644
+--- a/aiohttp/abc.py
++++ b/aiohttp/abc.py
+@@ -146,6 +146,11 @@ class AbstractCookieJar(Sized, IterableBase):
+     def __init__(self, *, loop: Optional[asyncio.AbstractEventLoop] = None) -> None:
+         self._loop = get_running_loop(loop)
+ 
++    @property
++    def treat_as_secure_origin(self) -> frozenset[URL]:
++        """Return origins considered secure even over cleartext connections."""
++        return frozenset()
++
+     @abstractmethod
+     def clear(self, predicate: Optional[ClearCookiePredicate] = None) -> None:
+         """Clear all cookies if no predicate is passed."""
+diff --git a/aiohttp/client.py b/aiohttp/client.py
+index 2e88917..103858a 100644
+--- a/aiohttp/client.py
++++ b/aiohttp/client.py
+@@ -540,7 +540,11 @@ class ClientSession:
+                     all_cookies = self._cookie_jar.filter_cookies(url)
+ 
+                     if cookies is not None:
+-                        tmp_cookie_jar = CookieJar()
++                        tmp_cookie_jar = CookieJar(
++                            treat_as_secure_origin=frozenset(
++                                self._cookie_jar.treat_as_secure_origin
++                            ),
++                        )
+                         tmp_cookie_jar.update_cookies(cookies)
+                         req_cookies = tmp_cookie_jar.filter_cookies(url)
+                         if req_cookies:
+diff --git a/aiohttp/cookiejar.py b/aiohttp/cookiejar.py
+index 59ace3a..60131c9 100644
+--- a/aiohttp/cookiejar.py
++++ b/aiohttp/cookiejar.py
+@@ -16,7 +16,6 @@ from typing import (  # noqa
+     Dict,
+     Iterable,
+     Iterator,
+-    List,
+     Mapping,
+     Optional,
+     Set,
+@@ -117,7 +116,7 @@ class CookieJar(AbstractCookieJar):
+         *,
+         unsafe: bool = False,
+         quote_cookie: bool = True,
+-        treat_as_secure_origin: Union[StrOrURL, List[StrOrURL], None] = None,
++        treat_as_secure_origin: Union[StrOrURL, Iterable[StrOrURL], None] = None,
+         loop: Optional[asyncio.AbstractEventLoop] = None,
+     ) -> None:
+         super().__init__(loop=loop)
+@@ -129,20 +128,28 @@ class CookieJar(AbstractCookieJar):
+         self._unsafe = unsafe
+         self._quote_cookie = quote_cookie
+         if treat_as_secure_origin is None:
+-            treat_as_secure_origin = []
++            self._treat_as_secure_origin: frozenset[URL] = frozenset()
+         elif isinstance(treat_as_secure_origin, URL):
+-            treat_as_secure_origin = [treat_as_secure_origin.origin()]
++            self._treat_as_secure_origin = frozenset({treat_as_secure_origin.origin()})
+         elif isinstance(treat_as_secure_origin, str):
+-            treat_as_secure_origin = [URL(treat_as_secure_origin).origin()]
++            self._treat_as_secure_origin = frozenset(
++                {URL(treat_as_secure_origin).origin()}
++            )
+         else:
+-            treat_as_secure_origin = [
+-                URL(url).origin() if isinstance(url, str) else url.origin()
+-                for url in treat_as_secure_origin
+-            ]
+-        self._treat_as_secure_origin = treat_as_secure_origin
++            self._treat_as_secure_origin = frozenset(
++                {
++                    URL(url).origin() if isinstance(url, str) else url.origin()
++                    for url in treat_as_secure_origin
++                }
++            )
+         self._next_expiration: float = ceil(time.time())
+         self._expirations: Dict[Tuple[str, str, str], float] = {}
+ 
++    @property
++    def treat_as_secure_origin(self) -> frozenset[URL]:
++        """Return origins considered secure even over cleartext connections."""
++        return self._treat_as_secure_origin
++
+     def save(self, file_path: PathLike) -> None:
+         """Save cookies to a file using JSON format.
+ 
+diff --git a/docs/client_reference.rst b/docs/client_reference.rst
+index 38b0833..5bb290e 100644
+--- a/docs/client_reference.rst
++++ b/docs/client_reference.rst
+@@ -1901,7 +1901,7 @@ Utilities
+       .. versionadded:: 3.7
+ 
+    :param treat_as_secure_origin: (optional) Mark origins as secure
+-                                  for cookies marked as Secured. Possible types are
++                                  for cookies marked as Secured.
+ 
+                                   Possible types are:
+ 
+@@ -1925,7 +1925,8 @@ Utilities
+          cookies*.  Regular cookies are coupled with server's URL and
+          are sent only to this server, shared ones are sent in every
+          client request (except that shared cookies marked ``Secure``
+-         are only sent over encrypted connections).
++         are only sent over encrypted connections or to origins listed
++         in *treat_as_secure_origin*).
+ 
+    .. method:: filter_cookies(request_url)
+ 
+@@ -1969,6 +1970,14 @@ Utilities
+ 
+       .. versionadded:: 4.0
+ 
++   .. attribute:: treat_as_secure_origin
++
++      A :class:`frozenset` of :class:`~yarl.URL` origins that are
++      treated as secure even when the connection is not encrypted, as
++      configured by the *treat_as_secure_origin* parameter.
++
++      .. versionadded:: 3.14.4
++
+ 
+ .. class:: DummyCookieJar(*, loop=None)
+ 
+diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py
+index e18348d..d321d82 100644
+--- a/tests/test_client_functional.py
++++ b/tests/test_client_functional.py
+@@ -30,7 +30,7 @@ from aiohttp.abc import AbstractResolver
+ from aiohttp.client_exceptions import TooManyRedirects
+ from aiohttp.compression_utils import DEFAULT_MAX_DECOMPRESS_SIZE, HAS_BROTLI
+ from aiohttp.http_exceptions import DecompressSizeError
+-from aiohttp.pytest_plugin import AiohttpClient, TestClient
++from aiohttp.pytest_plugin import AiohttpClient, AiohttpServer, TestClient
+ from aiohttp.test_utils import unused_port
+ 
+ 
+@@ -2306,6 +2306,55 @@ async def test_morsel_with_attributes(aiohttp_client) -> None:
+         assert 200 == resp.status
+ 
+ 
++async def test_request_secure_cookie_treat_as_secure_origin(
++    aiohttp_server: AiohttpServer, aiohttp_client: AiohttpClient
++) -> None:
++    """Per-request Secure cookies must honor the session jar's trusted origins."""
++
++    async def handler(request: web.Request) -> web.Response:
++        assert request.cookies.get("auth") == "token"
++        return web.Response()
++
++    app = web.Application()
++    app.router.add_get("/", handler)
++    server = await aiohttp_server(app)
++
++    jar = aiohttp.CookieJar(unsafe=True, treat_as_secure_origin=[server.make_url("/")])
++    client = await aiohttp_client(server, cookie_jar=jar)  # type: ignore[var-annotated]
++
++    c: http.cookies.Morsel[str] = http.cookies.Morsel()
++    c.set("auth", "token", "token")
++    c["secure"] = True
++
++    async with client.get("/", cookies={"auth": c}) as resp:
++        assert resp.status == 200
++
++
++async def test_request_secure_cookie_not_sent_over_http(
++    aiohttp_client: AiohttpClient,
++) -> None:
++    """A per-request Secure cookie is only sent to the jar's trusted origins."""
++
++    async def handler(request: web.Request) -> web.Response:
++        assert request.cookies.keys() == {"plain"}
++        return web.Response()
++
++    app = web.Application()
++    app.router.add_get("/", handler)
++    # The trusted origin never matches the test server, so the Secure
++    # cookie must still be withheld from this plain-http request.
++    jar = aiohttp.CookieJar(treat_as_secure_origin=[URL("http://example.com")])
++    client = await aiohttp_client(app, cookie_jar=jar)
++
++    c: http.cookies.Morsel[str] = http.cookies.Morsel()
++    c.set("auth", "token", "token")
++    c["secure"] = True
++
++    cookies: dict[str, str | http.cookies.Morsel[str]] = {"auth": c, "plain": "ok"}
++    async with client.get("/", cookies=cookies) as resp:
++        assert resp.status == 200
++
++
+ async def test_set_cookies(aiohttp_client) -> None:
+     async def handler(request):
+         ret = web.Response()
+diff --git a/tests/test_cookiejar.py b/tests/test_cookiejar.py
+index 8f852eb..f248de5 100644
+--- a/tests/test_cookiejar.py
++++ b/tests/test_cookiejar.py
+@@ -732,6 +732,7 @@ class TestCookieJarSafe(TestCookieJarBase):
+ async def test_dummy_cookie_jar() -> None:
+     cookie = SimpleCookie("foo=bar; Domain=example.com;")
+     dummy_jar = DummyCookieJar()
++    assert dummy_jar.treat_as_secure_origin == frozenset()
+     assert len(dummy_jar) == 0
+     dummy_jar.update_cookies(cookie)
+     assert len(dummy_jar) == 0
+@@ -847,7 +848,7 @@ async def test_pickle_format(cookies_to_send) -> None:
+ )
+ async def test_treat_as_secure_origin_init(url) -> None:
+     jar = CookieJar(unsafe=True, treat_as_secure_origin=url)
+-    assert jar._treat_as_secure_origin == [URL("http://127.0.0.1")]
++    assert jar.treat_as_secure_origin == frozenset({URL("http://127.0.0.1")})
+ 
+ 
+ async def test_treat_as_secure_origin() -> None:
diff --git a/meta-python/recipes-devtools/python/python3-aiohttp_3.9.5.bb b/meta-python/recipes-devtools/python/python3-aiohttp_3.9.5.bb
index 16ec0a603b..f86a594669 100644
--- a/meta-python/recipes-devtools/python/python3-aiohttp_3.9.5.bb
+++ b/meta-python/recipes-devtools/python/python3-aiohttp_3.9.5.bb
@@ -44,6 +44,8 @@  SRC_URI += "file://CVE-2024-52304.patch \
            file://CVE-2026-111066_p2.patch \
            file://CVE-2026-111065.patch \
            file://CVE-2026-111064.patch \
+           file://CVE-2026-111063_p1.patch \
+           file://CVE-2026-111063_p2.patch \
            "
 
 CVE_STATUS[CVE-2026-34515] = "not-applicable-platform: Vulnerability only affects applications running on Windows"