diff mbox series

[meta-python,wrynose,1/4] python3-oauthlib: fix CVE-2026-49265

Message ID 20261120034618.604880-1-hthakar@cisco.com
State New
Headers show
Series [meta-python,wrynose,1/4] python3-oauthlib: fix CVE-2026-49265 | expand

Commit Message

From: Hetvi Thakar <hthakar@cisco.com>

The plain and S256 PKCE checks use ordinary string equality, exposing
verifier/challenge comparisons to prefix-dependent timing differences.

Backport upstream fix [1], referenced by NVD [2] and Debian [3], to use
hmac.compare_digest for constant-time comparison in OAuthLib 3.3.1.

Include upstream follow-up [4] to compare UTF-8 bytes and avoid an
uncaught TypeError for non-ASCII input. Retain its regressions and add
token-endpoint coverage confirming that a verifier mismatch returns
HTTP 400 invalid_grant without issuing a token.

Omit the CHANGELOG.rst update because its newer release-note context
is absent from the 3.3.1 source.

[1] https://github.com/oauthlib/oauthlib/commit/74664d3fe037a354e180e305135c6bab1747a6b0
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-49265
[3] https://security-tracker.debian.org/tracker/CVE-2026-49265
[4] https://github.com/oauthlib/oauthlib/commit/9cf6654bf44bbd47a9187b9204a2c2503a7c97d3

Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
---
 .../python3-oauthlib/CVE-2026-49265_p1.patch  |  51 +++++++
 .../python3-oauthlib/CVE-2026-49265_p2.patch  | 129 ++++++++++++++++++
 .../python/python3-oauthlib_3.3.1.bb          |   5 +
 3 files changed, 185 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p1.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p2.patch
diff mbox series

Patch

diff --git a/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p1.patch b/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p1.patch
new file mode 100644
index 0000000000..b8e74be40c
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p1.patch
@@ -0,0 +1,51 @@ 
+From 74664d3fe037a354e180e305135c6bab1747a6b0 Mon Sep 17 00:00:00 2001
+From: Jonathan Huot <jonathan.huot@gmail.com>
+Date: Sat, 11 Jul 2026 13:15:29 +0200
+Subject: [PATCH] Improve PKCE code comparison
+
+CVE: CVE-2026-49265
+Upstream-Status: Backport [https://github.com/oauthlib/oauthlib/commit/74664d3fe037a354e180e305135c6bab1747a6b0]
+
+Backport Changes:
+- Omit CHANGELOG.rst because its newer release-note context is
+  absent from the 3.3.1 source.
+
+Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
+---
+ oauthlib/oauth2/rfc6749/grant_types/authorization_code.py | 8 +++++---
+ 1 file changed, 5 insertions(+), 3 deletions(-)
+
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+index 09dc619988941ea1dd83e15b4b4f11689b45bb36..c73314ac31a8d5523519fac5aef8a2b2728ec757 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+@@ -4,6 +4,7 @@ oauthlib.oauth2.rfc6749.grant_types
+ """
+ import base64
+ import hashlib
++import hmac
+ import json
+ import logging
+ 
+@@ -44,9 +45,10 @@ def code_challenge_method_s256(verifier, challenge):
+ 
+     .. _`Section 4.3`: https://tools.ietf.org/html/rfc7636#section-4.3
+     """
+-    return base64.urlsafe_b64encode(
++    expected = base64.urlsafe_b64encode(
+         hashlib.sha256(verifier.encode()).digest()
+-    ).decode().rstrip('=') == challenge
++    ).decode().rstrip('=')
++    return hmac.compare_digest(expected, challenge)
+ 
+ 
+ def code_challenge_method_plain(verifier, challenge):
+@@ -58,7 +60,7 @@ def code_challenge_method_plain(verifier, challenge):
+ 
+     .. _`Section 4.3`: https://tools.ietf.org/html/rfc7636#section-4.3
+     """
+-    return verifier == challenge
++    return hmac.compare_digest(verifier, challenge)
+ 
+ 
+ class AuthorizationCodeGrant(GrantTypeBase):
diff --git a/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p2.patch b/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p2.patch
new file mode 100644
index 0000000000..1ecadbf9f9
--- /dev/null
+++ b/meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p2.patch
@@ -0,0 +1,129 @@ 
+From 9cf6654bf44bbd47a9187b9204a2c2503a7c97d3 Mon Sep 17 00:00:00 2001
+From: Vibe Nuage Agent <vibe@mistral.ai>
+Date: Tue, 6 Oct 2026 18:03:18 +0000
+Subject: [PATCH] Fix PKCE comparison raising on non-ASCII input
+
+Encode both operands to UTF-8 bytes before hmac.compare_digest so
+any unicode string compares correctly (github issue #988).
+
+CVE: CVE-2026-49265
+Upstream-Status: Backport [https://github.com/oauthlib/oauthlib/commit/9cf6654bf44bbd47a9187b9204a2c2503a7c97d3]
+
+Backport Changes:
+- Add a token-endpoint regression confirming that a non-ASCII plain
+  verifier mismatch returns HTTP 400 invalid_grant without issuing a token.
+
+Co-authored-by: JonathanHuot <JonathanHuot@users.noreply.github.com>
+Signed-off-by: Hetvi Thakar <hthakar@cisco.com>
+---
+ .../rfc6749/grant_types/authorization_code.py      |  4 +-
+ .../rfc6749/grant_types/test_authorization_code.py | 63 +++++++++++++++++++++-
+ 2 files changed, 64 insertions(+), 3 deletions(-)
+
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+index c73314ac31a8d5523519fac5aef8a2b2728ec757..bde7cc97ee7effbf6161c3f7559bcae76eeac8d0 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+@@ -48,7 +48,7 @@ def code_challenge_method_s256(verifier, challenge):
+     expected = base64.urlsafe_b64encode(
+         hashlib.sha256(verifier.encode()).digest()
+     ).decode().rstrip('=')
+-    return hmac.compare_digest(expected, challenge)
++    return hmac.compare_digest(expected.encode(), challenge.encode())
+ 
+ 
+ def code_challenge_method_plain(verifier, challenge):
+@@ -60,7 +60,7 @@ def code_challenge_method_plain(verifier, challenge):
+ 
+     .. _`Section 4.3`: https://tools.ietf.org/html/rfc7636#section-4.3
+     """
+-    return hmac.compare_digest(verifier, challenge)
++    return hmac.compare_digest(verifier.encode(), challenge.encode())
+ 
+ 
+ class AuthorizationCodeGrant(GrantTypeBase):
+diff --git a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
+index 77e1a81b462a46ecea665fd8c5de6999d5707119..c05fdb9af33b2379a9c9cb3c1bddba4f80fe47f2 100644
+--- a/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
++++ b/tests/oauth2/rfc6749/grant_types/test_authorization_code.py
+@@ -2,8 +2,9 @@
+ import json
+ from unittest import mock
+ 
+-from oauthlib.common import Request
++from oauthlib.common import Request, urlencode
+ from oauthlib.oauth2.rfc6749 import errors
++from oauthlib.oauth2.rfc6749.endpoints import TokenEndpoint
+ from oauthlib.oauth2.rfc6749.grant_types import (
+     AuthorizationCodeGrant, authorization_code,
+ )
+@@ -306,9 +307,69 @@ class AuthorizationCodeGrantTest(TestCase):
+     def test_correct_code_challenge_method_plain(self):
+         self.assertTrue(authorization_code.code_challenge_method_plain("foo", "foo"))
+ 
++    def test_plain_non_ascii_verifier_matches_non_ascii_challenge(self):
++        # Regression test: non-ASCII values previously raised TypeError
++        # from hmac.compare_digest, causing a server error instead of
++        # invalid_grant. (github issue #988)
++        self.assertTrue(
++            authorization_code.code_challenge_method_plain("verifier-\u00e9", "verifier-\u00e9"))
++        self.assertFalse(
++            authorization_code.code_challenge_method_plain("verifier-\u00e9", "verifier"))
++        self.assertFalse(
++            authorization_code.code_challenge_method_plain("verifier", "verifier-\u00e9"))
++
++    def test_plain_invalid_types_raise(self):
++        # A RequestValidator.get_code_challenge implementation returning
++        # a non-string is a server implementation error and must surface
++        # as such, not as invalid_grant.
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_plain, None, "foo")
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_plain, "foo", None)
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_plain, "foo", {"a": 1})
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_plain, 42, "foo")
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_plain, b"foo", "foo")
++
++    def test_plain_non_ascii_verifier_returns_invalid_grant(self):
++        self.mock_validator.is_pkce_required.return_value = True
++        self.mock_validator.get_code_challenge.return_value = "stored-challenge"
++        self.mock_validator.get_code_challenge_method.return_value = "plain"
++        endpoint = TokenEndpoint(
++            default_grant_type="authorization_code",
++            default_token_type=BearerToken(self.mock_validator),
++            grant_types={"authorization_code": self.auth},
++        )
++        body = urlencode([
++            ("grant_type", "authorization_code"),
++            ("client_id", "abcdef"),
++            ("code", "1234"),
++            ("redirect_uri", "https://a.b/cb"),
++            ("code_verifier", "verifier-\u00e9"),
++        ])
++
++        _, response, status = endpoint.create_token_response(
++            "https://a.b/token", body=body)
++
++        self.assertEqual(status, 400)
++        self.assertEqual(json.loads(response)["error"], "invalid_grant")
++        self.mock_validator.save_bearer_token.assert_not_called()
++
+     def test_wrong_code_challenge_method_s256(self):
+         self.assertFalse(authorization_code.code_challenge_method_s256("foo", "bar"))
+ 
++    def test_s256_non_ascii_verifier_does_not_raise(self):
++        self.assertFalse(
++            authorization_code.code_challenge_method_s256("verifier-\u00e9", "foo"))
++
++    def test_s256_invalid_types_raise(self):
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_s256, None, "foo")
++        self.assertRaises((AttributeError, TypeError),
++                          authorization_code.code_challenge_method_s256, "foo", 42)
++
+     def test_correct_code_challenge_method_s256(self):
+         # "abcd" as verifier gives a '+' to base64
+         self.assertTrue(
diff --git a/meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb b/meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb
index bdc1f0e7b4..0974020a17 100644
--- a/meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb
+++ b/meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb
@@ -4,6 +4,11 @@  HOMEPAGE = "https://github.com/idan/oauthlib"
 LICENSE = "BSD-3-Clause"
 LIC_FILES_CHKSUM = "file://LICENSE;md5=2699a9fb0d71d5eafd75d8d7c302f7df"
 
+SRC_URI += " \
+    file://CVE-2026-49265_p1.patch \
+    file://CVE-2026-49265_p2.patch \
+"
+
 SRC_URI[sha256sum] = "0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9"
 
 CVE_PRODUCT = "oauthlib"