diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php index 76587ec135..7cacfcc1d9 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Base.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Base.php @@ -132,7 +132,7 @@ class Base extends Types $context = new QueryContext(); $context->add($this->collection); - parent::__construct($this->types, $context); + parent::__construct($this->types, $context, $allowedAttributes); } public function isSelectQueryAllowed(): bool diff --git a/src/Appwrite/Utopia/Database/Validator/Queries/Types.php b/src/Appwrite/Utopia/Database/Validator/Queries/Types.php index 6b92ce9801..6cfc56f577 100644 --- a/src/Appwrite/Utopia/Database/Validator/Queries/Types.php +++ b/src/Appwrite/Utopia/Database/Validator/Queries/Types.php @@ -28,17 +28,25 @@ class Types extends Validator protected ?QueryContext $context = null; /** - * @param array $types + * @param string[] $allowedAttributes */ - public function __construct(array $types = [], ?QueryContext $context = null) + protected array $allowedAttributes; + + /** + * @param array $types + * @param QueryContext|null $context + * @param array $allowedAttributes + */ + public function __construct(array $types = [], ?QueryContext $context = null, array $allowedAttributes = []) { $this->types = $types; - if ($context === null) { + if (is_null($context)) { $context = new QueryContext(); } $this->context = $context; + $this->allowedAttributes = $allowedAttributes; } /** @@ -69,11 +77,6 @@ class Types extends Validator $query = Query::parse($query); } - if (Query::isFilter($query->getMethod())) { - throw new \Exception('shmuel'); - // Check only allowed attribtes!! - } - if ($query->isNested()) { if (!self::isValid($query->getValues())) { throw new \Exception('Invalid queries'); @@ -83,6 +86,20 @@ class Types extends Validator if (!in_array($query->getMethod(), $this->types)) { throw new \Exception("Query method {$query->getMethod()} not allowed"); } + + /** + * Check only allowed attributed + */ + //if (Query::isFilter($query->getMethod())) { + if ( + $query->getMethod() !== Query::TYPE_SELECT && + !empty($query->getAttribute()) && + !in_array($query->getAttribute(), $this->allowedAttributes) + ) { + throw new \Exception('shmuel'); + } + //} + } $validator = new DocumentsValidator(