mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
Validate folder cursor as immediate child and correct error code
This commit is contained in:
1 parent
ff14e5dcec
commit
a8beaaabba
2 files changed
+19
-2
No files matched your search
@@ -91,8 +91,11 @@ class XList extends Action
|
||||
$parent = Folder::normalize($parent);
|
||||
$cursor = Folder::normalize($cursor);
|
||||
|
||||
if ($cursor !== '' && (!\str_starts_with($cursor, $parent) || $cursor === $parent)) {
|
||||
throw new Exception(Exception::GENERAL_CURSOR_NOT_FOUND, "Folder '{$cursor}' for the 'cursor' value is not inside '{$parent}'.");
|
||||
if ($cursor !== '') {
|
||||
$remainder = \substr($cursor, \strlen($parent), -1);
|
||||
if (!\str_starts_with($cursor, $parent) || $cursor === $parent || \str_contains($remainder, '/')) {
|
||||
throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, "Folder '{$cursor}' for the 'cursor' value is not an immediate child of '{$parent}'.");
|
||||
}
|
||||
}
|
||||
|
||||
$collection = 'bucket_' . $bucket->getSequence();
|
||||
@@ -145,6 +148,8 @@ class XList extends Action
|
||||
* Smallest string that sorts after every `parent` value inside the given
|
||||
* folder: the trailing '/' replaced with the next code point ('0'), so a
|
||||
* seek jumps past all of the folder's contents in one indexed query.
|
||||
* Assumes the database orders `parent` values bytewise (binary collation),
|
||||
* so nothing sorts between '/' (0x2F) and '0' (0x30).
|
||||
*/
|
||||
private static function seekPast(string $folder): string
|
||||
{
|
||||
|
||||
@@ -2151,6 +2151,18 @@ trait StorageBase
|
||||
// nonexistent prefix -- empty list, not 404
|
||||
$this->assertCount(0, $listFolders(['parent' => 'missing']));
|
||||
|
||||
// crafted cursors -- must be an immediate child of parent
|
||||
foreach ([
|
||||
['parent' => 'photos', 'cursor' => 'photos/2026/july'], // grandchild
|
||||
['parent' => 'photos', 'cursor' => 'invoices'], // outside parent
|
||||
] as $params) {
|
||||
$response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/folders', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), $params);
|
||||
$this->assertEquals(400, $response['headers']['status-code']);
|
||||
}
|
||||
|
||||
// implicit lifecycle -- deleting the last file removes the folder chain
|
||||
$delete = $this->client->call(Client::METHOD_DELETE, '/storage/buckets/' . $bucketId . '/files/' . $julyFileId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
||||
Reference in new issue
Block a user