From 635914a6a8a9fb3b172fc15528608df2d091036b Mon Sep 17 00:00:00 2001 From: Boris Bobrov Date: Tue, 7 Apr 2026 23:55:23 +0200 Subject: [PATCH 6/6] Block app cred tokens from authorizing OAuth1 requests The OAuth1 authorize endpoint checked is_delegated_auth to block trust-scoped and OAuth-scoped tokens from authorizing request tokens, but application credential tokens were not covered by this check. A restricted application credential could authorize a request token with any role the user actually holds, producing an access token that yields an unrestricted Keystone token with roles beyond the application credential's restricted set. Add an explicit check for application credential tokens on the OAuth1 authorize endpoint, consistent with how trust-scoped and OAuth-scoped tokens are already blocked. Related-Bug: #2142138 Generated-By: claude-opus-4-6 (OpenCode) Signed-off-by: Boris Bobrov Change-Id: I9506557609ff7edaa6a961f356f9b8e19faaefc3 (cherry picked from commit 29246c5fd8d1dafbe6cc8cec4c57faf5590cd44e) --- keystone/api/os_oauth1.py | 11 +++++++++++ keystone/tests/unit/test_v3_oauth1.py | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/keystone/api/os_oauth1.py b/keystone/api/os_oauth1.py index da3da54f3..4870d9a06 100644 --- a/keystone/api/os_oauth1.py +++ b/keystone/api/os_oauth1.py @@ -318,6 +318,17 @@ class AuthorizeResource(_OAuth1ResourceBase): 'delegation.' ) ) + auth_context = flask.request.environ.get( + authorization.AUTH_CONTEXT_ENV, {} + ) + token = auth_context.get('token') + if token and 'application_credential' in token.methods: + raise exception.Forbidden( + _( + 'Cannot authorize a request token with a token issued via ' + 'delegation.' + ) + ) req_token = PROVIDERS.oauth_api.get_request_token(request_token_id) diff --git a/keystone/tests/unit/test_v3_oauth1.py b/keystone/tests/unit/test_v3_oauth1.py index 8229b8850..0a6c680a8 100644 --- a/keystone/tests/unit/test_v3_oauth1.py +++ b/keystone/tests/unit/test_v3_oauth1.py @@ -699,6 +699,30 @@ class AuthTokenTests: url = f'/users/{self.user_id}/OS-OAUTH1/access_tokens' self.get(url, token=trust_token, expected_status=http.client.FORBIDDEN) + def _create_app_cred_get_token(self): + ref = unit.new_application_credential_ref(roles=[{'id': self.role_id}]) + del ref['id'] + r = self.post( + f'/users/{self.user_id}/application_credentials', + body={'application_credential': ref}, + ) + app_cred = r.result['application_credential'] + auth_data = self.build_authentication_request( + app_cred_id=app_cred['id'], secret=app_cred['secret'] + ) + return self.get_requested_token(auth_data) + + def test_app_cred_token_cannot_authorize_request_token(self): + app_cred_token = self._create_app_cred_get_token() + url = self._approve_request_token_url() + body = {'roles': [{'id': self.role_id}]} + self.put( + url, + body=body, + token=app_cred_token, + expected_status=http.client.FORBIDDEN, + ) + class FernetAuthTokenTests(AuthTokenTests, OAuthFlowTests): def config_overrides(self): -- 2.47.3