From 89c27eef46df420b66c4ecb76e6e658864c9032a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 25 Jun 2026 13:26:27 +0530 Subject: [PATCH 1/3] Fix OAuth admin project authorization --- app/controllers/shared/api.php | 13 ++++++++++++- app/init/constants.php | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index b69fbd86a8..5d3643875d 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -165,6 +165,13 @@ Http::init() // Step 4: Get scopes for the role $scopes = $roles[$role]['scopes']; + $isAdminProjectRequest = ! $user->isEmpty() + && $project->getId() !== 'console' + && $mode === APP_MODE_ADMIN; + $isOAuthAdminProjectRequest = ! empty($apiKey) + && $apiKey->getType() === API_KEY_OAUTH2 + && $apiKey->getRole() === User::ROLE_OWNER + && $isAdminProjectRequest; // Step 5: API Key Authentication if (! empty($apiKey)) { @@ -369,6 +376,10 @@ Http::init() $authorization->addRole($authRole); } + if ($isOAuthAdminProjectRequest) { + $authorization->setDefaultStatus(false); + } + if (!$impersonatorUser->isEmpty() && !$targetUser->isEmpty()) { $dbForProject->setMetadata('user', $targetUser->getId()); $dbForPlatform->setMetadata('user', $targetUser->getId()); @@ -379,7 +390,7 @@ Http::init() * But, for actions on resources (sites, functions, etc.) in a non-console project, we explicitly check * whether the admin user has necessary permission on the project (sites, functions, etc. don't have permissions associated to them). */ - if (empty($apiKey) && ! $user->isEmpty() && $project->getId() !== 'console' && $mode === APP_MODE_ADMIN) { + if ($isAdminProjectRequest && (empty($apiKey) || $isOAuthAdminProjectRequest)) { $input = new Input(Database::PERMISSION_READ, $project->getPermissionsByType(Database::PERMISSION_READ)); $initialStatus = $authorization->getStatus(); $authorization->enable(); diff --git a/app/init/constants.php b/app/init/constants.php index 2b7352e89c..8859937685 100644 --- a/app/init/constants.php +++ b/app/init/constants.php @@ -288,6 +288,7 @@ const API_KEY_STANDARD = 'standard'; const API_KEY_EPHEMERAL = 'ephemeral'; const API_KEY_ORGANIZATION = 'organization'; const API_KEY_ACCOUNT = 'account'; +const API_KEY_OAUTH2 = 'oauth2'; // Realtime const CONSOLE_TAIL_CHANNEL_PREFIX = 'console.tail'; From 0340a49bb8659b0182fac16b5edc00113610d31d Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 25 Jun 2026 13:41:15 +0530 Subject: [PATCH 2/3] Move OAuth admin request check after key auth --- app/controllers/shared/api.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 5d3643875d..273c90651e 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -165,13 +165,6 @@ Http::init() // Step 4: Get scopes for the role $scopes = $roles[$role]['scopes']; - $isAdminProjectRequest = ! $user->isEmpty() - && $project->getId() !== 'console' - && $mode === APP_MODE_ADMIN; - $isOAuthAdminProjectRequest = ! empty($apiKey) - && $apiKey->getType() === API_KEY_OAUTH2 - && $apiKey->getRole() === User::ROLE_OWNER - && $isAdminProjectRequest; // Step 5: API Key Authentication if (! empty($apiKey)) { @@ -376,6 +369,14 @@ Http::init() $authorization->addRole($authRole); } + $isAdminProjectRequest = ! $user->isEmpty() + && $project->getId() !== 'console' + && $mode === APP_MODE_ADMIN; + $isOAuthAdminProjectRequest = ! empty($apiKey) + && $apiKey->getType() === API_KEY_OAUTH2 + && $apiKey->getRole() === User::ROLE_OWNER + && $isAdminProjectRequest; + if ($isOAuthAdminProjectRequest) { $authorization->setDefaultStatus(false); } From 2ad0cbf2f8266c487f109a58b0adff4d52551c36 Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Thu, 25 Jun 2026 13:43:47 +0530 Subject: [PATCH 3/3] Clarify OAuth admin key check --- app/controllers/shared/api.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index 273c90651e..9387eaed17 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -372,12 +372,11 @@ Http::init() $isAdminProjectRequest = ! $user->isEmpty() && $project->getId() !== 'console' && $mode === APP_MODE_ADMIN; - $isOAuthAdminProjectRequest = ! empty($apiKey) + $isOAuthAdminKey = ! empty($apiKey) && $apiKey->getType() === API_KEY_OAUTH2 - && $apiKey->getRole() === User::ROLE_OWNER - && $isAdminProjectRequest; + && $apiKey->getRole() === User::ROLE_OWNER; - if ($isOAuthAdminProjectRequest) { + if ($isAdminProjectRequest && $isOAuthAdminKey) { $authorization->setDefaultStatus(false); } @@ -391,7 +390,7 @@ Http::init() * But, for actions on resources (sites, functions, etc.) in a non-console project, we explicitly check * whether the admin user has necessary permission on the project (sites, functions, etc. don't have permissions associated to them). */ - if ($isAdminProjectRequest && (empty($apiKey) || $isOAuthAdminProjectRequest)) { + if ($isAdminProjectRequest && (empty($apiKey) || $isOAuthAdminKey)) { $input = new Input(Database::PERMISSION_READ, $project->getPermissionsByType(Database::PERMISSION_READ)); $initialStatus = $authorization->getStatus(); $authorization->enable();