From 2ee7a3a35698ff5696af2a7dded863103577db8a Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Wed, 31 May 2023 16:02:46 -0700 Subject: [PATCH] Prevent triggering a function off of a function --- src/Appwrite/Event/Validator/Event.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Event/Validator/Event.php b/src/Appwrite/Event/Validator/Event.php index 4bf501f2d3..c67d60055b 100644 --- a/src/Appwrite/Event/Validator/Event.php +++ b/src/Appwrite/Event/Validator/Event.php @@ -7,6 +7,11 @@ use Utopia\Validator; class Event extends Validator { + /** + * @var string + */ + protected string $message = 'Event is not valid.'; + /** * Get Description. * @@ -16,7 +21,7 @@ class Event extends Validator */ public function getDescription(): string { - return 'Event is not valid.'; + return $this->message; } /** @@ -40,6 +45,12 @@ class Event extends Validator * Identify all sections of the pattern. */ $type = $parts[0] ?? false; + + if ($type == 'functions') { + $this->message = 'Triggering a function on a function event is not allowed.'; + return false; + } + $resource = $parts[1] ?? false; $hasSubResource = $count > 3 && ($events[$type]['$resource'] ?? false) && ($events[$type][$parts[2]]['$resource'] ?? false); $hasSubSubResource = $count > 5 && $hasSubResource && ($events[$type][$parts[2]][$parts[4]]['$resource'] ?? false);