diff --git a/CHANGES.md b/CHANGES.md index 670d33dd70..f37bd7bf5d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -18,6 +18,7 @@ - Fixed network calculation for uploaded files - Fixed a UI bug preventing float values in numeric fields - Fixed scroll positioning when moving rules order up & down +- Fixed missing validation for database documents key length (32 chars) ## Security diff --git a/app/views/console/database/collection.phtml b/app/views/console/database/collection.phtml index 8c6c75754d..c3ed6e5574 100644 --- a/app/views/console/database/collection.phtml +++ b/app/views/console/database/collection.phtml @@ -1,6 +1,7 @@ getParam('collection', []); $rules = $collection->getAttribute('rules', []); +$maxCells = 10; ?>
getAttribute('rules', []); - $rule): + if($i > $maxCells) { + break; + } $label = (isset($rule['label'])) ? $rule['label'] : ''; ?> @@ -96,7 +100,10 @@ $rules = $collection->getAttribute('rules', []); - $rule): + if($i > $maxCells) { + break; + } $label = (isset($rule['label'])) ? $rule['label'] : ''; $key = (isset($rule['key'])) ? $rule['key'] : ''; $type = (isset($rule['type'])) ? $rule['type'] : ''; @@ -251,7 +258,7 @@ $rules = $collection->getAttribute('rules', []);
- +
@@ -404,7 +411,7 @@ $rules = $collection->getAttribute('rules', []);
- +
diff --git a/src/Appwrite/Database/Validator/Key.php b/src/Appwrite/Database/Validator/Key.php index aef689fe02..f6cc7ce91f 100644 --- a/src/Appwrite/Database/Validator/Key.php +++ b/src/Appwrite/Database/Validator/Key.php @@ -34,11 +34,15 @@ class Key extends Validator */ public function isValid($value) { + if(!is_string($value)) { + return false; + } + if (preg_match('/[^A-Za-z0-9\-\_]/', $value)) { return false; } - if (mb_strlen($value) > 40) { + if (mb_strlen($value) > 32) { return false; } diff --git a/tests/unit/Database/Validator/KeyTest.php b/tests/unit/Database/Validator/KeyTest.php new file mode 100644 index 0000000000..1ec815ce2f --- /dev/null +++ b/tests/unit/Database/Validator/KeyTest.php @@ -0,0 +1,36 @@ +object = new Key(); + } + + public function tearDown() + { + } + + public function testValues() + { + $this->assertEquals($this->object->isValid('dasda asdasd'), false); + $this->assertEquals($this->object->isValid('asdasdasdas'), true); + $this->assertEquals($this->object->isValid('as$$5dasdasdas'), false); + $this->assertEquals($this->object->isValid(false), false); + $this->assertEquals($this->object->isValid(null), false); + $this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscribers'), false); + $this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscriber'), false); + $this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscribe'), true); + $this->assertEquals($this->object->isValid('socialAccountForYoutubeSubscrib'), true); + } +} \ No newline at end of file
escape($label); ?>