Skip to contentSkip to conversation

python3-pyjwt: Fix CVE-2026-48522

PATCH New Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco) 1 participant 6 messages Aug 19

lore
Share & tools
lore
#0 lore raw

PATCH 1/6 python3-pyjwt: Fix CVE-2026-48522

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 2.13.0 backport for CVE-2026-48522. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2].

[1] https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81
[2] https://github.com/advisories/GHSA-993g-76c3-p5m4

---
 .../python/files/CVE-2026-48522.patch         | 126 ++++++++++++++++++
 .../python/python3-pyjwt_2.12.1.bb            |   2 +
 2 files changed, 128 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-48522.patch
meta-python/recipes-devtools/python/files/CVE-2026-48522.patch new file +126 -0
new file mode 100644
index 0000000000..c1e6466d35
@@ -0,0 +1,126 @@
+From f369d32169410b17717d2a9c00d5bf3ac655c85d Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jos=C3=A9=20Padilla?= <[email protected]>
+Date: Thu, 21 May 2026 14:11:10 -0400
+Subject: [PATCH] Bundle security fixes and hardening into 2.13.0
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Security:
+- `HMACAlgorithm.prepare_key` rejects JWK JSON documents passed as raw
+  HMAC secrets to close an algorithm-confusion gap not covered by the
+  existing PEM/SSH guard. Reported by @aradona91 in GHSA-xgmm-8j9v-c9wx.
+- Bind the JWT header `alg` to `PyJWK.algorithm_name` during verification
+  so the caller's `algorithms` allow-list cannot be bypassed when decoding
+  with a `PyJWK` / `PyJWKClient` key. Reported by @sushi-gif in
+  GHSA-jq35-7prp-9v3f.
+- Skip the unconditional base64 decode of the compact-form payload
+  segment when `b64=false` is set, and require that segment to be empty
+  (RFC 7515 Appendix F detached form). Closes an unauthenticated DoS
+  amplifier. Reported by @thesmartshadow in GHSA-w7vc-732c-9m39.
+- `PyJWKClient` rejects any URI whose scheme is not `http` or `https` so
+  attacker-influenced URIs cannot read local files or reach unintended
+  schemes via urllib's default `file://` / `ftp://` / `data:` handlers.
+  Reported by @KEIJOT in GHSA-993g-76c3-p5m4.
+- Preserve the cached JWK Set on fetch errors in `PyJWKClient.fetch_data`.
+  The previous `finally`-block `put(None)` pattern cleared the cache on
+  any transient outage. Reported by @eddieran in GHSA-fhv5-28vv-h8m8.
+
+Fixes:
+- Reject empty HMAC keys outright in `HMACAlgorithm.prepare_key` with
+  `InvalidKeyError` instead of accepting them with only a warning.
+  Hardening prompted by reports from @SnailSploit and @spartan8806.
+- Forward per-call `options` (including `enforce_minimum_key_length`)
+  from `PyJWT.decode` through to `PyJWS._verify_signature`. Thanks to
+  @WLUB.
+- RFC 7797 §3 compliance for `b64=false`: encoder auto-adds `"b64"` to
+  `crit`; decoder rejects tokens that set `b64=false` without listing
+  it in `crit`. Thanks to @MachineLearning-Nerd.
+
+CVE: CVE-2026-48522
+Upstream-Status: Backport [https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81]
+
+Backport Changes:
+- Split out the PyJWKClient URI-scheme validation because the upstream
+  commit bundles multiple CVEs.
+- Omitted CHANGELOG.rst because it conflicted and is release documentation.
+- Omitted the 2.13.0 version bump and other bundled fixes; applicable CVE
+  fixes are carried in separate patches.
+
+(cherry picked from commit 95791b1759b8aa4f2203575d344d5c78564cdc81)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ jwt/jwks_client.py        | 11 +++++++++++
+ tests/test_jwks_client.py | 30 ++++++++++++++++++++++++++++++
+ 2 files changed, 41 insertions(+)
+
+diff --git a/jwt/jwks_client.py b/jwt/jwks_client.py
+index b81e8f4..8d1b0c4 100644
+--- a/jwt/jwks_client.py
++++ b/jwt/jwks_client.py
+@@ -6,6 +6,7 @@ from functools import lru_cache
+ from ssl import SSLContext
+ from typing import Any
+ from urllib.error import HTTPError, URLError
++from urllib.parse import urlparse
+ 
+ from .api_jwk import PyJWK, PyJWKSet
+ from .api_jwt import decode_complete as decode_token
+@@ -69,6 +70,16 @@ class PyJWKClient:
+         """
+         if headers is None:
+             headers = {}
++        # urllib's default OpenerDirector also handles file://, ftp://, and
++        # data: URIs. Reject anything that isn't http(s) eagerly so a caller
++        # passing an attacker-influenced URL (e.g. taken from a `jku` token
++        # header) can't read local files or reach other unintended schemes.
++        scheme = urlparse(uri).scheme.lower()
++        if scheme not in ("http", "https"):
++            raise PyJWKClientError(
++                f"Invalid JWKS URI scheme {scheme!r}: only 'http' and 'https' "
++                f"are supported."
++            )
+         self.uri = uri
+         self.jwk_set_cache: JWKSetCache | None = None
+         self.headers = headers
+diff --git a/tests/test_jwks_client.py b/tests/test_jwks_client.py
+index ceee672..d6793cc 100644
+--- a/tests/test_jwks_client.py
++++ b/tests/test_jwks_client.py
+@@ -344,6 +344,36 @@ class TestPyJWKClient:
+             jwks_client = PyJWKClient(url, lifespan=-1)
+             assert jwks_client is None
+ 
++    @pytest.mark.parametrize(
++        "uri",
++        [
++            "file:///etc/passwd",
++            "ftp://example.org/keys.json",
++            'data:application/json,{"keys":[]}',
++            "/etc/passwd",  # urlparse gives scheme="" — also rejected
++            "ldap://internal.test/jwks",
++        ],
++    )
++    def test_pyjwkclient_rejects_non_http_schemes(self, uri: str) -> None:
++        # urllib's default OpenerDirector handles file://, ftp://, and data:
++        # URIs. PyJWKClient must reject these so callers can't be tricked
++        # into reading attacker-controlled local files or other unintended
++        # schemes via a manipulated URI.
++        with pytest.raises(PyJWKClientError, match="Invalid JWKS URI scheme"):
++            PyJWKClient(uri)
++
++    @pytest.mark.parametrize(
++        "uri",
++        [
++            "http://localhost/jwks.json",
++            "https://example.test/jwks.json",
++            "HTTPS://Example.Test/jwks.json",  # case-insensitive
++        ],
++    )
++    def test_pyjwkclient_accepts_http_https_schemes(self, uri: str) -> None:
++        # Construction succeeds; no fetch is made until get_jwk_set().
++        PyJWKClient(uri)
++
+     def test_get_jwt_set_timeout(self) -> None:
+         url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
+         jwks_client = PyJWKClient(url, timeout=5)
meta-python/recipes-devtools/python/python3-pyjwt_2.12.1.bb +2 -0
index eb445f9c91..ed7a280ee5 100644
@@ -5,6 +5,8 @@ HOMEPAGE = "https://github.com/jpadilla/pyjwt"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=e4b56d2c9973d8cf54655555be06e551"
 
+SRC_URI += "file://CVE-2026-48522.patch"
+
 SRC_URI[sha256sum] = "c74a7a2adf861c04d002db713dd85f84beb242228e671280bf709d765b03672b"
 
 PYPI_PACKAGE = "pyjwt"
Signature · 1 line
2.35.6
#1 lore raw

PATCH 2/6 python3-pyjwt: Fix CVE-2026-48523

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 2.13.0 backport for CVE-2026-48523. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2].

[1] https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81
[2] https://github.com/advisories/GHSA-jq35-7prp-9v3f

---
 .../python/files/CVE-2026-48523.patch         | 115 ++++++++++++++++++
 .../python/python3-pyjwt_2.12.1.bb            |   4 +-
 2 files changed, 118 insertions(+), 1 deletion(-)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-48523.patch
meta-python/recipes-devtools/python/files/CVE-2026-48523.patch new file +115 -0
new file mode 100644
index 0000000000..f272338979
@@ -0,0 +1,115 @@
+From 6590add3a8d18098b107fe446ff256ae92e7238f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jos=C3=A9=20Padilla?= <[email protected]>
+Date: Thu, 21 May 2026 14:11:10 -0400
+Subject: [PATCH] Bundle security fixes and hardening into 2.13.0
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Security:
+- `HMACAlgorithm.prepare_key` rejects JWK JSON documents passed as raw
+  HMAC secrets to close an algorithm-confusion gap not covered by the
+  existing PEM/SSH guard. Reported by @aradona91 in GHSA-xgmm-8j9v-c9wx.
+- Bind the JWT header `alg` to `PyJWK.algorithm_name` during verification
+  so the caller's `algorithms` allow-list cannot be bypassed when decoding
+  with a `PyJWK` / `PyJWKClient` key. Reported by @sushi-gif in
+  GHSA-jq35-7prp-9v3f.
+- Skip the unconditional base64 decode of the compact-form payload
+  segment when `b64=false` is set, and require that segment to be empty
+  (RFC 7515 Appendix F detached form). Closes an unauthenticated DoS
+  amplifier. Reported by @thesmartshadow in GHSA-w7vc-732c-9m39.
+- `PyJWKClient` rejects any URI whose scheme is not `http` or `https` so
+  attacker-influenced URIs cannot read local files or reach unintended
+  schemes via urllib's default `file://` / `ftp://` / `data:` handlers.
+  Reported by @KEIJOT in GHSA-993g-76c3-p5m4.
+- Preserve the cached JWK Set on fetch errors in `PyJWKClient.fetch_data`.
+  The previous `finally`-block `put(None)` pattern cleared the cache on
+  any transient outage. Reported by @eddieran in GHSA-fhv5-28vv-h8m8.
+
+Fixes:
+- Reject empty HMAC keys outright in `HMACAlgorithm.prepare_key` with
+  `InvalidKeyError` instead of accepting them with only a warning.
+  Hardening prompted by reports from @SnailSploit and @spartan8806.
+- Forward per-call `options` (including `enforce_minimum_key_length`)
+  from `PyJWT.decode` through to `PyJWS._verify_signature`. Thanks to
+  @WLUB.
+- RFC 7797 §3 compliance for `b64=false`: encoder auto-adds `"b64"` to
+  `crit`; decoder rejects tokens that set `b64=false` without listing
+  it in `crit`. Thanks to @MachineLearning-Nerd.
+
+CVE: CVE-2026-48523
+Upstream-Status: Backport [https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81]
+
+Backport Changes:
+- Split out the PyJWK algorithm-binding validation because the upstream
+  commit bundles multiple CVEs.
+- Omitted CHANGELOG.rst because it conflicted and is release documentation.
+- Omitted the 2.13.0 version bump and other bundled fixes; applicable CVE
+  fixes are carried in separate patches.
+
+(cherry picked from commit 95791b1759b8aa4f2203575d344d5c78564cdc81)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ jwt/api_jws.py        | 10 ++++++++++
+ tests/test_api_jws.py | 27 +++++++++++++++++++++++++++
+ 2 files changed, 37 insertions(+)
+
+diff --git a/jwt/api_jws.py b/jwt/api_jws.py
+index 0ab7e4b..91d2ae3 100644
+--- a/jwt/api_jws.py
++++ b/jwt/api_jws.py
+@@ -348,6 +348,16 @@ class PyJWS:
+             raise InvalidAlgorithmError("The specified alg value is not allowed")
+ 
+         if isinstance(key, PyJWK):
++            # The PyJWK has a fixed algorithm bound at construction time.
++            # Verification must use that algorithm, not whatever the token
++            # header advertises, otherwise the caller's allow-list check
++            # above degenerates into a string compare with no behavioural
++            # effect on which algorithm actually verifies the signature.
++            if alg != key.algorithm_name:
++                raise InvalidAlgorithmError(
++                    f"Token algorithm {alg!r} does not match the key's "
++                    f"algorithm {key.algorithm_name!r}"
++                )
+             alg_obj = key.Algorithm
+             prepared_key = key.key
+         else:
+diff --git a/tests/test_api_jws.py b/tests/test_api_jws.py
+index 9f7edc0..0715b9e 100644
+--- a/tests/test_api_jws.py
++++ b/tests/test_api_jws.py
+@@ -397,6 +397,33 @@ class TestJWS:
+         with pytest.raises(InvalidAlgorithmError):
+             jws.decode(example_jws, jwk)
+ 
++    def test_decodes_with_jwk_rejects_header_alg_outside_jwk_alg(
++        self, jws: PyJWS
++    ) -> None:
++        # Token header says HS256 and the caller's allow-list also accepts
++        # HS256, but the PyJWK is bound to HS512. Even though the allow-list
++        # would pass, verification must be locked to the PyJWK's algorithm
++        # rather than the header's — otherwise an attacker who controls a
++        # registered key can advertise a disallowed algorithm in the header
++        # and have it accepted.
++        jwk = PyJWK(
++            {
++                "kty": "oct",
++                "alg": "HS512",
++                "k": "c2VjcmV0",  # "secret"
++            }
++        )
++        example_jws = (
++            b"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9."
++            b"aGVsbG8gd29ybGQ."
++            b"gEW0pdU4kxPthjtehYdhxB9mMOGajt1xCKlGGXDJ8PM"
++        )
++
++        with pytest.raises(
++            InvalidAlgorithmError, match="does not match the key's algorithm"
++        ):
++            jws.decode(example_jws, jwk, algorithms=["HS256", "HS512"])
++
+     # 'Control' Elliptic Curve jws created by another library.
+     # Used to test for regressions that could affect both
+     # encoding / decoding operations equally (causing tests
meta-python/recipes-devtools/python/python3-pyjwt_2.12.1.bb +3 -1
index ed7a280ee5..e67c7bae2f 100644
@@ -5,7 +5,9 @@ HOMEPAGE = "https://github.com/jpadilla/pyjwt"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=e4b56d2c9973d8cf54655555be06e551"
 
-SRC_URI += "file://CVE-2026-48522.patch"
+SRC_URI += "file://CVE-2026-48522.patch \
+           file://CVE-2026-48523.patch \
+           "
 
 SRC_URI[sha256sum] = "c74a7a2adf861c04d002db713dd85f84beb242228e671280bf709d765b03672b"
 
Signature · 1 line
2.35.6
#2 lore raw

PATCH 3/6 python3-pyjwt: Fix CVE-2026-48524

In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 2.13.0 backport for CVE-2026-48524. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2].

[1] https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81
[2] https://github.com/advisories/GHSA-fhv5-28vv-h8m8

---
 .../python/files/CVE-2026-48524.patch         | 125 ++++++++++++++++++
 .../python/python3-pyjwt_2.12.1.bb            |   1 +
 2 files changed, 126 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-48524.patch
meta-python/recipes-devtools/python/files/CVE-2026-48524.patch new file +125 -0
new file mode 100644
index 0000000000..d583ea1275
@@ -0,0 +1,125 @@
+From 9d971fad56d6571a3bfc037ca21e3be694b9cabd Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jos=C3=A9=20Padilla?= <[email protected]>
+Date: Thu, 21 May 2026 14:11:10 -0400
+Subject: [PATCH] Bundle security fixes and hardening into 2.13.0
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Security:
+- `HMACAlgorithm.prepare_key` rejects JWK JSON documents passed as raw
+  HMAC secrets to close an algorithm-confusion gap not covered by the
+  existing PEM/SSH guard. Reported by @aradona91 in GHSA-xgmm-8j9v-c9wx.
+- Bind the JWT header `alg` to `PyJWK.algorithm_name` during verification
+  so the caller's `algorithms` allow-list cannot be bypassed when decoding
+  with a `PyJWK` / `PyJWKClient` key. Reported by @sushi-gif in
+  GHSA-jq35-7prp-9v3f.
+- Skip the unconditional base64 decode of the compact-form payload
+  segment when `b64=false` is set, and require that segment to be empty
+  (RFC 7515 Appendix F detached form). Closes an unauthenticated DoS
+  amplifier. Reported by @thesmartshadow in GHSA-w7vc-732c-9m39.
+- `PyJWKClient` rejects any URI whose scheme is not `http` or `https` so
+  attacker-influenced URIs cannot read local files or reach unintended
+  schemes via urllib's default `file://` / `ftp://` / `data:` handlers.
+  Reported by @KEIJOT in GHSA-993g-76c3-p5m4.
+- Preserve the cached JWK Set on fetch errors in `PyJWKClient.fetch_data`.
+  The previous `finally`-block `put(None)` pattern cleared the cache on
+  any transient outage. Reported by @eddieran in GHSA-fhv5-28vv-h8m8.
+
+Fixes:
+- Reject empty HMAC keys outright in `HMACAlgorithm.prepare_key` with
+  `InvalidKeyError` instead of accepting them with only a warning.
+  Hardening prompted by reports from @SnailSploit and @spartan8806.
+- Forward per-call `options` (including `enforce_minimum_key_length`)
+  from `PyJWT.decode` through to `PyJWS._verify_signature`. Thanks to
+  @WLUB.
+- RFC 7797 §3 compliance for `b64=false`: encoder auto-adds `"b64"` to
+  `crit`; decoder rejects tokens that set `b64=false` without listing
+  it in `crit`. Thanks to @MachineLearning-Nerd.
+
+CVE: CVE-2026-48524
+Upstream-Status: Backport [https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81]
+
+Backport Changes:
+- Split out the cached-JWK-set preservation fix because the upstream
+  commit bundles multiple CVEs.
+- Omitted CHANGELOG.rst because it conflicted and is release documentation.
+- Omitted the 2.13.0 version bump and other bundled fixes; applicable CVE
+  fixes are carried in separate patches.
+
+(cherry picked from commit 95791b1759b8aa4f2203575d344d5c78564cdc81)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ jwt/jwks_client.py        | 14 ++++++++------
+ tests/test_jwks_client.py | 16 ++++++++++++++--
+ 2 files changed, 22 insertions(+), 8 deletions(-)
+
+diff --git a/jwt/jwks_client.py b/jwt/jwks_client.py
+index 8d1b0c4..41f333a 100644
+--- a/jwt/jwks_client.py
++++ b/jwt/jwks_client.py
+@@ -113,7 +113,6 @@ class PyJWKClient:
+         :returns: The parsed JWK Set as a dictionary.
+         :raises PyJWKClientConnectionError: If the HTTP request fails.
+         """
+-        jwk_set: Any = None
+         try:
+             r = urllib.request.Request(url=self.uri, headers=self.headers)
+             with urllib.request.urlopen(
+@@ -126,11 +125,14 @@ class PyJWKClient:
+             raise PyJWKClientConnectionError(
+                 f'Fail to fetch data from the url, err: "{e}"'
+             ) from e
+-        else:
+-            return jwk_set
+-        finally:
+-            if self.jwk_set_cache is not None:
+-                self.jwk_set_cache.put(jwk_set)
++
++        # Only update the cache on a successful fetch. Writing in a
++        # `finally` block with `jwk_set=None` on error clears any
++        # previously-cached JWKS, turning a transient outage into a cache
++        # wipe that breaks legitimate auth.
++        if self.jwk_set_cache is not None:
++            self.jwk_set_cache.put(jwk_set)
++        return jwk_set
+ 
+     def get_jwk_set(self, refresh: bool = False) -> PyJWKSet:
+         """Return the JWK Set, using the cache when available.
+diff --git a/tests/test_jwks_client.py b/tests/test_jwks_client.py
+index d6793cc..da68664 100644
+--- a/tests/test_jwks_client.py
++++ b/tests/test_jwks_client.py
+@@ -288,18 +288,30 @@ class TestPyJWKClient:
+ 
+         assert repeated_call.call_count == 1
+ 
+-    def test_get_jwt_set_failed_request_should_clear_cache(self) -> None:
++    def test_get_jwt_set_failed_refresh_preserves_cached_jwks(self) -> None:
++        # Regression: a transient fetch failure used to clear the cache via
++        # the previous `finally: put(jwk_set=None)` pattern, turning one bad
++        # request from the JWKS endpoint into application-wide auth failure.
++        # The cache must survive.
+         url = "https://dev-87evx9ru.auth0.com/.well-known/jwks.json"
+ 
+         jwks_client = PyJWKClient(url)
+         with mocked_success_response(RESPONSE_DATA_WITH_MATCHING_KID):
+             jwks_client.get_jwk_set()
+ 
++        assert jwks_client.jwk_set_cache is not None
++        assert jwks_client.jwk_set_cache.get() is not None
++
+         with pytest.raises(PyJWKClientError):
+             with mocked_failed_response():
+                 jwks_client.get_jwk_set(refresh=True)
+ 
+-            assert jwks_client.jwk_set_cache is None
++        cached = jwks_client.jwk_set_cache.get()
++        assert cached is not None
++        # Subsequent reads still serve from cache without another fetch.
++        with mocked_success_response(RESPONSE_DATA_WITH_MATCHING_KID) as call:
++            jwks_client.get_jwk_set()
++        assert call.call_count == 0
+ 
+     def test_failed_request_should_raise_connection_error(self) -> None:
+         token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6Ik5FRTFRVVJCT1RNNE16STVSa0ZETlRZeE9UVTFNRGcyT0Rnd1EwVXpNVGsxUWpZeVJrUkZRdyJ9.eyJpc3MiOiJodHRwczovL2Rldi04N2V2eDlydS5hdXRoMC5jb20vIiwic3ViIjoiYVc0Q2NhNzl4UmVMV1V6MGFFMkg2a0QwTzNjWEJWdENAY2xpZW50cyIsImF1ZCI6Imh0dHBzOi8vZXhwZW5zZXMtYXBpIiwiaWF0IjoxNTcyMDA2OTU0LCJleHAiOjE1NzIwMDY5NjQsImF6cCI6ImFXNENjYTc5eFJlTFdVejBhRTJINmtEME8zY1hCVnRDIiwiZ3R5IjoiY2xpZW50LWNyZWRlbnRpYWxzIn0.PUxE7xn52aTCohGiWoSdMBZGiYAHwE5FYie0Y1qUT68IHSTXwXVd6hn02HTah6epvHHVKA2FqcFZ4GGv5VTHEvYpeggiiZMgbxFrmTEY0csL6VNkX1eaJGcuehwQCRBKRLL3zKmA5IKGy5GeUnIbpPHLHDxr-GXvgFzsdsyWlVQvPX2xjeaQ217r2PtxDeqjlf66UYl6oY6AqNS8DH3iryCvIfCcybRZkc_hdy-6ZMoKT6Piijvk_aXdm7-QQqKJFHLuEqrVSOuBqqiNfVrG27QzAPuPOxvfXTVLXL2jek5meH6n-VWgrBdoMFH93QEszEDowDAEhQPHVs0xj7SIzA"
meta-python/recipes-devtools/python/python3-pyjwt_2.12.1.bb +1 -0
index e67c7bae2f..ff3eb8814d 100644
@@ -7,6 +7,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=e4b56d2c9973d8cf54655555be06e551"
 
 SRC_URI += "file://CVE-2026-48522.patch \
            file://CVE-2026-48523.patch \
+           file://CVE-2026-48524.patch \
            "
 
 SRC_URI[sha256sum] = "c74a7a2adf861c04d002db713dd85f84beb242228e671280bf709d765b03672b"
Signature · 1 line
2.35.6
#3 lore raw

PATCH 4/6 python3-pyjwt: Fix CVE-2026-48525

In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 2.13.0 backport for CVE-2026-48525. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2].

[1] https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81
[2] https://github.com/advisories/GHSA-w7vc-732c-9m39

---
 .../python/files/CVE-2026-48525.patch         | 146 ++++++++++++++++++
 .../python/python3-pyjwt_2.12.1.bb            |   1 +
 2 files changed, 147 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-48525.patch
meta-python/recipes-devtools/python/files/CVE-2026-48525.patch new file +146 -0
new file mode 100644
index 0000000000..9b7ffb97eb
@@ -0,0 +1,146 @@
+From e6152fb27dd439bf4541aab9b26a93134c48135f Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jos=C3=A9=20Padilla?= <[email protected]>
+Date: Thu, 21 May 2026 14:11:10 -0400
+Subject: [PATCH] Bundle security fixes and hardening into 2.13.0
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Security:
+- `HMACAlgorithm.prepare_key` rejects JWK JSON documents passed as raw
+  HMAC secrets to close an algorithm-confusion gap not covered by the
+  existing PEM/SSH guard. Reported by @aradona91 in GHSA-xgmm-8j9v-c9wx.
+- Bind the JWT header `alg` to `PyJWK.algorithm_name` during verification
+  so the caller's `algorithms` allow-list cannot be bypassed when decoding
+  with a `PyJWK` / `PyJWKClient` key. Reported by @sushi-gif in
+  GHSA-jq35-7prp-9v3f.
+- Skip the unconditional base64 decode of the compact-form payload
+  segment when `b64=false` is set, and require that segment to be empty
+  (RFC 7515 Appendix F detached form). Closes an unauthenticated DoS
+  amplifier. Reported by @thesmartshadow in GHSA-w7vc-732c-9m39.
+- `PyJWKClient` rejects any URI whose scheme is not `http` or `https` so
+  attacker-influenced URIs cannot read local files or reach unintended
+  schemes via urllib's default `file://` / `ftp://` / `data:` handlers.
+  Reported by @KEIJOT in GHSA-993g-76c3-p5m4.
+- Preserve the cached JWK Set on fetch errors in `PyJWKClient.fetch_data`.
+  The previous `finally`-block `put(None)` pattern cleared the cache on
+  any transient outage. Reported by @eddieran in GHSA-fhv5-28vv-h8m8.
+
+Fixes:
+- Reject empty HMAC keys outright in `HMACAlgorithm.prepare_key` with
+  `InvalidKeyError` instead of accepting them with only a warning.
+  Hardening prompted by reports from @SnailSploit and @spartan8806.
+- Forward per-call `options` (including `enforce_minimum_key_length`)
+  from `PyJWT.decode` through to `PyJWS._verify_signature`. Thanks to
+  @WLUB.
+- RFC 7797 §3 compliance for `b64=false`: encoder auto-adds `"b64"` to
+  `crit`; decoder rejects tokens that set `b64=false` without listing
+  it in `crit`. Thanks to @MachineLearning-Nerd.
+
+CVE: CVE-2026-48525
+Upstream-Status: Backport [https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81]
+
+Backport Changes:
+- Split out the b64=false payload-decoding DoS fix because the upstream
+  commit bundles multiple CVEs.
+- Omitted CHANGELOG.rst because it conflicted and is release documentation.
+- Carried the focused
+  `test_decode_b64_false_rejects_non_empty_payload_segment` regression test.
+  Omitted other tests/test_api_jws.py hunks for unrelated bundled fixes.
+- Omitted the 2.13.0 version bump and other bundled fixes; applicable CVE
+  fixes are carried in separate patches.
+
+(cherry picked from commit 95791b1759b8aa4f2203575d344d5c78564cdc81)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ jwt/api_jws.py        | 22 ++++++++++++++++++----
+ tests/test_api_jws.py | 36 +++++++++++++++++++++++++++++++++++-
+ 2 files changed, 53 insertions(+), 5 deletions(-)
+
+diff --git a/jwt/api_jws.py b/jwt/api_jws.py
+index 91d2ae3..5a91bce 100644
+--- a/jwt/api_jws.py
++++ b/jwt/api_jws.py
+@@ -317,10 +317,24 @@ class PyJWS:
+         if not isinstance(header, dict):
+             raise DecodeError("Invalid header string: must be a json object")
+ 
+-        try:
+-            payload = base64url_decode(payload_segment)
+-        except (TypeError, binascii.Error) as err:
+-            raise DecodeError("Invalid payload padding") from err
++        if header.get("b64", True) is False:
++            # Detached payload form (RFC 7515 Appendix F): the compact-form
++            # payload segment must be empty; the caller supplies the actual
++            # payload via the `detached_payload` argument in decode_complete.
++            # Skipping the base64 decode here removes an unauthenticated work
++            # amplifier — otherwise an attacker can inflate the unused
++            # segment to force CPU + memory cost before the signature is
++            # even checked.
++            if payload_segment:
++                raise DecodeError(
++                    "Payload segment must be empty when 'b64' is false."
++                )
++            payload = b""
++        else:
++            try:
++                payload = base64url_decode(payload_segment)
++            except (TypeError, binascii.Error) as err:
++                raise DecodeError("Invalid payload padding") from err
+ 
+         try:
+             signature = base64url_decode(crypto_segment)
+diff --git a/tests/test_api_jws.py b/tests/test_api_jws.py
+index 0715b9e..01de813 100644
+--- a/tests/test_api_jws.py
++++ b/tests/test_api_jws.py
+@@ -12,7 +12,7 @@ from jwt.exceptions import (
+     InvalidSignatureError,
+     InvalidTokenError,
+ )
+-from jwt.utils import base64url_decode
++from jwt.utils import base64url_decode, base64url_encode
+ from jwt.warnings import RemovedInPyjwt3Warning
+ 
+ from .utils import crypto_required, key_path, no_crypto_required
+@@ -984,6 +984,40 @@ class TestJWS:
+         assert "b64" not in msg_header_obj
+         assert msg_payload
+ 
++    def test_decode_b64_false_rejects_non_empty_payload_segment(
++        self, jws: PyJWS, payload: bytes
++    ) -> None:
++        # RFC 7515 Appendix F detached form: when b64=false, the compact-
++        # serialization payload segment must be empty. PyJWT must reject a
++        # non-empty middle segment without doing any base64-decoding work
++        # on it — that decode used to be the unauthenticated DoS amplifier.
++        secret = "secret"
++        import hmac as _hmac
++        import hashlib as _hashlib
++
++        header_obj = {
++            "typ": "JWT",
++            "alg": "HS256",
++            "b64": False,
++            "crit": ["b64"],
++        }
++        header_b64 = base64url_encode(
++            json.dumps(header_obj, separators=(",", ":")).encode()
++        )
++        # Stuff the middle segment with arbitrary attacker-controlled bytes.
++        # This should be rejected without being base64-decoded.
++        attacker_segment = b"A" * 1024
++        signing_input = b".".join([header_b64, payload])
++        sig = _hmac.new(secret.encode(), signing_input, _hashlib.sha256).digest()
++        token = b".".join(
++            [header_b64, attacker_segment, base64url_encode(sig)]
++        ).decode()
++
++        with pytest.raises(DecodeError, match="Payload segment must be empty"):
++            jws.decode(
++                token, secret, algorithms=["HS256"], detached_payload=payload
++            )
++
+     def test_decode_detached_content_without_proper_argument(self, jws: PyJWS) -> None:
+         example_jws = (
+             "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiIsImI2NCI6ZmFsc2V9"
meta-python/recipes-devtools/python/python3-pyjwt_2.12.1.bb +1 -0
index ff3eb8814d..3e68f9c0b3 100644
@@ -8,6 +8,7 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=e4b56d2c9973d8cf54655555be06e551"
 SRC_URI += "file://CVE-2026-48522.patch \
            file://CVE-2026-48523.patch \
            file://CVE-2026-48524.patch \
+           file://CVE-2026-48525.patch \
            "
 
 SRC_URI[sha256sum] = "c74a7a2adf861c04d002db713dd85f84beb242228e671280bf709d765b03672b"
Signature · 1 line
2.35.6
#4 lore raw

PATCH 5/6 python3-pyjwt: Fix CVE-2026-48526

In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 2.13.0 backport for CVE-2026-48526. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2].

[1] https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81
[2] https://github.com/advisories/GHSA-xgmm-8j9v-c9wx

---
 .../python/files/CVE-2026-48526.patch         | 126 ++++++++++++++++++
 .../python/python3-pyjwt_2.12.1.bb            |   1 +
 2 files changed, 127 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-48526.patch
meta-python/recipes-devtools/python/files/CVE-2026-48526.patch new file +126 -0
new file mode 100644
index 0000000000..00c2a55838
@@ -0,0 +1,126 @@
+From 336f1a0c18c04b63cab024b9f030af2b6c6b248c Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Jos=C3=A9=20Padilla?= <[email protected]>
+Date: Thu, 21 May 2026 14:11:10 -0400
+Subject: [PATCH] Bundle security fixes and hardening into 2.13.0
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Security:
+- `HMACAlgorithm.prepare_key` rejects JWK JSON documents passed as raw
+  HMAC secrets to close an algorithm-confusion gap not covered by the
+  existing PEM/SSH guard. Reported by @aradona91 in GHSA-xgmm-8j9v-c9wx.
+- Bind the JWT header `alg` to `PyJWK.algorithm_name` during verification
+  so the caller's `algorithms` allow-list cannot be bypassed when decoding
+  with a `PyJWK` / `PyJWKClient` key. Reported by @sushi-gif in
+  GHSA-jq35-7prp-9v3f.
+- Skip the unconditional base64 decode of the compact-form payload
+  segment when `b64=false` is set, and require that segment to be empty
+  (RFC 7515 Appendix F detached form). Closes an unauthenticated DoS
+  amplifier. Reported by @thesmartshadow in GHSA-w7vc-732c-9m39.
+- `PyJWKClient` rejects any URI whose scheme is not `http` or `https` so
+  attacker-influenced URIs cannot read local files or reach unintended
+  schemes via urllib's default `file://` / `ftp://` / `data:` handlers.
+  Reported by @KEIJOT in GHSA-993g-76c3-p5m4.
+- Preserve the cached JWK Set on fetch errors in `PyJWKClient.fetch_data`.
+  The previous `finally`-block `put(None)` pattern cleared the cache on
+  any transient outage. Reported by @eddieran in GHSA-fhv5-28vv-h8m8.
+
+Fixes:
+- Reject empty HMAC keys outright in `HMACAlgorithm.prepare_key` with
+  `InvalidKeyError` instead of accepting them with only a warning.
+  Hardening prompted by reports from @SnailSploit and @spartan8806.
+- Forward per-call `options` (including `enforce_minimum_key_length`)
+  from `PyJWT.decode` through to `PyJWS._verify_signature`. Thanks to
+  @WLUB.
+- RFC 7797 §3 compliance for `b64=false`: encoder auto-adds `"b64"` to
+  `crit`; decoder rejects tokens that set `b64=false` without listing
+  it in `crit`. Thanks to @MachineLearning-Nerd.
+
+CVE: CVE-2026-48526
+Upstream-Status: Backport [https://github.com/jpadilla/pyjwt/commit/95791b1759b8aa4f2203575d344d5c78564cdc81]
+
+Backport Changes:
+- Split out the raw JWK-as-HMAC-secret rejection because the upstream
+  commit bundles multiple CVEs.
+- Omitted CHANGELOG.rst because it conflicted and is release documentation.
+- Carried `test_hmac_prepare_key_rejects_jwk_json` and
+  `test_hmac_prepare_key_accepts_json_without_kty` regression tests covering
+  the same JWK-classification security boundary.
+- Omitted other tests/test_algorithms.py hunks for separate empty-key and
+  per-call key-length hardening.
+- Omitted the 2.13.0 version bump and other bundled fixes; applicable CVE
+  fixes are carried in separate patches.
+
+(cherry picked from commit 95791b1759b8aa4f2203575d344d5c78564cdc81)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ jwt/algorithms.py        | 20 ++++++++++++++++++++
+ tests/test_algorithms.py | 23 +++++++++++++++++++++++
+ 2 files changed, 43 insertions(+)
+
+diff --git a/jwt/algorithms.py b/jwt/algorithms.py
+index 615dcf3..cf6da45 100644
+--- a/jwt/algorithms.py
++++ b/jwt/algorithms.py
+@@ -331,6 +331,26 @@ class HMACAlgorithm(Algorithm):
+                 " should not be used as an HMAC secret."
+             )
+ 
++        # Defense against algorithm-confusion attacks: an attacker with
++        # control over the token header can force this code path by setting
++        # alg=HS*, and HMACAlgorithm is the only algorithm that accepts
++        # arbitrary bytes as a valid secret. Other algorithms reject
++        # non-key-shaped input naturally. Even a symmetric (kty=oct) JWK
++        # should be loaded via PyJWK / from_jwk rather than fed as raw JSON
++        # bytes (whose contents are not the secret material).
++        stripped = key_bytes.lstrip()
++        if stripped.startswith(b"{"):
++            try:
++                jwk_obj = json.loads(key_bytes)
++            except ValueError:
++                jwk_obj = None
++            if isinstance(jwk_obj, dict) and "kty" in jwk_obj:
++                raise InvalidKeyError(
++                    "The specified key looks like a JWK and should not be "
++                    "used directly as an HMAC secret. Load it via "
++                    "PyJWK / HMACAlgorithm.from_jwk first."
++                )
++
+         return key_bytes
+ 
+     @overload
+diff --git a/tests/test_algorithms.py b/tests/test_algorithms.py
+index 5449f3c..82659cf 100644
+--- a/tests/test_algorithms.py
++++ b/tests/test_algorithms.py
+@@ -122,6 +122,29 @@ class TestAlgorithms:
+             with pytest.raises(InvalidKeyError):
+                 algo.from_jwk(keyfile.read())
+ 
++    @pytest.mark.parametrize(
++        "jwk_file",
++        [
++            "jwk_rsa_pub.json",
++            "jwk_ec_pub_P-256.json",
++            "jwk_okp_pub_Ed25519.json",
++            "jwk_hmac.json",
++        ],
++    )
++    def test_hmac_prepare_key_rejects_jwk_json(self, jwk_file: str) -> None:
++        algo = HMACAlgorithm(HMACAlgorithm.SHA256)
++
++        with open(key_path(jwk_file)) as keyfile:
++            with pytest.raises(InvalidKeyError, match="looks like a JWK"):
++                algo.prepare_key(keyfile.read())
++
++    def test_hmac_prepare_key_accepts_json_without_kty(self) -> None:
++        # JSON that doesn't look like a JWK (no "kty") should not be misclassified.
++        algo = HMACAlgorithm(HMACAlgorithm.SHA256)
++
++        key = algo.prepare_key('{"this": "is just a json-shaped secret"}')
++        assert key == b'{"this": "is just a json-shaped secret"}'
++
+     @crypto_required
+     def test_rsa_should_parse_pem_public_key(self) -> None:
+         algo = RSAAlgorithm(RSAAlgorithm.SHA256)
meta-python/recipes-devtools/python/python3-pyjwt_2.12.1.bb +1 -0
index 3e68f9c0b3..bae7418565 100644
@@ -9,6 +9,7 @@ SRC_URI += "file://CVE-2026-48522.patch \
            file://CVE-2026-48523.patch \
            file://CVE-2026-48524.patch \
            file://CVE-2026-48525.patch \
+           file://CVE-2026-48526.patch \
            "
 
 SRC_URI[sha256sum] = "c74a7a2adf861c04d002db713dd85f84beb242228e671280bf709d765b03672b"
Signature · 1 line
2.35.6
#5 lore raw

PATCH 6/6 python3-twisted: Fix CVE-2026-42304

In reply to Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco)

From: Hetvi Thakar <[email protected]>

This patch applies the upstream 26.4.0rc2 backport for CVE-2026-42304. The upstream fix merge is referenced in [1], and the public CVE advisory is referenced in [2]. The individual backported commit links are recorded in the patch headers.

[1] https://github.com/twisted/twisted/commit/2d196123264efb0027eecfe1b430be4a9babdbd8
[2] https://github.com/advisories/GHSA-grgv-6hw6-v9g4

---
 .../python/files/CVE-2026-42304_p1.patch      | 299 ++++++++++++++++
 .../python/files/CVE-2026-42304_p2.patch      |  30 ++
 .../python/files/CVE-2026-42304_p3.patch      |  33 ++
 .../python/files/CVE-2026-42304_p4.patch      | 318 ++++++++++++++++++
 .../python/files/CVE-2026-42304_p5.patch      | 218 ++++++++++++
 .../python/files/CVE-2026-42304_p6.patch      |  23 ++
 .../python/python3-twisted_25.5.0.bb          |   8 +
 7 files changed, 929 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p1.patch
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p2.patch
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p3.patch
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p4.patch
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p5.patch
 create mode 100644 meta-python/recipes-devtools/python/files/CVE-2026-42304_p6.patch
meta-python/recipes-devtools/python/files/CVE-2026-42304_p1.patch new file +299 -0
new file mode 100644
index 0000000000..462c4a4f8c
@@ -0,0 +1,299 @@
+From a023e4192dbbdc7d8d6b391ef9b226c2cfffe97e Mon Sep 17 00:00:00 2001
+From: tomasilluminati <[email protected]>
+Date: Sun, 19 Apr 2026 05:57:33 -0300
+Subject: [PATCH] (fix): denial of service in twisted.names mitigation
+
+CVE: CVE-2026-42304
+Upstream-Status: Backport [https://github.com/twisted/twisted/commit/be71ecaa113f642f03083bd5ed33af47c59308c8]
+
+(cherry picked from commit be71ecaa113f642f03083bd5ed33af47c59308c8)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ src/twisted/names/dns.py           | 116 +++++++++++++++++++++++++----
+ src/twisted/names/test/test_dns.py |  91 ++++++++++++++++++++++
+ 2 files changed, 193 insertions(+), 14 deletions(-)
+
+diff --git a/src/twisted/names/dns.py b/src/twisted/names/dns.py
+index c7644ef50..7142d9e75 100644
+--- a/src/twisted/names/dns.py
++++ b/src/twisted/names/dns.py
+@@ -11,6 +11,7 @@ Future Plans:
+ from __future__ import annotations
+ 
+ # System imports
++import contextvars
+ import inspect
+ import random
+ import socket
+@@ -126,6 +127,7 @@ __all__ = [
+     "OP_UPDATE",
+     "PORT",
+     "AuthoritativeDomainError",
++    "DNSDecodeError",
+     "DNSQueryTimeoutError",
+     "DomainError",
+ ]
+@@ -444,6 +446,64 @@ def readPrecisely(file, l):
+     return buff
+ 
+ 
++# Cap the total number of compression-pointer dereferences performed while
++# decoding a single DNS message.  A hostile peer can otherwise craft a packet
++# in which every record name chases a long compression chain, forcing O(N*M)
++# work and stalling the reactor.
++MAX_COMPRESSION_POINTERS_PER_MESSAGE = 1000
++
++
++class DNSDecodeError(ValueError):
++    """
++    Raised when a DNS message cannot be decoded because it violates a
++    protocol-level safety limit
++    """
++
++
++class _DecodeContext:
++    """
++    Mutable state shared between the L{IEncodable} decoders invoked while
++    reading a single DNS message.
++
++    The primary purpose is to bound the total number of compression-pointer
++    jumps taken across every name in the message, defending against packets
++    that fan out thousands of records pointing to deeply chained pointers.
++
++    @ivar jumps: The number of compression pointers followed so far.
++    @ivar maxJumps: The inclusive upper bound on C{jumps}.  Exceeding it
++        causes L{registerJump} to raise L{DNSDecodeError}.
++    """
++
++    __slots__ = ("jumps", "maxJumps")
++
++    def __init__(self, maxJumps: int = MAX_COMPRESSION_POINTERS_PER_MESSAGE) -> None:
++        self.jumps = 0
++        self.maxJumps = maxJumps
++
++    def registerJump(self) -> None:
++        """
++        Record that a compression pointer has been followed
++
++        @raise DNSDecodeError: if the cumulative number of jumps exceeds
++            L{maxJumps}
++        """
++        self.jumps += 1
++        if self.jumps > self.maxJumps:
++            raise DNSDecodeError(
++                "Too many compression pointers while decoding DNS message "
++                f"(limit is {self.maxJumps})"
++            )
++
++
++# Tracks state across nested calls without altering every record's signature.
++# L{Message.decode} manages the lifecycle per-message, while standalone decoders
++# default to a local context when C{_decodeContextVar} is C{None}
++
++_decodeContextVar: contextvars.ContextVar[_DecodeContext | None] = (
++    contextvars.ContextVar("_dnsDecodeContext", default=None)
++)
++
++
+ class IEncodable(Interface):
+     """
+     Interface for something which can be encoded to and decoded
+@@ -591,7 +651,7 @@ class Name:
+             strio.write(label)
+         strio.write(b"\x00")
+ 
+-    def decode(self, strio, length=None):
++    def decode(self, strio, length=None, context=None):
+         """
+         Decode a byte string into this Name.
+ 
+@@ -599,12 +659,27 @@ class Name:
+         @param strio: Bytes will be read from this file until the full Name
+         is decoded.
+ 
++        @type context: L{_DecodeContext} or L{None}
++        @param context: Shared decoding state used to cap the total number
++            of compression-pointer jumps taken while decoding the enclosing
++            DNS message.  When L{None}, the context installed by
++            L{Message.decode} is used if one is active; otherwise a fresh,
++            call-local context is created so that direct callers remain
++            protected and backwards compatible.
++
+         @raise EOFError: Raised when there are not enough bytes available
+         from C{strio}.
+ 
+-        @raise ValueError: Raised when the name cannot be decoded (for example,
+-            because it contains a loop).
++        @raise ValueError: Raised when the name cannot be decoded because it
++            contains a compression loop.
++
++        @raise DNSDecodeError: Raised when the cumulative number of
++            compression-pointer jumps exceeds the configured limit.
+         """
++        if context is None:
++            context = _decodeContextVar.get()
++            if context is None:
++                context = _DecodeContext()
+         visited = set()
+         self.name = b""
+         off = 0
+@@ -616,6 +691,7 @@ class Name:
+                 return
+             if (l >> 6) == 3:
+                 new_off = (l & 63) << 8 | ord(readPrecisely(strio, 1))
++                context.registerJump()
+                 if new_off in visited:
+                     raise ValueError("Compression loop in encoded name")
+                 visited.add(new_off)
+@@ -2704,19 +2780,31 @@ class Message(tputil.FancyEqMixin):
+         self.checkingDisabled = (byte4 >> 4) & 1
+         self.rCode = byte4 & 0xF
+ 
+-        self.queries = []
+-        for i in range(nqueries):
+-            q = Query()
+-            try:
+-                q.decode(strio)
+-            except EOFError:
+-                return
+-            self.queries.append(q)
++        # A single shared counter bounds the total compression-pointer work
++        # performed across every name in this message.  It is installed on
++        # the context variable so nested record decoders pick it up without
++        # needing to thread it through each signature.
++        token = _decodeContextVar.set(_DecodeContext())
++        try:
++            self.queries = []
++            for i in range(nqueries):
++                q = Query()
++                try:
++                    q.decode(strio)
++                except EOFError:
++                    return
++                self.queries.append(q)
+ 
+-        items = ((self.answers, nans), (self.authority, nns), (self.additional, nadd))
++            items = (
++                (self.answers, nans),
++                (self.authority, nns),
++                (self.additional, nadd),
++            )
+ 
+-        for l, n in items:
+-            self.parseRecords(l, n, strio)
++            for l, n in items:
++                self.parseRecords(l, n, strio)
++        finally:
++            _decodeContextVar.reset(token)
+ 
+     def parseRecords(self, list, num, strio):
+         for i in range(num):
+diff --git a/src/twisted/names/test/test_dns.py b/src/twisted/names/test/test_dns.py
+index 3b8f6e130..9b27c4b3a 100644
+--- a/src/twisted/names/test/test_dns.py
++++ b/src/twisted/names/test/test_dns.py
+@@ -352,6 +352,60 @@ class NameTests(unittest.TestCase):
+         stream = BytesIO(b"\xc0\x00")
+         self.assertRaises(ValueError, name.decode, stream)
+ 
++    def test_rejectTooManyCompressionPointers(self):
++        """
++        L{Name.decode} raises L{dns.DNSDecodeError} when the number of
++        compression-pointer dereferences taken for a single message exceeds
++        the limit carried by the shared L{dns._DecodeContext}.
++        """
++        # Five distinct pointers chained end-to-end, terminated by a zero
++        # label byte.  With a maxJumps of three the fourth dereference must
++        # trip the safety limit.
++        payload = b"\xc0\x02\xc0\x04\xc0\x06\xc0\x08\x00"
++        context = dns._DecodeContext(maxJumps=3)
++        self.assertRaises(
++            dns.DNSDecodeError,
++            dns.Name().decode,
++            BytesIO(payload),
++            None,
++            context,
++        )
++
++    def test_compressionPointerCounterIsShared(self):
++        """
++        The L{dns._DecodeContext} counter accumulates across successive
++        L{Name.decode} calls, so that a message whose individual names are
++        each within bounds is still rejected when their aggregate exceeds
++        the configured limit.
++        """
++        payload = b"\xc0\x02\xc0\x04\x00"
++        context = dns._DecodeContext(maxJumps=3)
++
++        stream = BytesIO(payload)
++        dns.Name().decode(stream, context=context)
++        self.assertEqual(context.jumps, 2)
++
++        stream.seek(0)
++        self.assertRaises(
++            dns.DNSDecodeError,
++            dns.Name().decode,
++            stream,
++            None,
++            context,
++        )
++
++    def test_decodeWithoutContextIsBackwardsCompatible(self):
++        """
++        L{Name.decode} continues to work when called without a context,
++        using a fresh per-call counter so existing callers are unaffected.
++        """
++        name = dns.Name()
++        stream = BytesIO()
++        dns.Name(b"example.org").encode(stream)
++        stream.seek(0)
++        name.decode(stream)
++        self.assertEqual(name.name, b"example.org")
++
+     def test_equality(self):
+         """
+         L{Name} instances are equal as long as they have the same value for
+@@ -761,6 +815,43 @@ class MessageTests(unittest.SynchronousTestCase):
+         """
+         self.assertEqual(dns.Message().authenticData, 0)
+ 
++    def test_rejectCompressionPointerFlood(self):
++        """
++        L{Message.decode} installs a shared compression-pointer counter and
++        raises L{dns.DNSDecodeError} when the aggregate number of pointer
++        dereferences across every record in the message exceeds
++        L{dns.MAX_COMPRESSION_POINTERS_PER_MESSAGE}.
++        """
++        chainLength = 100
++        numRecords = 8000
++        header = struct.pack(
++            "!H2B4H", 0x1234, 0x80, 0x00, 0, numRecords, 0, 0
++        )
++
++        # Long compression chain inside the RDATA of an unknown
++        # record so that subsequent records can aim pointers at it.
++        owner = b"\x04rrrr\x00"
++        chainBase = len(header) + len(owner) + 10
++        chain = bytearray()
++        for i in range(chainLength):
++            chain += struct.pack("!H", 0xC000 | (chainBase + 2 * (i + 1)))
++        chain += b"\x04test\x00"
++
++        firstRecord = (
++            owner
++            + struct.pack("!HHIH", 999, 1, 0, len(chain))
++            + bytes(chain)
++        )
++        followupRecord = (
++            struct.pack("!H", 0xC000 | chainBase)
++            + struct.pack("!HHIH", 1, 1, 0, 4)
++            + b"\x00\x00\x00\x00"
++        )
++        payload = header + firstRecord + followupRecord * (numRecords - 1)
++
++        message = dns.Message()
++        self.assertRaises(dns.DNSDecodeError, message.decode, BytesIO(payload))
++
+     def test_authenticDataOverride(self):
+         """
+         L{dns.Message.__init__} accepts a C{authenticData} argument which
meta-python/recipes-devtools/python/files/CVE-2026-42304_p2.patch new file +30 -0
new file mode 100644
index 0000000000..2c5490c190
@@ -0,0 +1,30 @@
+From 094d33d4073368ab1a85fcf63e3b75addb01fd6a Mon Sep 17 00:00:00 2001
+From: Tomas Illuminati Balbin <[email protected]>
+Date: Mon, 20 Apr 2026 09:17:13 -0300
+Subject: [PATCH] Update src/twisted/names/dns.py
+
+Co-authored-by: Adi Roiban <[email protected]>
+
+CVE: CVE-2026-42304
+Upstream-Status: Backport [https://github.com/twisted/twisted/commit/86e1b5490de5baa8ca284d1e6f4f0ade3e8ad7e0]
+
+(cherry picked from commit 86e1b5490de5baa8ca284d1e6f4f0ade3e8ad7e0)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ src/twisted/names/dns.py | 3 +--
+ 1 file changed, 1 insertion(+), 2 deletions(-)
+
+diff --git a/src/twisted/names/dns.py b/src/twisted/names/dns.py
+index 7142d9e75..93e4080bf 100644
+--- a/src/twisted/names/dns.py
++++ b/src/twisted/names/dns.py
+@@ -2784,8 +2784,7 @@ class Message(tputil.FancyEqMixin):
+         # performed across every name in this message.  It is installed on
+         # the context variable so nested record decoders pick it up without
+         # needing to thread it through each signature.
+-        token = _decodeContextVar.set(_DecodeContext())
+-        try:
++        with _decodeContextVar.set(_DecodeContext()):
+             self.queries = []
+             for i in range(nqueries):
+                 q = Query()
meta-python/recipes-devtools/python/files/CVE-2026-42304_p3.patch new file +33 -0
new file mode 100644
index 0000000000..9b04562ca3
@@ -0,0 +1,33 @@
+From 7213b262b9c98fe6d522dbd23fd83bb9535b54c6 Mon Sep 17 00:00:00 2001
+From: Tomas Illuminati Balbin <[email protected]>
+Date: Mon, 20 Apr 2026 09:18:05 -0300
+Subject: [PATCH] Update src/twisted/names/test/test_dns.py
+
+Co-authored-by: Adi Roiban <[email protected]>
+
+CVE: CVE-2026-42304
+Upstream-Status: Backport [https://github.com/twisted/twisted/commit/c75d44ed81b47f8086ed801cfcdb2568b0b32301]
+
+(cherry picked from commit c75d44ed81b47f8086ed801cfcdb2568b0b32301)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ src/twisted/names/test/test_dns.py | 6 +++---
+ 1 file changed, 3 insertions(+), 3 deletions(-)
+
+diff --git a/src/twisted/names/test/test_dns.py b/src/twisted/names/test/test_dns.py
+index 9b27c4b3a..94aa4a802 100644
+--- a/src/twisted/names/test/test_dns.py
++++ b/src/twisted/names/test/test_dns.py
+@@ -389,9 +389,9 @@ class NameTests(unittest.TestCase):
+         self.assertRaises(
+             dns.DNSDecodeError,
+             dns.Name().decode,
+-            stream,
+-            None,
+-            context,
++            strio=stream,
++            length=None,
++            context=context,
+         )
+ 
+     def test_decodeWithoutContextIsBackwardsCompatible(self):
meta-python/recipes-devtools/python/files/CVE-2026-42304_p4.patch new file +318 -0

318 lines not on this page · raw message

meta-python/recipes-devtools/python/files/CVE-2026-42304_p5.patch new file +218 -0

218 lines not on this page · raw message

meta-python/recipes-devtools/python/files/CVE-2026-42304_p6.patch new file +23 -0
new file mode 100644
index 0000000000..2df57691e9
@@ -0,0 +1,23 @@
+From 2dc37caa8af3559e14fc1a1b36b049851d36943c Mon Sep 17 00:00:00 2001
+From: Adi Roiban <[email protected]>
+Date: Wed, 29 Apr 2026 15:55:05 +0100
+Subject: [PATCH] Update src/twisted/names/newsfragments/12626.bugfix
+
+CVE: CVE-2026-42304
+Upstream-Status: Backport [https://github.com/twisted/twisted/commit/9ca319ebf61386dd33354c4ade3946ef84ad58fb]
+
+(cherry picked from commit 9ca319ebf61386dd33354c4ade3946ef84ad58fb)
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ src/twisted/names/newsfragments/12626.bugfix | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/src/twisted/names/newsfragments/12626.bugfix b/src/twisted/names/newsfragments/12626.bugfix
+index 44896c3e5..179b92d83 100644
+--- a/src/twisted/names/newsfragments/12626.bugfix
++++ b/src/twisted/names/newsfragments/12626.bugfix
+@@ -1 +1 @@
+-twisted.names was fix for Denial of Service (DoS) attack via resource exhaustion during DNS name decompression. CVE-REFERENCE HERE
+\ No newline at end of file
++twisted.names was fix for Denial of Service (DoS) attack via resource exhaustion during DNS name decompression. CVE-2026-42304
+\ No newline at end of file
meta-python/recipes-devtools/python/python3-twisted_25.5.0.bb +8 -0
index 8ce5740e0b..3b49f56093 100644
@@ -6,6 +6,14 @@ HOMEPAGE = "https://twisted.org"
 LICENSE = "MIT"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=5316a448a61a38d722c291f78d915d11"
 
+SRC_URI += "file://CVE-2026-42304_p1.patch \
+           file://CVE-2026-42304_p2.patch \
+           file://CVE-2026-42304_p3.patch \
+           file://CVE-2026-42304_p4.patch \
+           file://CVE-2026-42304_p5.patch \
+           file://CVE-2026-42304_p6.patch \
+           "
+
 SRC_URI[sha256sum] = "1deb272358cb6be1e3e8fc6f9c8b36f78eb0fa7c2233d2dbe11ec6fee04ea316"
 
 CVE_PRODUCT = "twisted"
Signature · 1 line
2.35.6