From ab35f67e85d882522181c4bb4acf242bafd5d88a Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 28 Oct 2026 10:42:48 +0100 Subject: [PATCH 1/2] fix(dav): Check ownership of face detections Face photos were resolved by detection id without checking that the detection belongs to the requesting user, which allowed moving other users' detections into one's own clusters. Assisted-by: ClaudeCode:claude-opus-5.5 Signed-off-by: Marcel Klehr (cherry picked from commit a810793a850b1d9fd080e53c90f78473918de666) --- lib/Dav/Faces/FaceRoot.php | 5 ++++- lib/Dav/Faces/UnassignedFacesHome.php | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Dav/Faces/FaceRoot.php b/lib/Dav/Faces/FaceRoot.php index 97b0d8625..6df6babfd 100644 --- a/lib/Dav/Faces/FaceRoot.php +++ b/lib/Dav/Faces/FaceRoot.php @@ -114,7 +114,7 @@ public function getChild($name): FacePhoto { } catch (DoesNotExistException $e) { throw new NotFound(); } - if ($detection->getClusterId() !== $this->cluster->getId()) { + if ($detection->getUserId() !== $this->user->getUID() || $detection->getClusterId() !== $this->cluster->getId()) { throw new NotFound(); } return new FacePhoto($this->detectionMapper, $detection, $this->rootFolder->getUserFolder($this->user->getUID()), $this->tagManager, $this->previewManager); @@ -131,6 +131,9 @@ public function childExists($name): bool { public function moveInto($targetName, $sourcePath, INode $sourceNode) { if ($sourceNode instanceof FacePhoto) { + if ($sourceNode->getFaceDetection()->getUserId() !== $this->user->getUID()) { + throw new Forbidden('Not allowed to move face detections of other users'); + } $sourceNode->getFaceDetection()->setClusterId($this->cluster->getId()); $this->detectionMapper->update($sourceNode->getFaceDetection()); return true; diff --git a/lib/Dav/Faces/UnassignedFacesHome.php b/lib/Dav/Faces/UnassignedFacesHome.php index a1d491d42..d38d8cf54 100644 --- a/lib/Dav/Faces/UnassignedFacesHome.php +++ b/lib/Dav/Faces/UnassignedFacesHome.php @@ -76,7 +76,7 @@ public function getChild($name): UnassignedFacePhoto { } catch (DoesNotExistException $e) { throw new NotFound(); } - if ($detection->getClusterId() !== -1) { + if ($detection->getUserId() !== $this->user->getUID() || $detection->getClusterId() !== -1) { throw new NotFound(); } From 9cd55935844c2b4288e4e8bf8cd2039a18b38fb9 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 28 Oct 2026 10:48:18 +0100 Subject: [PATCH 2/2] fix(dav): Only return the current user's face detections The face-detections property returned the detections of all users with access to a file, including their private cluster titles. (adapted from commit 9f046d39) Assisted-by: ClaudeCode:claude-opus-5.5 Signed-off-by: Marcel Klehr --- lib/Dav/Faces/PropFindPlugin.php | 19 +++++++++++++++++-- lib/Db/FaceDetectionMapper.php | 4 +++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/lib/Dav/Faces/PropFindPlugin.php b/lib/Dav/Faces/PropFindPlugin.php index 41721e2a1..d32bbdebe 100644 --- a/lib/Dav/Faces/PropFindPlugin.php +++ b/lib/Dav/Faces/PropFindPlugin.php @@ -20,6 +20,7 @@ use OCP\DB\Exception; use OCP\Files\DavUtil; use OCP\IPreview; +use OCP\IUserSession; use OCP\Security\ICrypto; use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; @@ -49,6 +50,7 @@ public function __construct( private LoggerInterface $logger, private ITimeFactory $timeFactory, private IAppConfig $appConfig, + private IUserSession $userSession, ) { } @@ -61,13 +63,26 @@ public function initialize(Server $server): void { } + /** + * @return list + * @throws Exception + */ + private function getDetections(int $fileId): array { + // Detections and cluster titles are private to each user + $userId = $this->userSession->getUser()?->getUID(); + if ($userId === null) { + return []; + } + return $this->faceDetectionMapper->findByFileIdWithTitle($fileId, $userId); + } + public function propFind(PropFind $propFind, INode $node): void { if ($node instanceof FacePhoto) { $propFind->handle(self::FACE_DETECTIONS_PROPERTYNAME, function () use ($node) { return json_encode( array_map( fn (FaceDetectionWithTitle $face) => $face->toArray(), - $this->faceDetectionMapper->findByFileIdWithTitle($node->getFile()->getId()) + $this->getDetections($node->getFile()->getId()) ) ); }); @@ -102,7 +117,7 @@ public function propFind(PropFind $propFind, INode $node): void { return json_encode( array_map( fn (FaceDetectionWithTitle $face) => $face->toArray(), - $this->faceDetectionMapper->findByFileIdWithTitle($node->getId()), + $this->getDetections((int)$node->getId()), ) ); }); diff --git a/lib/Db/FaceDetectionMapper.php b/lib/Db/FaceDetectionMapper.php index 939205429..5f2c28e3d 100644 --- a/lib/Db/FaceDetectionMapper.php +++ b/lib/Db/FaceDetectionMapper.php @@ -179,14 +179,16 @@ public function assocWithCluster(FaceDetection $faceDetection, FaceCluster $face /** * @param int $fileId + * @param string $userId * @return list<\OCA\Recognize\Db\FaceDetectionWithTitle> * @throws \OCP\DB\Exception */ - public function findByFileIdWithTitle(int $fileId) : array { + public function findByFileIdWithTitle(int $fileId, string $userId) : array { $qb = $this->db->getQueryBuilder(); $qb->select(array_merge(array_map(fn ($col) => 'd.'.$col, FaceDetection::$columns), ['c.title'])) ->from('recognize_face_detections', 'd') ->where($qb->expr()->eq('file_id', $qb->createPositionalParameter($fileId, IQueryBuilder::PARAM_INT))) + ->andWhere($qb->expr()->eq('d.user_id', $qb->createPositionalParameter($userId, IQueryBuilder::PARAM_STR))) ->leftJoin('d', 'recognize_face_clusters', 'c', $qb->expr()->eq('d.cluster_id', 'c.id')); /** @var list<\OCA\Recognize\Db\FaceDetectionWithTitle> $entities */ $entities = $this->findEntities($qb);