From f9c18a64622540d4b566a397994188bdb2950ffe Mon Sep 17 00:00:00 2001 From: ArnabChatterjee20k Date: Wed, 6 May 2026 13:20:19 +0530 Subject: [PATCH] updated validator subscribe --- .../Message/Validators/SubscribePayload.php | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Realtime/Message/Validators/SubscribePayload.php b/src/Appwrite/Realtime/Message/Validators/SubscribePayload.php index d76955d873..da99b8c555 100644 --- a/src/Appwrite/Realtime/Message/Validators/SubscribePayload.php +++ b/src/Appwrite/Realtime/Message/Validators/SubscribePayload.php @@ -2,6 +2,7 @@ namespace Appwrite\Realtime\Message\Validators; +use Appwrite\Utopia\Database\Validator\CustomId; use Utopia\Validator; class SubscribePayload extends Validator @@ -30,11 +31,17 @@ class SubscribePayload extends Validator return false; } + $customId = new CustomId(); + foreach ($value as $payload) { if (!\is_array($payload)) { $this->description = 'Each subscribe payload must be an object.'; return false; } + if (\array_key_exists('subscriptionId', $payload) && !$customId->isValid($payload['subscriptionId'])) { + $this->description = 'subscriptionId is not a valid id.'; + return false; + } if (!\array_key_exists('channels', $payload)) { $this->description = 'channels is not present in payload.'; return false; @@ -43,12 +50,15 @@ class SubscribePayload extends Validator $this->description = 'channels is not a valid array.'; return false; } - if (\array_key_exists('queries', $payload) - && (!\is_array($payload['queries']) || !\array_is_list($payload['queries'])) - ) { - $this->description = 'queries is not a valid array.'; - return false; + foreach ($payload['channels'] as $channel) { + if (!\is_string($channel)) { + $this->description = 'channels must contain only strings.'; + return false; + } } + + // not validating queries here as we will be doing it anyways during the controller level + // kind of expensive validating queries twice as we need to check a lot of cases } return true;