Skip to contentSkip to conversation

python3-oauthlib: fix CVE-2026-49265

PATCH New Hetvi Thakar -X (hthakar - E INFOCHIPS PRIVATE LIMITED at Cisco) 1 participant 4 messages Nov 20

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 python3-oauthlib: fix CVE-2026-49265

From: Hetvi Thakar <[email protected]>

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

---
 .../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
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p1.patch new file +51 -0
new file mode 100644
index 0000000000..b8e74be40c
@@ -0,0 +1,51 @@
+From 74664d3fe037a354e180e305135c6bab1747a6b0 Mon Sep 17 00:00:00 2001
+From: Jonathan Huot <[email protected]>
+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 <[email protected]>
+---
+ 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):
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49265_p2.patch new file +129 -0

129 lines not on this page · raw message

meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb +5 -0
index bdc1f0e7b4..0974020a17 100644
@@ -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"
Signature · 1 line
2.35.6
#1 lore raw

PATCH 2/4 python3-oauthlib: fix CVE-2026-49264

From: Hetvi Thakar <[email protected]>

When enable_jsonp=True, the token revocation endpoint reflects an unvalidated callback into its responses. Applications loading these responses as trusted JSONP can execute attacker-controlled JavaScript.

Backport upstream fix [1], referenced by NVD [2] and Debian [3], to remove JSONP support from token revocation in OAuthLib 3.3.1.

Include upstream follow-up [4] to reject callback passed through keyword arguments, including callback=None, and retain its regression tests. 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/c888359f3c42bec235b2c5caab2069c9ed62457c
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-49264
[3] https://security-tracker.debian.org/tracker/CVE-2026-49264
[4] https://github.com/oauthlib/oauthlib/commit/8f7db807dfeabc69386b4b67b14bb10c9efe56c8

---
 .../python3-oauthlib/CVE-2026-49264_p1.patch  | 200 ++++++++++++++++++
 .../python3-oauthlib/CVE-2026-49264_p2.patch  |  50 +++++
 .../python/python3-oauthlib_3.3.1.bb          |   2 +
 3 files changed, 252 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49264_p1.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49264_p2.patch
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49264_p1.patch new file +200 -0
new file mode 100644
index 0000000000..e336f9b6a7
@@ -0,0 +1,200 @@
+From c888359f3c42bec235b2c5caab2069c9ed62457c Mon Sep 17 00:00:00 2001
+From: Jonathan Huot <[email protected]>
+Date: Fri, 22 May 2026 19:51:42 +0000
+Subject: [PATCH] Remove JSONP support from token revocation
+
+JSONP was useful in the past for cross-origin requests but has been
+superseded by CORS browser protections. This change removes the outdated
+JSONP functionality.
+
+Breaking changes:
+- Remove enable_jsonp parameter from RevocationEndpoint
+- Remove callback parameter from prepare_token_revocation_request
+- Remove JSONP documentation and examples
+- Remove JSONP tests
+
+The token revocation endpoint now returns empty response bodies on
+success instead of JSONP-wrapped responses.
+
+CVE: CVE-2026-49264
+Upstream-Status: Backport [https://github.com/oauthlib/oauthlib/commit/c888359f3c42bec235b2c5caab2069c9ed62457c]
+
+Backport Changes:
+- Omit the CHANGELOG.rst hunk because its later WIP section is absent
+  from 3.3.1. Retain all upstream code, documentation and test changes.
+
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ oauthlib/oauth2/rfc6749/clients/base.py            | 24 ++--------------------
+ oauthlib/oauth2/rfc6749/endpoints/revocation.py    | 11 ++--------
+ oauthlib/oauth2/rfc6749/parameters.py              |  8 ++------
+ tests/oauth2/rfc6749/clients/test_base.py          |  7 -------
+ .../rfc6749/endpoints/test_revocation_endpoint.py  | 13 ------------
+ 5 files changed, 6 insertions(+), 57 deletions(-)
+
+diff --git a/oauthlib/oauth2/rfc6749/clients/base.py b/oauthlib/oauth2/rfc6749/clients/base.py
+index 17f833d236cb0f1ca7a4dd85f661b2e6be6b087e..cdbbc191f75393d8e17fbcd852987bb45dd9c0df 100644
+--- a/oauthlib/oauth2/rfc6749/clients/base.py
++++ b/oauthlib/oauth2/rfc6749/clients/base.py
+@@ -320,7 +320,7 @@ class Client:
+         return token_url, FORM_ENC_HEADERS, body
+ 
+     def prepare_token_revocation_request(self, revocation_url, token,
+-                                         token_type_hint="access_token", body='', callback=None, **kwargs):
++                                         token_type_hint="access_token", body='', **kwargs):
+         """Prepare a token revocation request.
+ 
+         :param revocation_url: Provider token revocation endpoint URL.
+@@ -329,14 +329,9 @@ class Client:
+             ``"refresh_token"``. This is optional and if you wish to not pass it you
+             must provide ``token_type_hint=None``.
+         :param body:
+-        :param callback: A jsonp callback such as ``package.callback`` to be invoked
+-            upon receiving the response. Not that it should not include a () suffix.
+         :param kwargs: Additional parameters to included in the request.
+         :returns: The prepared request tuple with (url, headers, body).
+ 
+-        Note that JSONP request may use GET requests as the parameters will
+-        be added to the request URL query as opposed to the request body.
+-
+         An example of a revocation request
+ 
+         .. code-block:: http
+@@ -348,21 +343,6 @@ class Client:
+ 
+             token=45ghiukldjahdnhzdauz&token_type_hint=refresh_token
+ 
+-        An example of a jsonp revocation request
+-
+-        .. code-block:: http
+-
+-            GET /revoke?token=agabcdefddddafdd&callback=package.myCallback HTTP/1.1
+-            Host: server.example.com
+-            Content-Type: application/x-www-form-urlencoded
+-            Authorization: Basic czZCaGRSa3F0MzpnWDFmQmF0M2JW
+-
+-        and an error response
+-
+-        .. code-block:: javascript
+-
+-            package.myCallback({"error":"unsupported_token_type"});
+-
+         Note that these requests usually require client credentials, client_id in
+         the case for public clients and provider specific authentication
+         credentials for confidential clients.
+@@ -371,7 +351,7 @@ class Client:
+             raise InsecureTransportError()
+ 
+         return prepare_token_revocation_request(revocation_url, token,
+-                                                token_type_hint=token_type_hint, body=body, callback=callback,
++                                                token_type_hint=token_type_hint, body=body,
+                                                 **kwargs)
+ 
+     def parse_request_body_response(self, body, scope=None, **kwargs):
+diff --git a/oauthlib/oauth2/rfc6749/endpoints/revocation.py b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
+index 596d0860fae67017a86b1042fcf9edb674fdf38d..06b450a43fa7c9b74c293b0cbade270629c0a9f1 100644
+--- a/oauthlib/oauth2/rfc6749/endpoints/revocation.py
++++ b/oauthlib/oauth2/rfc6749/endpoints/revocation.py
+@@ -27,13 +27,11 @@ class RevocationEndpoint(BaseEndpoint):
+     valid_token_types = ('access_token', 'refresh_token')
+     valid_request_methods = ('POST',)
+ 
+-    def __init__(self, request_validator, supported_token_types=None,
+-            enable_jsonp=False):
++    def __init__(self, request_validator, supported_token_types=None):
+         BaseEndpoint.__init__(self)
+         self.request_validator = request_validator
+         self.supported_token_types = (
+             supported_token_types or self.valid_token_types)
+-        self.enable_jsonp = enable_jsonp
+ 
+     @catch_errors_and_unavailability
+     def create_revocation_response(self, uri, http_method='POST', body=None,
+@@ -69,18 +67,13 @@ class RevocationEndpoint(BaseEndpoint):
+         except OAuth2Error as e:
+             log.debug('Client error during validation of %r. %r.', request, e)
+             response_body = e.json
+-            if self.enable_jsonp and request.callback:
+-                response_body = '{}({});'.format(request.callback, response_body)
+             resp_headers.update(e.headers)
+             return resp_headers, response_body, e.status_code
+ 
+         self.request_validator.revoke_token(request.token,
+                                             request.token_type_hint, request)
+ 
+-        response_body = ''
+-        if self.enable_jsonp and request.callback:
+-            response_body = request.callback + '();'
+-        return {}, response_body, 200
++        return {}, '', 200
+ 
+     def validate_revocation_request(self, request):
+         """Ensure the request is valid.
+diff --git a/oauthlib/oauth2/rfc6749/parameters.py b/oauthlib/oauth2/rfc6749/parameters.py
+index 8268ef927cc2d174f44a00e60cf07156fb223db7..b912e447b817c7ed125900f4e5c455ff416cb6d2 100644
+--- a/oauthlib/oauth2/rfc6749/parameters.py
++++ b/oauthlib/oauth2/rfc6749/parameters.py
+@@ -172,7 +172,7 @@ def prepare_token_request(grant_type, body='', include_client_id=True, code_veri
+ 
+ 
+ def prepare_token_revocation_request(url, token, token_type_hint="access_token",
+-        callback=None, body='', **kwargs):
++        body='', **kwargs):
+     """Prepare a token revocation request.
+ 
+     The client constructs the request by including the following parameters
+@@ -222,11 +222,7 @@ def prepare_token_revocation_request(url, token, token_type_hint="access_token",
+ 
+     headers = {'Content-Type': 'application/x-www-form-urlencoded'}
+ 
+-    if callback:
+-        params.append(('callback', callback))
+-        return add_params_to_uri(url, params), headers, body
+-    else:
+-        return url, headers, add_params_to_qs(body, params)
++    return url, headers, add_params_to_qs(body, params)
+ 
+ 
+ def parse_authorization_code_response(uri, state=None):
+diff --git a/tests/oauth2/rfc6749/clients/test_base.py b/tests/oauth2/rfc6749/clients/test_base.py
+index b0970f2d46a5f053ad7100ebda3f09bc27bc5281..d01a1dbdcc4232eacb8dafbf6f81c871f641aa35 100644
+--- a/tests/oauth2/rfc6749/clients/test_base.py
++++ b/tests/oauth2/rfc6749/clients/test_base.py
+@@ -237,13 +237,6 @@ class ClientTest(TestCase):
+         self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
+         self.assertEqual(b, 'token=%s&token_type_hint=refresh_token' % token)
+ 
+-        # JSONP
+-        u, h, b = client.prepare_token_revocation_request(
+-            url, token, callback='hello.world')
+-        self.assertURLEqual(u, url + '?callback=hello.world&token=%s&token_type_hint=access_token' % token)
+-        self.assertEqual(h, {'Content-Type': 'application/x-www-form-urlencoded'})
+-        self.assertEqual(b, '')
+-
+     def test_prepare_authorization_request(self):
+         redirect_url = 'https://example.com/callback/'
+         scopes = 'read'
+diff --git a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
+index 338dbd91faa795a0c25d7254818fbf72879c2920..d347b1767c285bddd1e99910e173df2343239add 100644
+--- a/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
++++ b/tests/oauth2/rfc6749/endpoints/test_revocation_endpoint.py
+@@ -88,19 +88,6 @@ class RevocationEndpointTest(TestCase):
+         self.assertEqual(loads(b)['error'], 'invalid_client')
+         self.assertEqual(s, 401)
+ 
+-    def test_revoke_with_callback(self):
+-        endpoint = RevocationEndpoint(self.validator, enable_jsonp=True)
+-        callback = 'package.hello_world'
+-        for token_type in ('access_token', 'refresh_token', 'invalid'):
+-            body = urlencode([('token', 'foo'),
+-                              ('token_type_hint', token_type),
+-                              ('callback', callback)])
+-            h, b, s = endpoint.create_revocation_response(self.uri,
+-                    headers=self.headers, body=body)
+-            self.assertEqual(h, {})
+-            self.assertEqual(b, callback + '();')
+-            self.assertEqual(s, 200)
+-
+     def test_revoke_unsupported_token(self):
+         endpoint = RevocationEndpoint(self.validator,
+                                       supported_token_types=['access_token'])
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49264_p2.patch new file +50 -0

50 lines not on this page · raw message

meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb +2 -0
index 0974020a17..ffb07fef30 100644
@@ -7,6 +7,8 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=2699a9fb0d71d5eafd75d8d7c302f7df"
 SRC_URI += " \
     file://CVE-2026-49265_p1.patch \
     file://CVE-2026-49265_p2.patch \
+    file://CVE-2026-49264_p1.patch \
+    file://CVE-2026-49264_p2.patch \
 "
 
 SRC_URI[sha256sum] = "0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9"
Signature · 1 line
2.35.6
#2 lore raw

PATCH 3/4 python3-oauthlib: fix CVE-2026-118669

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

From: Hetvi Thakar <[email protected]>

The client_credentials and password grants can authenticate one client while authorizing grants and scopes using a supplied client_id for another client, when validators rely on that client_id argument.

Backport upstream fix [1], referenced by NVD [2] and Debian [3], to bind authorization to the authenticated client identity and reject a conflicting client_id in OAuthLib 3.3.1.

Include authentication-helper prerequisite [4] for the older grant implementation. Public-client validators must attach request.client. Retain the upstream validator contract and regressions, and add cases for missing, matching and inconsistent client identifiers. Omit docs/oauth2/server.rst because the 3.3.1 source archive excludes docs.

[1] https://github.com/oauthlib/oauthlib/commit/c951a1d09f99f14e3240973fa83c4f4287d4753d
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-118669
[3] https://security-tracker.debian.org/tracker/CVE-2026-118669
[4] https://github.com/oauthlib/oauthlib/commit/90d8aa851b6ce0fd095ed27e0f88051ab02279a9

---
 .../CVE-2026-118669-dependent.patch           | 237 +++++++
 .../python3-oauthlib/CVE-2026-118669.patch    | 602 ++++++++++++++++++
 .../python/python3-oauthlib_3.3.1.bb          |   2 +
 3 files changed, 841 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-118669-dependent.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-118669.patch
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-118669-dependent.patch new file +237 -0
new file mode 100644
index 0000000000..f3933854e5
@@ -0,0 +1,237 @@
+From 90d8aa851b6ce0fd095ed27e0f88051ab02279a9 Mon Sep 17 00:00:00 2001
+From: Kyle Hekhuis <[email protected]>
+Date: Mon, 14 Jul 2025 16:04:42 -0400
+Subject: [PATCH] Add helper method for validating client authentication and
+ use it in AuthorizationCodeGrant, DeviceCodeGrant, RefreshTokenGrant, and
+ ResourceOwnerPasswordCredentialsGrant.
+
+Add some missing imports to the oauth2 __init__.py
+
+CVE: CVE-2026-118669
+Upstream-Status: Backport [https://github.com/oauthlib/oauthlib/commit/90d8aa851b6ce0fd095ed27e0f88051ab02279a9]
+
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ oauthlib/oauth2/__init__.py                        |  5 ++--
+ .../rfc6749/grant_types/authorization_code.py      | 16 +----------
+ oauthlib/oauth2/rfc6749/grant_types/base.py        | 21 +++++++++++++++
+ .../oauth2/rfc6749/grant_types/refresh_token.py    | 16 ++++-------
+ .../resource_owner_password_credentials.py         |  9 +------
+ oauthlib/oauth2/rfc8628/grant_types/device_code.py | 20 +++++---------
+ .../oauth2/rfc8628/grant_types/test_device_code.py | 31 +++++++++++++++++++++-
+ 7 files changed, 67 insertions(+), 51 deletions(-)
+
+diff --git a/oauthlib/oauth2/__init__.py b/oauthlib/oauth2/__init__.py
+index 3bb5102..0e0bafd 100644
+--- a/oauthlib/oauth2/__init__.py
++++ b/oauthlib/oauth2/__init__.py
+@@ -66,5 +66,6 @@ from .rfc6749.request_validator import RequestValidator
+ from .rfc6749.tokens import BearerToken, OAuth2Token
+ from .rfc6749.utils import is_secure_transport
+ from .rfc8628.clients import DeviceClient
+-from oauthlib.oauth2.rfc8628.endpoints import DeviceAuthorizationEndpoint, DeviceApplicationServer
+-from oauthlib.oauth2.rfc8628.grant_types import DeviceCodeGrant
++from .rfc8628.endpoints import DeviceAuthorizationEndpoint, DeviceApplicationServer
++from .rfc8628.errors import AuthorizationPendingError, SlowDownError, ExpiredTokenError, AccessDenied
++from .rfc8628.grant_types import DeviceCodeGrant
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+index 09dc619..f2d6d27 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/authorization_code.py
+@@ -452,21 +452,7 @@ class AuthorizationCodeGrant(GrantTypeBase):
+                 raise errors.InvalidRequestError(description='Duplicate %s parameter.' % param,
+                                                  request=request)
+ 
+-        if self.request_validator.client_authentication_required(request):
+-            # If the client type is confidential or the client was issued client
+-            # credentials (or assigned other authentication requirements), the
+-            # client MUST authenticate with the authorization server as described
+-            # in Section 3.2.1.
+-            # https://tools.ietf.org/html/rfc6749#section-3.2.1
+-            if not self.request_validator.authenticate_client(request):
+-                log.debug('Client authentication failed, %r.', request)
+-                raise errors.InvalidClientError(request=request)
+-        elif not self.request_validator.authenticate_client_id(request.client_id, request):
+-            # REQUIRED, if the client is not authenticating with the
+-            # authorization server as described in Section 3.2.1.
+-            # https://tools.ietf.org/html/rfc6749#section-3.2.1
+-            log.debug('Client authentication failed, %r.', request)
+-            raise errors.InvalidClientError(request=request)
++        self.validate_client_authentication(request)
+ 
+         if not hasattr(request.client, 'client_id'):
+             raise NotImplementedError('Authenticate client must set the '
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py
+index d96a2db..0b69e54 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/base.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/base.py
+@@ -175,6 +175,27 @@ class GrantTypeBase:
+                                                       request.scopes, request.client, request):
+             raise errors.InvalidScopeError(request=request)
+ 
++    def validate_client_authentication(self, request):
++        """Raise on failed client authentication."""
++        # Handles confidential clients
++        if self.request_validator.client_authentication_required(request):
++            # If the client type is confidential or the client was issued client
++            # credentials (or assigned other authentication requirements), the
++            # client MUST authenticate with the authorization server as described
++            # in Section 3.2.1.
++            # https://tools.ietf.org/html/rfc6749#section-3.2.1
++            if not self.request_validator.authenticate_client(request):
++                log.debug('Client authentication failed, %r.', request)
++                raise errors.InvalidClientError(request=request)
++
++        # Handles public clients
++        elif not self.request_validator.authenticate_client_id(request.client_id, request):
++            # REQUIRED, if the client is not authenticating with the
++            # authorization server as described in Section 3.2.1.
++            # https://tools.ietf.org/html/rfc6749#section-3.2.1
++            log.debug('Client authentication failed, %r.', request)
++            raise errors.InvalidClientError(request=request)
++
+     def prepare_authorization_response(self, request, token, headers, body, status):
+         """Place token according to response mode.
+ 
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
+index 43bf55a..f626f0c 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/refresh_token.py
+@@ -96,17 +96,11 @@ class RefreshTokenGrant(GrantTypeBase):
+         # authentication requirements), the client MUST authenticate with the
+         # authorization server as described in Section 3.2.1.
+         # https://tools.ietf.org/html/rfc6749#section-3.2.1
+-        if self.request_validator.client_authentication_required(request):
+-            log.debug('Authenticating client, %r.', request)
+-            if not self.request_validator.authenticate_client(request):
+-                log.debug('Invalid client (%r), denying access.', request)
+-                raise errors.InvalidClientError(request=request)
+-            # Ensure that request.client_id is set.
+-            if request.client_id is None and request.client is not None:
+-                request.client_id = request.client.client_id
+-        elif not self.request_validator.authenticate_client_id(request.client_id, request):
+-            log.debug('Client authentication failed, %r.', request)
+-            raise errors.InvalidClientError(request=request)
++        self.validate_client_authentication(request)
++
++        # Ensure that request.client_id is set.
++        if request.client_id is None and request.client is not None:
++            request.client_id = request.client.client_id
+ 
+         # Ensure client is authorized use of this grant type
+         self.validate_grant_type(request)
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
+index 55d9287..6fc67c6 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/resource_owner_password_credentials.py
+@@ -85,14 +85,7 @@ class ResourceOwnerPasswordCredentialsGrant(GrantTypeBase):
+         """
+         headers = self._get_default_headers()
+         try:
+-            if self.request_validator.client_authentication_required(request):
+-                log.debug('Authenticating client, %r.', request)
+-                if not self.request_validator.authenticate_client(request):
+-                    log.debug('Client authentication failed, %r.', request)
+-                    raise errors.InvalidClientError(request=request)
+-            elif not self.request_validator.authenticate_client_id(request.client_id, request):
+-                log.debug('Client authentication failed, %r.', request)
+-                raise errors.InvalidClientError(request=request)
++            self.validate_client_authentication(request)
+             log.debug('Validating access token request, %r.', request)
+             self.validate_token_request(request)
+         except errors.OAuth2Error as e:
+diff --git a/oauthlib/oauth2/rfc8628/grant_types/device_code.py b/oauthlib/oauth2/rfc8628/grant_types/device_code.py
+index 082daf0..9d23d45 100644
+--- a/oauthlib/oauth2/rfc8628/grant_types/device_code.py
++++ b/oauthlib/oauth2/rfc8628/grant_types/device_code.py
+@@ -55,14 +55,12 @@ class DeviceCodeGrant(GrantTypeBase):
+                     description=f"Duplicate {param} parameter.", request=request
+                 )
+ 
+-        if not self.request_validator.authenticate_client(request):
+-            raise rfc6749_errors.InvalidClientError(request=request)
+-        elif not hasattr(request.client, "client_id"):
+-            raise NotImplementedError(
+-                "Authenticate client must set the "
+-                "request.client.client_id attribute "
+-                "in authenticate_client."
+-            )
++        self.validate_client_authentication(request)
++
++        if not hasattr(request.client, 'client_id'):
++            raise NotImplementedError('Authenticate client must set the '
++                                      'request.client.client_id attribute '
++                                      'in authenticate_client.')
+ 
+         # Ensure client is authorized use of this grant type
+         self.validate_grant_type(request)
+@@ -93,13 +91,7 @@ class DeviceCodeGrant(GrantTypeBase):
+         """
+         headers = self._get_default_headers()
+         try:
+-            if self.request_validator.client_authentication_required(
+-                request
+-            ) and not self.request_validator.authenticate_client(request):
+-                raise rfc6749_errors.InvalidClientError(request=request)
+-
+             self.validate_token_request(request)
+-
+         except rfc6749_errors.OAuth2Error as e:
+             headers.update(e.headers)
+             return headers, e.json, e.status_code
+diff --git a/tests/oauth2/rfc8628/grant_types/test_device_code.py b/tests/oauth2/rfc8628/grant_types/test_device_code.py
+index da0592f..10b5dd6 100644
+--- a/tests/oauth2/rfc8628/grant_types/test_device_code.py
++++ b/tests/oauth2/rfc8628/grant_types/test_device_code.py
+@@ -99,7 +99,7 @@ def test_create_token_response():
+     validator.save_token.assert_called_once()
+ 
+ 
+-def test_invalid_client_error():
++def test_invalid_client_authentication_error_confidential_client():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
+     request.client = mock.Mock()
+@@ -107,6 +107,8 @@ def test_invalid_client_error():
+     auth = DeviceCodeGrant(validator)
+     bearer = BearerToken(validator)
+ 
++    # Simulate a confidential client that requires authentication
++    validator.client_authentication_required.return_value = True
+     validator.authenticate_client.return_value = False
+ 
+     headers, body, status_code = auth.create_token_response(request, bearer)
+@@ -124,6 +126,33 @@ def test_invalid_client_error():
+     validator.save_token.assert_not_called()
+ 
+ 
++def test_invalid_client_authentication_error_public_client():
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    request.client = mock.Mock()
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++
++    # Simulate a public client that does not require authentication
++    validator.client_authentication_required.return_value = False
++    validator.authenticate_client_id.return_value = False
++
++    headers, body, status_code = auth.create_token_response(request, bearer)
++    body = json.loads(body)
++
++    assert headers == {
++        "Content-Type": "application/json",
++        "Cache-Control": "no-store",
++        "Pragma": "no-cache",
++        "WWW-Authenticate": 'Bearer error="invalid_client"',
++    }
++    assert body == {"error": "invalid_client"}
++    assert status_code == 401
++
++    validator.save_token.assert_not_called()
++
++
+ def test_invalid_grant_type_error():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-118669.patch new file +602 -0

602 lines not on this page · raw message

meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb +2 -0
index ffb07fef30..d41eeff279 100644
@@ -9,6 +9,8 @@ SRC_URI += " \
     file://CVE-2026-49265_p2.patch \
     file://CVE-2026-49264_p1.patch \
     file://CVE-2026-49264_p2.patch \
+    file://CVE-2026-118669-dependent.patch \
+    file://CVE-2026-118669.patch \
 "
 
 SRC_URI[sha256sum] = "0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9"
Signature · 1 line
2.35.6
#3 lore raw

PATCH 4/4 python3-oauthlib: fix CVE-2026-49272

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

From: Hetvi Thakar <[email protected]>

The RFC 8628 token endpoint can issue a bearer token for a missing or bogus device_code when the configured client validator accepts the request, without checking the device authorization state.

Backport upstream fix [1], referenced by NVD [2], to OAuthLib 3.3.1. Require the provider's validate_device_code hook to verify client ownership and authorization state before a token can be issued.

Include upstream scope follow-up [3] to ignore client-supplied scopes and require scopes from the stored authorization.

Add a local adjustment to preserve an approved empty scope list instead of expanding it to client defaults, a remaining upstream gap reproduced on 3.3.1. Keep the validator's scope-policy check and test missing, empty and denied approved scopes.

Retain the upstream device-flow regressions. Omit docs/oauth2/endpoints/device.rst because the 3.3.1 source archive excludes the documentation tree.

[1] https://github.com/oauthlib/oauthlib/commit/77a5f1c8ce00da2b0b8c5f6e9cc129920085f114
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-49272
[3] https://github.com/oauthlib/oauthlib/commit/5edac41fb1164485582f4bc4d2abd9c50eb6df47

---
 .../python3-oauthlib/CVE-2026-49272_p1.patch  | 817 ++++++++++++++++++
 .../python3-oauthlib/CVE-2026-49272_p2.patch  | 263 ++++++
 .../python/python3-oauthlib_3.3.1.bb          |   2 +
 3 files changed, 1082 insertions(+)
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49272_p1.patch
 create mode 100644 meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49272_p2.patch
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49272_p1.patch new file +817 -0
new file mode 100644
index 0000000000..17d9d16731
@@ -0,0 +1,817 @@
+From 77a5f1c8ce00da2b0b8c5f6e9cc129920085f114 Mon Sep 17 00:00:00 2001
+From: Jonathan Huot <[email protected]>
+Date: Fri, 2 Oct 2026 00:30:11 +0200
+Subject: [PATCH] Merge pull request #954 from hekhuisk/improve-device-workflow
+
+Improve device workflow
+
+CVE: CVE-2026-49272
+Upstream-Status: Backport [https://github.com/oauthlib/oauthlib/commit/77a5f1c8ce00da2b0b8c5f6e9cc129920085f114]
+
+Backport Changes:
+- Omit docs/oauth2/endpoints/device.rst because the 3.3.1 source archive
+  does not contain the documentation tree. Retain all production code,
+  regression tests and validator-contract documentation in Python files.
+
+Signed-off-by: Hetvi Thakar <[email protected]>
+---
+ oauthlib/common.py                                 |   1 +
+ oauthlib/oauth2/rfc6749/grant_types/base.py        |   6 +-
+ .../rfc8628/endpoints/device_authorization.py      |  56 ++-----
+ oauthlib/oauth2/rfc8628/grant_types/device_code.py | 136 ++++++++++++++++
+ oauthlib/oauth2/rfc8628/request_validator.py       |  38 +++++
+ .../rfc8628/endpoints/test_error_responses.py      |  80 ++++++----
+ .../oauth2/rfc8628/grant_types/test_device_code.py | 175 ++++++++++++++++++++-
+ tests/oauth2/rfc8628/test_server.py                |  43 ++++-
+ 8 files changed, 455 insertions(+), 80 deletions(-)
+
+diff --git a/oauthlib/common.py b/oauthlib/common.py
+index dfa851798828b24f54e767a7f61a2180cd59b48c..641a0e228105aab0acbc8dd85bcf9017a1ccd45d 100644
+--- a/oauthlib/common.py
++++ b/oauthlib/common.py
+@@ -366,6 +366,7 @@ class Request:
+             "code_challenge": None,
+             "code_challenge_method": None,
+             "code_verifier": None,
++            "device_code": None,
+             "extra_credentials": None,
+             "grant_type": None,
+             "redirect_uri": None,
+diff --git a/oauthlib/oauth2/rfc6749/grant_types/base.py b/oauthlib/oauth2/rfc6749/grant_types/base.py
+index a5e5f426a9c44e1539716e734ea8bda6f035d435..a108bf685ebe514e98c0fccb8b1750e9849d704c 100644
+--- a/oauthlib/oauth2/rfc6749/grant_types/base.py
++++ b/oauthlib/oauth2/rfc6749/grant_types/base.py
+@@ -208,9 +208,9 @@ class GrantTypeBase:
+ 
+         if request.client is None or \
+             not hasattr(request.client, 'client_id'):
+-            raise NotImplementedError('Authenticate client must set the '
+-                                      'request.client.client_id attribute '
+-                                      'in authenticate_client.')
++            raise NotImplementedError('authenticate_client_id must set the '
++                                      'request.client attribute to a client '
++                                      'object with a client_id attribute.')
+ 
+         if not request.client_id:
+             request.client_id = request.client.client_id
+diff --git a/oauthlib/oauth2/rfc8628/endpoints/device_authorization.py b/oauthlib/oauth2/rfc8628/endpoints/device_authorization.py
+index 3f38a540590a9d38d42e3d84a79f6acfe440cac7..81f2fe8539ec369cd401f91d16f55ee4a252baa3 100644
+--- a/oauthlib/oauth2/rfc8628/endpoints/device_authorization.py
++++ b/oauthlib/oauth2/rfc8628/endpoints/device_authorization.py
+@@ -10,11 +10,12 @@ import logging
+ from typing import Callable
+ 
+ from oauthlib.common import Request, generate_token
+-from oauthlib.oauth2.rfc6749 import errors
++from oauthlib.oauth2.rfc6749 import utils
+ from oauthlib.oauth2.rfc6749.endpoints.base import (
+     BaseEndpoint,
+     catch_errors_and_unavailability,
+ )
++from oauthlib.oauth2.rfc8628.grant_types import DeviceCodeGrant
+ 
+ log = logging.getLogger(__name__)
+ 
+@@ -52,6 +53,7 @@ class DeviceAuthorizationEndpoint(BaseEndpoint):
+         :param user_code_generator: a callable that returns a configurable user code
+         """
+         self.request_validator = request_validator
++        self.device_code_grant = DeviceCodeGrant(request_validator)
+         self._expires_in = expires_in
+         self._interval = interval
+         self._verification_uri = verification_uri
+@@ -101,44 +103,7 @@ class DeviceAuthorizationEndpoint(BaseEndpoint):
+         .. _`Section 3.2.1. of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-3.2.1
+         .. _`Section 2.2 of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-2.2
+         """
+-
+-        # First check duplicate parameters
+-        for param in ("client_id", "scope"):
+-            try:
+-                duplicate_params = request.duplicate_params
+-            except ValueError:
+-                raise errors.InvalidRequestFatalError(
+-                    description="Unable to parse query string", request=request
+-                )
+-            if param in duplicate_params:
+-                raise errors.InvalidRequestFatalError(
+-                    description="Duplicate %s parameter." % param, request=request
+-                )
+-
+-        # the "application/x-www-form-urlencoded" format, per Appendix B of [RFC6749]
+-        # https://www.rfc-editor.org/rfc/rfc6749#appendix-B
+-        if request.headers["Content-Type"] != "application/x-www-form-urlencoded":
+-            raise errors.InvalidRequestError(
+-                "Content-Type must be application/x-www-form-urlencoded",
+-                request=request,
+-            )
+-
+-        # REQUIRED. The client identifier as described in Section 2.2.
+-        # https://tools.ietf.org/html/rfc6749#section-2.2
+-        # TODO: extract client_id an helper validation function.
+-        if not request.client_id:
+-            raise errors.MissingClientIdError(request=request)
+-
+-        if not self.request_validator.validate_client_id(request.client_id, request):
+-            raise errors.InvalidClientIdError(request=request)
+-
+-        # The client authentication requirements of Section 3.2.1 of [RFC6749]
+-        # apply to requests on this endpoint, which means that confidential
+-        # clients (those that have established client credentials) authenticate
+-        # in the same manner as when making requests to the token endpoint, and
+-        # public clients provide the "client_id" parameter to identify
+-        # themselves.
+-        self._raise_on_invalid_client(request)
++        self.device_code_grant.validate_device_authorization_request(request)
+ 
+     @catch_errors_and_unavailability
+     def create_device_authorization_response(
+@@ -189,6 +154,13 @@ class DeviceAuthorizationEndpoint(BaseEndpoint):
+               SHOULD wait between polling requests to the token endpoint. If no
+               value is provided, clients MUST use 5 as the default.
+ 
++           scope
++              **OPTIONAL.** The space delimited scopes resolved for this request,
++              either the scopes the device asked for or the ones returned by
++              ``get_default_scopes``. Not defined by RFC 8628, it is included so
++              the caller can persist the authorized scopes with the device_code.
++              Omitted when no scopes were resolved.
++
+            **For example:**
+ 
+               .. code-block:: http
+@@ -224,6 +196,12 @@ class DeviceAuthorizationEndpoint(BaseEndpoint):
+         if self.interval is not None:
+             data["interval"] = self.interval
+ 
++        # ``validate_device_authorization_request`` resolves request.scopes,
++        # falling back to ``get_default_scopes`` when the device omitted the
++        # ``scope`` parameter. Echo the resolved value so callers can persist it
++        # alongside the device_code/user_code without re-running the validator.
++        if request.scopes:
++            data["scope"] = utils.list_to_scope(request.scopes)
+ 
+         verification_uri_complete = self.verification_uri_complete(user_code)
+         if verification_uri_complete:
+diff --git a/oauthlib/oauth2/rfc8628/grant_types/device_code.py b/oauthlib/oauth2/rfc8628/grant_types/device_code.py
+index 41ee09e263af3bfe257daa68578d8f7da5cdf6d6..f17384854c66bc10978ef457d1a9b2427ce86641 100644
+--- a/oauthlib/oauth2/rfc8628/grant_types/device_code.py
++++ b/oauthlib/oauth2/rfc8628/grant_types/device_code.py
+@@ -1,5 +1,6 @@
+ from __future__ import annotations
+ import json
++import logging
+ 
+ from typing import Callable
+ 
+@@ -7,9 +8,33 @@ from oauthlib import common # noqa: TC001
+ 
+ from oauthlib.oauth2.rfc6749 import errors as rfc6749_errors
+ from oauthlib.oauth2.rfc6749.grant_types.base import GrantTypeBase
++from oauthlib.oauth2.rfc8628 import errors as rfc8628_errors
++
++log = logging.getLogger(__name__)
+ 
+ 
+ class DeviceCodeGrant(GrantTypeBase):
++    #: Maps a non-authorized device code status to the RFC 8628 Section 3.5
++    #: error it raises. The status strings are the errors' own ``error`` codes,
++    #: keeping a single source of truth.
++    _device_code_errors = {
++        cls.error: cls
++        for cls in (
++            rfc8628_errors.AuthorizationPendingError,
++            rfc8628_errors.SlowDownError,
++            rfc8628_errors.ExpiredTokenError,
++            rfc8628_errors.AccessDenied,
++        )
++    }
++
++    #: Authorization statuses returned by
++    #: :meth:`RequestValidator.validate_device_code`, per RFC 8628 Section 3.5.
++    DEVICE_CODE_AUTHORIZED = "authorized"
++    DEVICE_CODE_PENDING = rfc8628_errors.AuthorizationPendingError.error
++    DEVICE_CODE_SLOW_DOWN = rfc8628_errors.SlowDownError.error
++    DEVICE_CODE_EXPIRED = rfc8628_errors.ExpiredTokenError.error
++    DEVICE_CODE_DENIED = rfc8628_errors.AccessDenied.error
++
+     def create_authorization_response(
+         self, request: common.Request, token_handler: Callable
+     ) -> tuple[dict, str, int]:
+@@ -33,6 +58,61 @@ class DeviceCodeGrant(GrantTypeBase):
+ 
+         return self.create_token_response(request, token_handler)
+ 
++    def validate_device_authorization_request(self, request: common.Request) -> None:
++        """Validate the device authorization request.
++
++        The client_id is required if the client is not authenticating with the
++        authorization server as described in `Section 3.2.1. of [RFC6749]`_.
++        The client identifier as described in `Section 2.2 of [RFC6749]`_.
++
++        :param request: OAuthlib request.
++        :type request: oauthlib.common.Request
++
++        .. _`Section 3.2.1. of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-3.2.1
++        .. _`Section 2.2 of [RFC6749]`: https://www.rfc-editor.org/rfc/rfc6749#section-2.2
++        """
++        # First check duplicate parameters
++        for param in ("client_id", "scope"):
++            try:
++                duplicate_params = request.duplicate_params
++            except ValueError:
++                raise rfc6749_errors.InvalidRequestFatalError(
++                    description="Unable to parse query string", request=request
++                )
++            if param in duplicate_params:
++                raise rfc6749_errors.InvalidRequestFatalError(
++                    description="Duplicate %s parameter." % param, request=request
++                )
++
++        # the "application/x-www-form-urlencoded" format, per Appendix B of [RFC6749]
++        # https://www.rfc-editor.org/rfc/rfc6749#appendix-B
++        content_type = request.headers.get("Content-Type", "")
++        content_type = content_type.split(";", 1)[0].strip().lower()
++        if content_type != "application/x-www-form-urlencoded":
++            raise rfc6749_errors.InvalidRequestError(
++                "Content-Type must be application/x-www-form-urlencoded", request=request
++            )
++
++        # REQUIRED. The client identifier as described in Section 2.2.
++        # https://tools.ietf.org/html/rfc6749#section-2.2
++        if not request.client_id:
++            raise rfc6749_errors.MissingClientIdError(request=request)
++
++        if not self.request_validator.validate_client_id(request.client_id, request):
++            raise rfc6749_errors.InvalidClientIdError(request=request)
++
++        # The client authentication requirements of Section 3.2.1 of [RFC6749]
++        # apply to requests on this endpoint, which means that confidential
++        # clients (those that have established client credentials) authenticate
++        # in the same manner as when making requests to the token endpoint, and
++        # public clients provide the "client_id" parameter to identify
++        # themselves.
++        self.validate_client_authentication(request)
++
++        # OPTIONAL. The scope of the access request as defined by Section 3.3
++        # of [RFC6749]. https://www.rfc-editor.org/rfc/rfc8628#section-3.1
++        self.validate_scopes(request)
++
+     def validate_token_request(self, request: common.Request) -> None:
+         """
+         Performs the necessary check against the request to ensure
+@@ -60,11 +140,67 @@ class DeviceCodeGrant(GrantTypeBase):
+         # Ensure client is authorized use of this grant type
+         self.validate_grant_type(request)
+ 
++        # Validate the device_code first: per RFC 8628 Section 3.4 the token
++        # request carries no scope, so the validator must populate
++        # request.user and request.scopes from the stored authorization before
++        # validate_scopes runs (otherwise it would fall back to default scopes).
++        self.validate_device_code(request)
++
+         self.validate_scopes(request)
+ 
+         for validator in self.custom_validators.post_token:
+             validator(request)
+ 
++    def validate_device_code(self, request: common.Request) -> None:
++        """Validate the ``device_code`` and its authorization status.
++
++        Delegates to :meth:`RequestValidator.validate_device_code`, which
++        returns one of the ``DEVICE_CODE_*`` statuses, and maps it to the
++        appropriate RFC 8628 Section 3.5 error.
++
++        :param request: OAuthlib request.
++        :type request: oauthlib.common.Request
++        """
++        if not request.device_code:
++            raise rfc6749_errors.InvalidRequestError(
++                "Missing device_code parameter.", request=request
++            )
++
++        status = self.request_validator.validate_device_code(
++            request.client_id, request.device_code, request
++        )
++        if status == self.DEVICE_CODE_AUTHORIZED:
++            # The validator is expected to populate these from the stored
++            # authorization; if it did not, validate_scopes will silently fall
++            # back to the client's default scopes.
++            if getattr(request, "user", None) is None:
++                log.debug("request.user was not set on device_code validation.")
++            if getattr(request, "scopes", None) is None and request.scope is None:
++                raise rfc6749_errors.ServerError(
++                    description="validate_device_code must set request.scopes for an authorized device_code.",
++                    request=request,
++                )
++            if getattr(request, "scopes", None) is None:
++                log.debug("request.scopes was not set on device_code validation.")
++            return
++
++        # A recognized non-authorized status maps to its RFC 8628 polling
++        # error; anything else means the device_code is unknown or invalid.
++        error_class = self._device_code_errors.get(status)
++        if error_class is not None:
++            raise error_class(request=request)
++
++        # None is the documented "unknown/invalid device_code" return. Any
++        # other unrecognized value most likely signals a validator that did
++        # not return a DEVICE_CODE_* status, so surface it for debugging.
++        if status is not None:
++            log.warning(
++                "validate_device_code returned unrecognized status %r; treating "
++                "the device_code as invalid. Return one of the "
++                "DeviceCodeGrant.DEVICE_CODE_* constants.", status
++            )
++        raise rfc6749_errors.InvalidGrantError(request=request)
++
+     def create_token_response(
+         self, request: common.Request, token_handler: Callable
+     ) -> tuple[dict, str, int]:
+diff --git a/oauthlib/oauth2/rfc8628/request_validator.py b/oauthlib/oauth2/rfc8628/request_validator.py
+index 70ee7824e92dae12b5b44d073f11c708ebd07577..1afacd291113f4ffd94568ec7fb6a6fcf420c9c3 100644
+--- a/oauthlib/oauth2/rfc8628/request_validator.py
++++ b/oauthlib/oauth2/rfc8628/request_validator.py
+@@ -23,3 +23,41 @@ class RequestValidator(OAuth2RequestValidator):
+         .. _`Section 3.1`: https://www.rfc-editor.org/rfc/rfc8628#section-3.1
+         """
+         return True
++
++    def validate_device_code(self, client_id, code, request, *args, **kwargs):
++        """Validate a ``device_code`` and return its authorization status.
++
++        Called when a device polls the token endpoint. The implementation
++        should look up the ``device_code``, confirm it was issued to the
++        authenticating client, and report where it is in the authorization
++        process described in `Section 3.5`_ by returning one of the
++        ``DeviceCodeGrant`` status constants:
++
++        - ``DEVICE_CODE_AUTHORIZED``: the end user approved the request.
++          The implementation should also set ``request.user`` (and any
++          scopes or claims to embed) so they end up on the issued token,
++          which removes the need for a separate token validator.
++        - ``DEVICE_CODE_PENDING``: the user has not yet completed the
++          interaction; raises ``AuthorizationPendingError``.
++        - ``DEVICE_CODE_SLOW_DOWN``: as pending, but the client is polling
++          too quickly; raises ``SlowDownError``.
++        - ``DEVICE_CODE_EXPIRED``: the ``device_code`` has expired; raises
++          ``ExpiredTokenError``.
++        - ``DEVICE_CODE_DENIED``: the user denied the request; raises
++          ``AccessDenied``.
++
++        Returning ``None`` (or any unrecognized value) is treated as an
++        unknown or invalid ``device_code`` and raises ``InvalidGrantError``.
++
++        :param client_id: Unicode client identifier.
++        :param code: Unicode device_code.
++        :param request: OAuthlib request.
++        :type request: oauthlib.common.Request
++        :rtype: str or None
++
++        Method is used by:
++            - Device Code Grant
++
++        .. _`Section 3.5`: https://www.rfc-editor.org/rfc/rfc8628#section-3.5
++        """
++        raise NotImplementedError("Subclasses must implement this method.")
+diff --git a/tests/oauth2/rfc8628/endpoints/test_error_responses.py b/tests/oauth2/rfc8628/endpoints/test_error_responses.py
+index c799cc81af295715d91351d3ac75cf0bb970a6e7..75f0ef06b8fdad07d5f490c7cc217b3d9bef7bd5 100644
+--- a/tests/oauth2/rfc8628/endpoints/test_error_responses.py
++++ b/tests/oauth2/rfc8628/endpoints/test_error_responses.py
+@@ -8,15 +8,23 @@ from oauthlib.oauth2.rfc8628.request_validator import RequestValidator
+ 
+ 
+ class ErrorResponseTest(TestCase):
+-    def set_client(self, request):
++    def set_client(self, request, *args, **kwargs):
++        """Stand in for a validator that attaches the client, as documented."""
+         request.client = mock.MagicMock()
+-        request.client.client_id = "mocked"
++        request.client.client_id = request.client_id
+         return True
+ 
+-    def build_request(self, uri="https://example.com/device_authorize", client_id="foo"):
+-        body = ""
+-        if client_id:
+-            body = f"client_id={client_id}"
++    def set_client_id(self, client_id, request, *args, **kwargs):
++        return self.set_client(request)
++
++    def build_request(
++        self, uri="https://example.com/device_authorize", client_id="foo", body=None
++    ):
++        # The body must be passed to the constructor: Request parses it once at
++        # initialization, so assigning to request.body afterwards would leave
++        # request.scope and request.duplicate_params stale.
++        if body is None:
++            body = f"client_id={client_id}" if client_id else ""
+         return Request(
+             uri,
+             http_method="POST",
+@@ -24,26 +32,29 @@ class ErrorResponseTest(TestCase):
+             headers={"Content-Type": "application/x-www-form-urlencoded"},
+         )
+ 
+-    def assert_request_raises(self, error, request):
++    def assert_request_raises(self, error, request, description=None):
+         """Test that the request fails similarly on the validation and response endpoint."""
+-        self.assertRaises(
+-            error,
+-            self.device.validate_device_authorization_request,
+-            request,
+-        )
+-        self.assertRaises(
+-            error,
+-            self.device.create_device_authorization_response,
+-            uri=request.uri,
+-            http_method=request.http_method,
+-            body=request.body,
+-            headers=request.headers,
+-        )
++        with self.assertRaises(error) as caught:
++            self.device.validate_device_authorization_request(request)
++        if description is not None:
++            self.assertEqual(description, caught.exception.description)
++
++        with self.assertRaises(error) as caught:
++            self.device.create_device_authorization_response(
++                uri=request.uri,
++                http_method=request.http_method,
++                body=request.body,
++                headers=request.headers,
++            )
++        if description is not None:
++            self.assertEqual(description, caught.exception.description)
+ 
+     def setUp(self):
+         self.validator = mock.MagicMock(spec=RequestValidator)
+         self.validator.get_default_redirect_uri.return_value = None
+         self.validator.get_code_challenge.return_value = None
++        self.validator.authenticate_client.side_effect = self.set_client
++        self.validator.authenticate_client_id.side_effect = self.set_client_id
+         self.device = DeviceApplicationServer(self.validator, "https://example.com/verify")
+ 
+     def test_missing_client_id(self):
+@@ -69,27 +80,40 @@ class ErrorResponseTest(TestCase):
+         self.assert_request_raises(errors.InvalidClientIdError, request)
+ 
+     def test_duplicate_client_id(self):
+-        request = self.build_request()
+-        request.body = "client_id=foo&client_id=bar"
++        request = self.build_request(body="client_id=foo&client_id=bar")
+         # Device code grant
+-        self.validator.validate_client_id.return_value = False
+-        self.assert_request_raises(errors.InvalidRequestFatalError, request)
++        self.assert_request_raises(
++            errors.InvalidRequestFatalError, request, "Duplicate client_id parameter."
++        )
+ 
+     def test_unauthenticated_confidential_client(self):
+         self.validator.client_authentication_required.return_value = True
++        self.validator.authenticate_client.side_effect = None
+         self.validator.authenticate_client.return_value = False
+         request = self.build_request()
+         self.assert_request_raises(errors.InvalidClientError, request)
+ 
+     def test_unauthenticated_public_client(self):
+         self.validator.client_authentication_required.return_value = False
++        self.validator.authenticate_client_id.side_effect = None
+         self.validator.authenticate_client_id.return_value = False
+         request = self.build_request()
+         self.assert_request_raises(errors.InvalidClientError, request)
+ 
+     def test_duplicate_scope_parameter(self):
+-        request = self.build_request()
+-        request.body = "client_id=foo&scope=foo&scope=bar"
++        request = self.build_request(body="client_id=foo&scope=foo&scope=bar")
+         # Device code grant
+-        self.validator.validate_client_id.return_value = False
+-        self.assert_request_raises(errors.InvalidRequestFatalError, request)
++        self.assert_request_raises(
++            errors.InvalidRequestFatalError, request, "Duplicate scope parameter."
++        )
++
++    def test_invalid_scope(self):
++        request = self.build_request(body="client_id=foo&scope=foo")
++
++        # Only reject the scope requested in the body, so that the test fails if
++        # the requested scope never reaches the validator.
++        def validate_scopes(client_id, scopes, client, request):
++            return scopes != ["foo"]
++
++        self.validator.validate_scopes.side_effect = validate_scopes
++        self.assert_request_raises(errors.InvalidScopeError, request)
+diff --git a/tests/oauth2/rfc8628/grant_types/test_device_code.py b/tests/oauth2/rfc8628/grant_types/test_device_code.py
+index 3e3c002b4f30e6418bcb9d8bb456b76c12734b95..952cfe4c1aaf82b03e6e9bc92be1ac46711e557a 100644
+--- a/tests/oauth2/rfc8628/grant_types/test_device_code.py
++++ b/tests/oauth2/rfc8628/grant_types/test_device_code.py
+@@ -5,18 +5,24 @@ import pytest
+ from oauthlib import common
+ 
+ from oauthlib.oauth2.rfc8628.grant_types import DeviceCodeGrant
++from oauthlib.oauth2.rfc8628.request_validator import RequestValidator
+ from oauthlib.oauth2.rfc6749.tokens import BearerToken
+ 
+ def create_request(body: str = "") -> common.Request:
+     request = common.Request("http://a.b/path", body=body or None)
+     request.scopes = ("hello", "world")
+     request.expires_in = 1800
+-    request.client = "batman"
+     request.client_id = "abcdef"
++    # Client authentication must leave request.client set to an object whose
++    # client_id matches request.client_id, otherwise validate_client_confidential
++    # /validate_client_public raise before the grant's own checks run.
++    request.client = mock.Mock()
++    request.client.client_id = request.client_id
+     request.code = "1234"
+     request.response_type = "code"
+     request.grant_type = "urn:ietf:params:oauth:grant-type:device_code"
+     request.redirect_uri = "https://a.b/"
++    request.device_code = "device_code_1234"
+     return request
+ 
+ 
+@@ -54,6 +60,7 @@ def test_custom_pre_and_post_token_validators():
+     request: common.Request = create_request()
+     request.client = client
+     client.client_id = request.client_id
++    validator.validate_device_code.return_value = DeviceCodeGrant.DEVICE_CODE_AUTHORIZED
+ 
+     auth = DeviceCodeGrant(validator)
+ 
+@@ -70,8 +77,7 @@ def test_custom_pre_and_post_token_validators():
+ def test_create_token_response():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
+-    request.client = mock.Mock()
+-    request.client.client_id = request.client_id
++    validator.validate_device_code.return_value = DeviceCodeGrant.DEVICE_CODE_AUTHORIZED
+ 
+     auth = DeviceCodeGrant(validator)
+ 
+@@ -104,7 +110,6 @@ def test_create_token_response():
+ def test_invalid_client_authentication_error_confidential_client():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
+-    request.client = mock.Mock()
+ 
+     auth = DeviceCodeGrant(validator)
+     bearer = BearerToken(validator)
+@@ -131,7 +136,6 @@ def test_invalid_client_authentication_error_confidential_client():
+ def test_invalid_client_authentication_error_public_client():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
+-    request.client = mock.Mock()
+ 
+     auth = DeviceCodeGrant(validator)
+     bearer = BearerToken(validator)
+@@ -158,7 +162,6 @@ def test_invalid_client_authentication_error_public_client():
+ def test_invalid_grant_type_error():
+     validator = mock.MagicMock()
+     request: common.Request = create_request()
+-    request.client = mock.Mock()
+ 
+     request.grant_type = "not_device_code"
+ 
+@@ -184,7 +187,6 @@ def test_duplicate_params_error():
+     request: common.Request = create_request(
+         "client_id=123&scope=openid&scope=openid"
+     )
+-    request.client = mock.Mock()
+ 
+     auth = DeviceCodeGrant(validator)
+     bearer = BearerToken(validator)
+@@ -201,3 +203,162 @@ def test_duplicate_params_error():
+     assert status_code == 400
+ 
+     validator.save_token.assert_not_called()
++
++
[email protected](
++    ("status", "expected_error"),
++    [
++        (DeviceCodeGrant.DEVICE_CODE_PENDING, "authorization_pending"),
++        (DeviceCodeGrant.DEVICE_CODE_SLOW_DOWN, "slow_down"),
++        (DeviceCodeGrant.DEVICE_CODE_EXPIRED, "expired_token"),
++        (DeviceCodeGrant.DEVICE_CODE_DENIED, "access_denied"),
++    ],
++)
++def test_device_code_status_errors(status, expected_error):
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    validator.validate_device_code.return_value = status
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++
++    _headers, body, status_code = auth.create_token_response(request, bearer)
++    body = json.loads(body)
++
++    assert body == {"error": expected_error}
++    assert status_code == 400
++
++    validator.validate_device_code.assert_called_once_with(
++        request.client_id, request.device_code, request
++    )
++    validator.save_token.assert_not_called()
++
++
[email protected](
++    "status",
++    [
++        None,  # documented "unknown / invalid device_code" return
++        "not_a_real_status",  # validator returned an unrecognized value
++        True,  # validator wrongly returned a bool instead of a status
++    ],
++)
++def test_invalid_device_code(status):
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    validator.validate_device_code.return_value = status
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++
++    _headers, body, status_code = auth.create_token_response(request, bearer)
++    body = json.loads(body)
++
++    assert body == {"error": "invalid_grant"}
++    assert status_code == 400
++
++    validator.save_token.assert_not_called()
++
++
++def test_device_code_scopes_populated_before_scope_validation():
++    """Authorized scopes from the stored grant must be validated, not defaults.
++
++    Per RFC 8628 Section 3.4 the device token request carries no scope, so
++    validate_device_code must populate request.scopes from the stored
++    authorization before validate_scopes runs; otherwise validate_scopes falls
++    back to get_default_scopes and the token silently receives default scopes
++    (issue #944).
++    """
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    # The device token request has no scope of its own.
++    request.scope = None
++    request.scopes = None
++
++    def authorize(client_id, code, req):
++        req.scopes = ["read", "write"]
++        return DeviceCodeGrant.DEVICE_CODE_AUTHORIZED
++
++    validator.validate_device_code.side_effect = authorize
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++    auth.create_token_response(request, bearer)
++
++    validator.get_default_scopes.assert_not_called()
++    validator.validate_scopes.assert_called_once_with(
++        "abcdef", ["read", "write"], request.client, request
++    )
++
++
++def test_device_code_authorized_without_scopes_fails_loudly():
++    """An authorized device_code must not silently fall back to default scopes.
++
++    If ``validate_device_code`` returns ``DEVICE_CODE_AUTHORIZED`` without
++    populating ``request.scopes`` (and the token request itself carries no
++    ``scope``), failing loudly with a ``server_error`` is the only safe
++    option: continuing would let ``validate_scopes`` fall back to
++    ``get_default_scopes`` and reintroduce the consent-integrity bug from
++    issue #944.
++    """
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    # The device token request has no scope of its own, and the validator
++    # forgets to set request.scopes on the authorized device_code.
++    request.scope = None
++    request.scopes = None
++    validator.validate_device_code.return_value = DeviceCodeGrant.DEVICE_CODE_AUTHORIZED
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++
++    _headers, body, status_code = auth.create_token_response(request, bearer)
++    body = json.loads(body)
++
++    assert body == {
++        "error": "server_error",
++        "error_description": (
++            "validate_device_code must set request.scopes for an "
++            "authorized device_code."
++        ),
++    }
++    assert status_code == 400
++
++    validator.get_default_scopes.assert_not_called()
++    validator.validate_scopes.assert_not_called()
++    validator.save_token.assert_not_called()
++
++
++def test_validate_device_code_is_required_on_real_validator():
++    """The hook lives on the rfc8628 RequestValidator and must be implemented.
++
++    Guards against the gap mocks hide: a MagicMock auto-creates
++    ``validate_device_code``, so the behavior tests above pass even if the
++    method did not exist. A real validator subclass that has not implemented
++    it must fail loudly rather than silently.
++    """
++    request: common.Request = create_request()
++    with pytest.raises(NotImplementedError):
++        RequestValidator().validate_device_code(
++            request.client_id, request.device_code, request
++        )
++
++
++def test_missing_device_code():
++    validator = mock.MagicMock()
++    request: common.Request = create_request()
++    request.device_code = None
++
++    auth = DeviceCodeGrant(validator)
++    bearer = BearerToken(validator)
++
++    _headers, body, status_code = auth.create_token_response(request, bearer)
++    body = json.loads(body)
++
++    assert body == {
++        "error": "invalid_request",
++        "error_description": "Missing device_code parameter.",
++    }
++    assert status_code == 400
++
++    validator.validate_device_code.assert_not_called()
++    validator.save_token.assert_not_called()
+diff --git a/tests/oauth2/rfc8628/test_server.py b/tests/oauth2/rfc8628/test_server.py
+index 52025032849ec5cee16c4e2778802958a1ed73ea..9592d9e1eeaa6208deb8fcf7479fe06f15d9a9da 100644
+--- a/tests/oauth2/rfc8628/test_server.py
++++ b/tests/oauth2/rfc8628/test_server.py
+@@ -8,11 +8,30 @@ from tests.unittest import TestCase
+ 
+ 
+ class DeviceAuthorizationEndpointTest(TestCase):
++    def _set_client(self, request, *args, **kwargs):
++        """Stand in for a validator that attaches the client, as documented."""
++        request.client = mock.MagicMock()
++        request.client.client_id = request.client_id
++        return True
++
++    def _build_validator(self, scopes=None):
++        validator = mock.MagicMock(spec=RequestValidator)
++        validator.authenticate_client.side_effect = self._set_client
++        validator.authenticate_client_id.side_effect = (
++            lambda client_id, request, *a, **kw: self._set_client(request)
++        )
++        validator.get_default_scopes.return_value = scopes
++        return validator
++
+     def _configure_endpoint(
+-        self, interval=None, verification_uri_complete=None, user_code_generator=None
++        self,
++        interval=None,
++        verification_uri_complete=None,
++        user_code_generator=None,
++        scopes=None,
+     ):
+         self.endpoint = DeviceAuthorizationEndpoint(
+-            request_validator=mock.MagicMock(spec=RequestValidator),
++            request_validator=self._build_validator(scopes),
+             verification_uri=self.verification_uri,
+             interval=interval,
+             verification_uri_complete=verification_uri_complete,
+@@ -20,7 +39,6 @@ class DeviceAuthorizationEndpointTest(TestCase):
+         )
+ 
+     def setUp(self):
+-        self.request_validator = mock.MagicMock(spec=RequestValidator)
+         self.verification_uri = "http://i.b/l/verify"
+         self.uri = "http://i.b/l"
+         self.http_method = "POST"
+@@ -46,6 +64,25 @@ class DeviceAuthorizationEndpointTest(TestCase):
+         self.assertEqual(200, status_code)
+         self.assertEqual(body, expected_payload)
+ 
++    @mock.patch(
++        "oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token",
++        lambda: "abc",
++    )
++    def test_device_authorization_grant_echoes_requested_scope(self):
++        self.body = "client_id=abc&scope=read+write"
++        _, body, _ = self.endpoint.create_device_authorization_response(*self.response_payload())
++        self.assertEqual("read write", body["scope"])
++
++    @mock.patch(
++        "oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token",
++        lambda: "abc",
++    )
++    def test_device_authorization_grant_echoes_default_scope(self):
++        """A device that omits scope gets the resolved defaults back (issue #949)."""
++        self._configure_endpoint(scopes=["read", "write"])
++        _, body, _ = self.endpoint.create_device_authorization_response(*self.response_payload())
++        self.assertEqual("read write", body["scope"])
++
+     @mock.patch(
+         "oauthlib.oauth2.rfc8628.endpoints.device_authorization.generate_token",
+         lambda: "abc",
meta-python/recipes-devtools/python/python3-oauthlib/CVE-2026-49272_p2.patch new file +263 -0

263 lines not on this page · raw message

meta-python/recipes-devtools/python/python3-oauthlib_3.3.1.bb +2 -0
index d41eeff279..ca78875fb4 100644
@@ -11,6 +11,8 @@ SRC_URI += " \
     file://CVE-2026-49264_p2.patch \
     file://CVE-2026-118669-dependent.patch \
     file://CVE-2026-118669.patch \
+    file://CVE-2026-49272_p1.patch \
+    file://CVE-2026-49272_p2.patch \
 "
 
 SRC_URI[sha256sum] = "0f0f8aa759826a193cf66c12ea1af1637f87b9b4622d46e866952bb022e538c9"
Signature · 1 line
2.35.6