From 865a994d30e6f736a34b5af4dd3f2183749942f0 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 29 Oct 2026 17:16:32 +0100 Subject: [PATCH 1/3] fix(files): check that the source is deletable before moving between storages `Local::moveFromStorage()`, the same-storage branch of `Common::moveFromStorage()` and the same-bucket branch of `ObjectStoreStorage::moveFromStorage()` resolve the jail of the source storage and move the file on the underlying storage. This also skips any `PermissionsMask` of the source, so a file could be moved out of a share or mount without delete permissions. Check `isDeletable()` on the source before taking any of these shortcuts, like the generic copy-and-delete fallback already does. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4RX49FAX. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- .../Files/ObjectStore/ObjectStoreStorage.php | 4 +++ lib/private/Files/Storage/Common.php | 9 ++--- lib/private/Files/Storage/Local.php | 5 +++ .../ObjectStore/ObjectStoreStorageTest.php | 22 ++++++++++++ tests/lib/Files/ViewTest.php | 36 +++++++++++++++++++ 5 files changed, 72 insertions(+), 4 deletions(-) diff --git a/lib/private/Files/ObjectStore/ObjectStoreStorage.php b/lib/private/Files/ObjectStore/ObjectStoreStorage.php index a08ae2f2ace26..e1f5ebe2014b8 100644 --- a/lib/private/Files/ObjectStore/ObjectStoreStorage.php +++ b/lib/private/Files/ObjectStore/ObjectStoreStorage.php @@ -631,6 +631,10 @@ public function copyFromStorage( #[\Override] public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath, ?ICacheEntry $sourceCacheEntry = null): bool { + if (!$sourceStorage->isDeletable($sourceInternalPath)) { + return false; + } + $sourceCache = $sourceStorage->getCache(); // An encrypted source has to be read through its encryption wrapper: the metadata diff --git a/lib/private/Files/Storage/Common.php b/lib/private/Files/Storage/Common.php index 34358f821ed4d..3683d085fe8d8 100644 --- a/lib/private/Files/Storage/Common.php +++ b/lib/private/Files/Storage/Common.php @@ -602,6 +602,11 @@ private function isSameStorage(IStorage $storage): bool { #[\Override] public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { + // check before resolving the jail, as that also drops any permission mask of the source + if (!$sourceStorage->isDeletable($sourceInternalPath)) { + return false; + } + if ( !$sourceStorage->instanceOfStorage(Encryption::class) && $this->isSameStorage($sourceStorage) @@ -618,10 +623,6 @@ public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalP return $this->rename($sourceInternalPath, $targetInternalPath); } - if (!$sourceStorage->isDeletable($sourceInternalPath)) { - return false; - } - $result = $this->copyFromStorage($sourceStorage, $sourceInternalPath, $targetInternalPath, true); if ($result) { // keeping the source cache entry preserves the file id when leaving an object diff --git a/lib/private/Files/Storage/Local.php b/lib/private/Files/Storage/Local.php index d94c34920026f..e3df7bd9fd34f 100644 --- a/lib/private/Files/Storage/Local.php +++ b/lib/private/Files/Storage/Local.php @@ -648,6 +648,11 @@ public function copyFromStorage(IStorage $sourceStorage, string $sourceInternalP #[\Override] public function moveFromStorage(IStorage $sourceStorage, string $sourceInternalPath, string $targetInternalPath): bool { if ($this->canDoCrossStorageMove($sourceStorage)) { + // check before resolving the jail, as that also drops any permission mask of the source + if (!$sourceStorage->isDeletable($sourceInternalPath)) { + return false; + } + // resolve any jailed paths while ($sourceStorage->instanceOfStorage(Jail::class)) { /** diff --git a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php index c896eb377978c..dc02a4a103b1c 100644 --- a/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php +++ b/tests/lib/Files/ObjectStore/ObjectStoreStorageTest.php @@ -11,6 +11,7 @@ use OC\Files\ObjectStore\StorageObjectStore; use OC\Files\Storage\Temporary; use OC\Files\Storage\Wrapper\Jail; +use OC\Files\Storage\Wrapper\PermissionsMask; use OCP\Constants; use OCP\Files\ObjectStore\IObjectStore; use Test\Files\Storage\Storage; @@ -231,6 +232,27 @@ public function testCopyBetweenJails(): void { $this->assertEquals('3', $this->instance->file_get_contents('b/target/sub/3.txt')); } + public function testMoveFromNonDeletableJail(): void { + $this->instance->mkdir('a'); + $this->instance->mkdir('b'); + $this->instance->file_put_contents('a/1.txt', '1'); + $jailA = new Jail([ + 'storage' => new PermissionsMask([ + 'storage' => $this->instance, + 'mask' => Constants::PERMISSION_ALL & ~Constants::PERMISSION_DELETE, + ]), + 'root' => 'a' + ]); + $jailB = new Jail([ + 'storage' => $this->instance, + 'root' => 'b' + ]); + + $this->assertFalse($jailB->moveFromStorage($jailA, '1.txt', '1.txt')); + $this->assertEquals('1', $this->instance->file_get_contents('a/1.txt')); + $this->assertFalse($this->instance->file_exists('b/1.txt')); + } + public function testCopyGrantsPermissions(): void { $config['objectstore'] = $this->objectStorage; $instance = new ObjectStoreStorageOverwrite($config); diff --git a/tests/lib/Files/ViewTest.php b/tests/lib/Files/ViewTest.php index c0a460c148470..812aa49e78ef2 100644 --- a/tests/lib/Files/ViewTest.php +++ b/tests/lib/Files/ViewTest.php @@ -16,6 +16,8 @@ use OC\Files\Storage\Common; use OC\Files\Storage\Storage; use OC\Files\Storage\Temporary; +use OC\Files\Storage\Wrapper\Jail; +use OC\Files\Storage\Wrapper\PermissionsMask; use OC\Files\View; use OC\Share20\ShareDisableChecker; use OCA\Files_Trashbin\Trash\ITrashManager; @@ -1164,6 +1166,40 @@ public function testRenameCrossStoragePreserveMtime(): void { $this->assertEquals($time, $view->filemtime('/test/sub/storage/foo/bar.txt')); } + public static function renameFromNonDeletableJailProvider(): array { + return [ + 'local' => [Temporary::class, false], + 'local, same storage' => [Temporary::class, true], + 'common' => [TemporaryNoCross::class, false], + 'common, same storage' => [TemporaryNoCross::class, true], + ]; + } + + #[\PHPUnit\Framework\Attributes\DataProvider('renameFromNonDeletableJailProvider')] + public function testRenameFromNonDeletableJail(string $class, bool $sameStorage): void { + Server::get(IStorageFactory::class)->removeStorageWrapper('oc_encryption'); + + $storage = new $class([]); + $sourceStorage = $sameStorage ? $storage : new $class([]); + $sourceStorage->mkdir('shared'); + $sourceStorage->file_put_contents('shared/foo.txt', 'foo'); + $sourceStorage->getScanner()->scan(''); + + Filesystem::mount($storage, [], '/test/'); + Filesystem::mount(new Jail([ + 'storage' => new PermissionsMask([ + 'storage' => $sourceStorage, + 'mask' => Constants::PERMISSION_ALL & ~Constants::PERMISSION_DELETE, + ]), + 'root' => 'shared', + ]), [], '/test/readonly'); + + $view = new View('/test'); + $this->assertFalse($view->rename('readonly/foo.txt', 'foo.txt')); + $this->assertTrue($sourceStorage->file_exists('shared/foo.txt')); + $this->assertFalse($storage->file_exists('foo.txt')); + } + public function testRenameFailDeleteTargetKeepSource(): void { $this->doTestCopyRenameFail('rename'); } From 7a984e2a4518feafdd98b0174cb416dd02b8011c Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 29 Oct 2026 17:19:07 +0100 Subject: [PATCH 2/3] fix(files): check source permissions in Node::move() `Node::move()` only checked that the target folder accepts new files, but never that the source may be moved away. Any caller passing it a node from a share or mount without delete permissions could therefore move that file out. Apply the same checks as WebDAV (`FilesPlugin::checkMove()`): a rename within the same folder follows `DavUtil::canRename()`, a move into another folder requires the source to be deletable unless it is the root of a movable mount. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4RX49FAX. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- lib/private/Files/Node/Node.php | 12 ++++++++ tests/lib/Files/Node/NodeTestCase.php | 43 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lib/private/Files/Node/Node.php b/lib/private/Files/Node/Node.php index 63e275d1f476d..c780115b90682 100644 --- a/lib/private/Files/Node/Node.php +++ b/lib/private/Files/Node/Node.php @@ -14,6 +14,7 @@ use OCP\EventDispatcher\GenericEvent; use OCP\EventDispatcher\IEventDispatcher; use OCP\Files\Cache\ICacheEntry; +use OCP\Files\DavUtil; use OCP\Files\FileInfo; use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; @@ -471,6 +472,17 @@ public function move($targetPath) { ) ) ) { + if (dirname($this->path) === dirname($targetPath)) { + $canMove = DavUtil::canRename($this, $parent); + } else { + // the source is removed from its folder, so it needs to be deletable unless it is a movable mount point + $canMove = $this->isDeletable() + || ($this->getInternalPath() === '' && $this->getMountPoint() instanceof IMovableMount); + } + if (!$canMove) { + throw new NotPermittedException('No permission to move ' . $this->path); + } + $nonExisting = $this->createNonExistingNode($targetPath); $this->sendHooks(['preRename'], [$this, $nonExisting]); $this->sendHooks(['preWrite'], [$nonExisting]); diff --git a/tests/lib/Files/Node/NodeTestCase.php b/tests/lib/Files/Node/NodeTestCase.php index 4605b8c648792..212de8a6939a1 100644 --- a/tests/lib/Files/Node/NodeTestCase.php +++ b/tests/lib/Files/Node/NodeTestCase.php @@ -22,6 +22,7 @@ use OCP\Files\InvalidPathException; use OCP\Files\IRootFolder; use OCP\Files\Mount\IMountPoint; +use OCP\Files\Mount\IMovableMount; use OCP\Files\Node; use OCP\Files\NotFoundException; use OCP\Files\NotPermittedException; @@ -697,6 +698,48 @@ public function testMoveNotPermitted(): void { $node->move('/bar/asd'); } + public static function moveSourcePermissionsProvider(): array { + return [ + 'move needs delete' => ['/other/asd', Constants::PERMISSION_ALL & ~Constants::PERMISSION_DELETE, false, false], + 'move with delete' => ['/other/asd', Constants::PERMISSION_READ | Constants::PERMISSION_DELETE, false, true], + 'move of a movable mount' => ['/other/asd', Constants::PERMISSION_READ, true, true], + 'rename needs update or delete' => ['/bar/asd', Constants::PERMISSION_READ, false, false], + 'rename with update' => ['/bar/asd', Constants::PERMISSION_READ | Constants::PERMISSION_UPDATE, false, true], + 'rename with delete' => ['/bar/asd', Constants::PERMISSION_READ | Constants::PERMISSION_DELETE, false, true], + 'rename of a movable mount' => ['/bar/asd', Constants::PERMISSION_READ, true, true], + ]; + } + + #[\PHPUnit\Framework\Attributes\DataProvider('moveSourcePermissionsProvider')] + public function testMoveSourcePermissions(string $target, int $sourcePermissions, bool $sourceIsMovableMount, bool $allowed): void { + $sourceMount = $sourceIsMovableMount + ? $this->createMockForIntersectionOfInterfaces([IMountPoint::class, IMovableMount::class]) + : $this->createMock(IMountPoint::class); + $sourceMount->method('getStorage') + ->willReturn($this->getMockStorage()); + $sourceInfo = new FileInfo('', $this->getMockStorage(), $sourceIsMovableMount ? '' : 'foo', ['permissions' => $sourcePermissions, 'fileid' => 1], $sourceMount); + $parentInfo = $this->getFileInfo(['permissions' => Constants::PERMISSION_ALL, 'fileid' => 2], 'parent'); + + $this->view->method('getFileInfo') + ->willReturnCallback(fn (string $path) => $path === '/bar/foo' ? $sourceInfo : $parentInfo); + + $this->view->expects($allowed ? $this->once() : $this->never()) + ->method('rename') + ->with('/bar/foo', $target) + ->willReturn(true); + + $node = $this->createTestNode($this->root, $this->view, '/bar/foo'); + $parentNode = new Folder($this->root, $this->view, dirname($target)); + + $this->root->method('get') + ->willReturnMap([[dirname($target), $parentNode], [$target, $node]]); + + if (!$allowed) { + $this->expectException(NotPermittedException::class); + } + $node->move($target); + $this->assertEquals($target, $node->getPath()); + } public function testMoveNoParent(): void { $this->expectException(NotFoundException::class); From ad45c288513642ca3bc0cc1b66463486f9cf016e Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 29 Oct 2026 17:47:32 +0100 Subject: [PATCH 3/3] test(files): cover live photo peers in read-only shares Add integration tests that renaming a live photo still renames its peer, and that a peer in a share without delete permission is not moved out of the share. The move step now also records server errors, as an aborted live photo rename answers with a 500. Discovered by Anthropic's OSS Scanner, as vulnerability ANT-2026-4RX49FAX. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Ferdinand Thiessen --- .../integration/features/bootstrap/WebDav.php | 2 +- .../files_features/live-photos.feature | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/build/integration/features/bootstrap/WebDav.php b/build/integration/features/bootstrap/WebDav.php index dc64680d90c04..e5ebbdaecabc5 100644 --- a/build/integration/features/bootstrap/WebDav.php +++ b/build/integration/features/bootstrap/WebDav.php @@ -114,7 +114,7 @@ public function userMovesFile($user, $entry, $fileSource, $fileDestination) { $headers['Destination'] = $fullUrl . $fileDestination; try { $this->response = $this->makeDavRequest($user, 'MOVE', $fileSource, $headers); - } catch (\GuzzleHttp\Exception\ClientException $e) { + } catch (\GuzzleHttp\Exception\BadResponseException $e) { $this->response = $e->getResponse(); } } diff --git a/build/integration/files_features/live-photos.feature b/build/integration/files_features/live-photos.feature index d104dd1ab50fa..144e5973bf732 100644 --- a/build/integration/files_features/live-photos.feature +++ b/build/integration/files_features/live-photos.feature @@ -89,3 +89,25 @@ Feature: live photos And as "user0" the file "/local_storage/live-photos/IMG.jpg" exists And as "user0" the file "/IMG.jpg" does not exist And User "user0" deletes folder "/local_storage/live-photos" + + Scenario: Renaming a live photo also renames its peer + Given User "user0" uploads file with content "photo" to "/photo.jpg" + And User "user0" uploads file with content "video" to "/photo.mov" + And User "user0" links "/photo.jpg" as live photo to "/photo.mov" + And User "user0" links "/photo.mov" as live photo to "/photo.jpg" + When User "user0" moves file "/photo.jpg" to "/renamed.jpg" + Then as "user0" the file "/renamed.jpg" exists + And as "user0" the file "/renamed.mov" exists + And as "user0" the file "/photo.mov" does not exist + + Scenario: Renaming a live photo does not move its peer out of a read-only share + Given user "user1" exists + And User "user0" created a folder "/handbook" + And User "user0" uploads file with content "chapter one" to "/handbook/chapter.txt" + And folder "/handbook" of user "user0" is shared with user "user1" with permissions 1 + And User "user1" uploads file with content "photo" to "/photo.jpg" + And User "user1" links "/photo.jpg" as live photo to "/handbook/chapter.txt" + When User "user1" moves file "/photo.jpg" to "/mine.jpg" + Then as "user0" the file "/handbook/chapter.txt" exists + And as "user1" the file "/handbook/chapter.txt" exists + And as "user1" the file "/mine.txt" does not exist