From 0aceb8fd11d3250098b64f74c5c2ed79b3ba4339 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 11 Dec 2025 07:50:18 +0100 Subject: [PATCH] fix(comments): Check comment object Signed-off-by: Joas Schilling --- apps/dav/lib/Comments/EntityCollection.php | 9 ++++++-- .../unit/Comments/EntityCollectionTest.php | 23 +++++++++++++++---- lib/private/DB/QueryBuilder/QueryBuilder.php | 8 +++++++ .../Sharded/ShardedQueryBuilder.php | 12 ++++++++-- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/apps/dav/lib/Comments/EntityCollection.php b/apps/dav/lib/Comments/EntityCollection.php index 19af2d9c234..7c120a37a84 100644 --- a/apps/dav/lib/Comments/EntityCollection.php +++ b/apps/dav/lib/Comments/EntityCollection.php @@ -84,6 +84,10 @@ class EntityCollection extends RootCollection implements IProperties { public function getChild($name) { try { $comment = $this->commentsManager->get($name); + if ($comment->getObjectType() !== $this->name + || $comment->getObjectId() !== $this->id) { + throw new NotFound(); + } return new CommentNode( $this->commentsManager, $comment, @@ -137,8 +141,9 @@ class EntityCollection extends RootCollection implements IProperties { */ public function childExists($name) { try { - $this->commentsManager->get($name); - return true; + $comment = $this->commentsManager->get($name); + return $comment->getObjectType() === $this->name + && $comment->getObjectId() === $this->id; } catch (NotFoundException $e) { return false; } diff --git a/apps/dav/tests/unit/Comments/EntityCollectionTest.php b/apps/dav/tests/unit/Comments/EntityCollectionTest.php index 0d4adae250e..8c417aeabca 100644 --- a/apps/dav/tests/unit/Comments/EntityCollectionTest.php +++ b/apps/dav/tests/unit/Comments/EntityCollectionTest.php @@ -58,14 +58,16 @@ class EntityCollectionTest extends \Test\TestCase { } public function testGetChild(): void { + $comment = $this->createMock(IComment::class); + $comment->method('getObjectType') + ->willReturn('files'); + $comment->method('getObjectId') + ->willReturn('19'); + $this->commentsManager->expects($this->once()) ->method('get') ->with('55') - ->willReturn( - $this->getMockBuilder(IComment::class) - ->disableOriginalConstructor() - ->getMock() - ); + ->willReturn($comment); $node = $this->collection->getChild('55'); $this->assertTrue($node instanceof \OCA\DAV\Comments\CommentNode); @@ -117,6 +119,17 @@ class EntityCollectionTest extends \Test\TestCase { } public function testChildExistsTrue(): void { + $comment = $this->createMock(IComment::class); + $comment->method('getObjectType') + ->willReturn('files'); + $comment->method('getObjectId') + ->willReturn('19'); + + $this->commentsManager->expects($this->once()) + ->method('get') + ->with('44') + ->willReturn($comment); + $this->assertTrue($this->collection->childExists('44')); } diff --git a/lib/private/DB/QueryBuilder/QueryBuilder.php b/lib/private/DB/QueryBuilder/QueryBuilder.php index c0cbff8d3f5..9c891080f40 100644 --- a/lib/private/DB/QueryBuilder/QueryBuilder.php +++ b/lib/private/DB/QueryBuilder/QueryBuilder.php @@ -1117,6 +1117,10 @@ class QueryBuilder implements IQueryBuilder { * @return $this This QueryBuilder instance. */ public function orderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->queryBuilder->orderBy( $this->helper->quoteColumnName($sort), $order @@ -1134,6 +1138,10 @@ class QueryBuilder implements IQueryBuilder { * @return $this This QueryBuilder instance. */ public function addOrderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->queryBuilder->addOrderBy( $this->helper->quoteColumnName($sort), $order diff --git a/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php b/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php index 018b891cd71..3b7347829d1 100644 --- a/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php +++ b/lib/private/DB/QueryBuilder/Sharded/ShardedQueryBuilder.php @@ -276,13 +276,21 @@ class ShardedQueryBuilder extends ExtendedQueryBuilder { } public function addOrderBy($sort, $order = null) { - $this->registerOrder((string) $sort, (string) $order ?? 'ASC'); + if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) { + $order = null; + } + + $this->registerOrder((string) $sort, (string) ($order ?? 'ASC')); return parent::addOrderBy($sort, $order); } public function orderBy($sort, $order = null) { + if ($order !== null && !in_array(strtoupper((string) $order), ['ASC', 'DESC'], true)) { + $order = null; + } + $this->sortList = []; - $this->registerOrder((string) $sort, (string) $order ?? 'ASC'); + $this->registerOrder((string) $sort, (string) ($order ?? 'ASC')); return parent::orderBy($sort, $order); }