From 5d1843e74935fd9d5f01c9ab275f9c788b725504 Mon Sep 17 00:00:00 2001 From: Luka Trovic Date: Thu, 23 Jul 2026 09:30:09 +0200 Subject: [PATCH] fix: validate board permission in setDoneStack method Signed-off-by: Luka Trovic --- lib/Service/StackService.php | 5 +++++ tests/unit/Service/StackServiceTest.php | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/lib/Service/StackService.php b/lib/Service/StackService.php index 9effcd3885..f9b5ffc844 100644 --- a/lib/Service/StackService.php +++ b/lib/Service/StackService.php @@ -307,6 +307,11 @@ public function reorder(int $id, int $order): array { */ public function setDoneStack(int $stackId, int $boardId, bool $isDone): void { $this->permissionService->checkPermission($this->stackMapper, $stackId, Acl::PERMISSION_MANAGE); + $stack = $this->stackMapper->find($stackId); + + if ($stack->getBoardId() !== $boardId) { + throw new BadRequestException('Stack does not belong to the specified board.'); + } if ($this->boardService->isArchived($this->stackMapper, $stackId)) { throw new NoPermissionException('Operation not allowed. This board is archived.'); diff --git a/tests/unit/Service/StackServiceTest.php b/tests/unit/Service/StackServiceTest.php index 4b7c6476eb..fde58b709f 100644 --- a/tests/unit/Service/StackServiceTest.php +++ b/tests/unit/Service/StackServiceTest.php @@ -276,6 +276,10 @@ private function createStack(int $id, int $order) { public function testSetDoneStackSetsDoneColumn(): void { $this->permissionService->expects($this->once())->method('checkPermission'); + $this->stackMapper->expects($this->once()) + ->method('find') + ->with(5) + ->willReturn($this->createStack(5, 0)); $this->boardService->expects($this->once())->method('isArchived')->willReturn(false); $this->stackMapper->expects($this->once()) ->method('clearDoneColumnForBoard') @@ -303,6 +307,10 @@ public function testSetDoneStackSetsDoneColumn(): void { public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void { $this->permissionService->expects($this->once())->method('checkPermission'); $this->boardService->expects($this->once())->method('isArchived')->willReturn(false); + $this->stackMapper->expects($this->once()) + ->method('find') + ->with(5) + ->willReturn($this->createStack(5, 0)); $this->stackMapper->expects($this->never())->method('clearDoneColumnForBoard'); $this->cardMapper->expects($this->never())->method('findAll'); $this->cardMapper->expects($this->never())->method('update'); @@ -314,9 +322,24 @@ public function testSetDoneStackDoesNotMarkCardsWhenUnsetting(): void { public function testSetDoneStackThrowsOnArchivedBoard(): void { $this->permissionService->expects($this->once())->method('checkPermission'); + $this->stackMapper->expects($this->once()) + ->method('find') + ->with(5) + ->willReturn($this->createStack(5, 0)); $this->boardService->expects($this->once())->method('isArchived')->willReturn(true); $this->stackMapper->expects($this->never())->method('setIsDoneColumn'); $this->expectException(\OCA\Deck\NoPermissionException::class); $this->stackService->setDoneStack(5, 1, true); } + + public function testSetDoneStackThrowsOnMismatchBoardId(): void { + $this->permissionService->expects($this->once())->method('checkPermission'); + $this->stackMapper->expects($this->once()) + ->method('find') + ->with(5) + ->willReturn($this->createStack(5, 0)); + $this->stackMapper->expects($this->never())->method('setIsDoneColumn'); + $this->expectException(\OCA\Deck\BadRequestException::class); + $this->stackService->setDoneStack(5, 2, true); + } }