From 18dfaedc376553c7ee702ad41917e4782f597314 Mon Sep 17 00:00:00 2001 From: harsh mahajan Date: Fri, 5 Jun 2026 15:01:45 +0530 Subject: [PATCH] refactor: use Query security scheme variants for impersonation on LOCATION methods --- src/Appwrite/Platform/Tasks/Specs.php | 54 +++++++++++++++++++ .../SDK/Specification/Format/OpenAPI3.php | 3 +- .../SDK/Specification/Format/Swagger2.php | 3 +- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/Specs.php b/src/Appwrite/Platform/Tasks/Specs.php index 8717ae742e..ffe8757a78 100644 --- a/src/Appwrite/Platform/Tasks/Specs.php +++ b/src/Appwrite/Platform/Tasks/Specs.php @@ -181,18 +181,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], APP_SDK_PLATFORM_SERVER => [ 'Project' => [ @@ -255,18 +273,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], APP_SDK_PLATFORM_CONSOLE => [ 'Project' => [ @@ -329,18 +365,36 @@ class Specs extends Action 'description' => 'Impersonate a user by ID on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserIdQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateUserId', + 'description' => 'Impersonate a user by ID via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserEmail' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Email', 'description' => 'Impersonate a user by email on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserEmailQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonateEmail', + 'description' => 'Impersonate a user by email via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], 'ImpersonateUserPhone' => [ 'type' => 'apiKey', 'name' => 'X-Appwrite-Impersonate-User-Phone', 'description' => 'Impersonate a user by phone on an already user-authenticated request. Requires the current request to be authenticated as a user with impersonator capability; X-Appwrite-Key alone is not sufficient. Impersonator users are intentionally granted users.read so they can discover a target before impersonation begins. Internal audit logs still attribute actions to the original impersonator and record the impersonated target only in internal audit payload data.', 'in' => 'header', ], + 'ImpersonateUserPhoneQuery' => [ + 'type' => 'apiKey', + 'name' => 'impersonatePhone', + 'description' => 'Impersonate a user by phone via query param. Used for location-type methods where headers cannot be set.', + 'in' => 'query', + ], ], ]; } diff --git a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php index b852a72658..c40c44b85e 100644 --- a/src/Appwrite/SDK/Specification/Format/OpenAPI3.php +++ b/src/Appwrite/SDK/Specification/Format/OpenAPI3.php @@ -385,9 +385,8 @@ class OpenAPI3 extends Format $temp['x-appwrite']['auth'] = array_slice($securities, 0, $this->authCount); - // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = []; diff --git a/src/Appwrite/SDK/Specification/Format/Swagger2.php b/src/Appwrite/SDK/Specification/Format/Swagger2.php index 31e5e5de07..ca2643222a 100644 --- a/src/Appwrite/SDK/Specification/Format/Swagger2.php +++ b/src/Appwrite/SDK/Specification/Format/Swagger2.php @@ -375,9 +375,8 @@ class Swagger2 extends Format $temp['x-appwrite']['auth'] = \array_slice($securities, 0, $this->authCount); - // Impersonation falls back to query params for location-type methods (browsers can't set headers on resource URLs) if ($sdk->getType() === MethodType::LOCATION) { - foreach (['ImpersonateUserId', 'ImpersonateUserEmail', 'ImpersonateUserPhone'] as $key) { + foreach (['ImpersonateUserIdQuery', 'ImpersonateUserEmailQuery', 'ImpersonateUserPhoneQuery'] as $key) { if (\array_key_exists($key, $this->keys)) { $securities[$key] = []; $temp['x-appwrite']['auth'][$key] = [];