Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion apps/files_trashbin/lib/Trashbin.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,16 @@
use OCP\FilesMetadata\IFilesMetadataManager;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IUserManager;
use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException;
use OCP\Server;
use OCP\Share\Exceptions\ShareNotFound;
use OCP\Util;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Psr\Log\LoggerInterface;

/** @template-implements IEventListener<BeforeNodeDeletedEvent> */
Expand Down Expand Up @@ -326,13 +330,16 @@ public static function move2trash($file_path, $ownerOnly = false) {
}

if ($moveSuccessful) {
// there is still a possibility that the file has been deleted by a remote user
$deletedBy = self::overwriteDeletedBy($user);

$query = Server::get(IDBConnection::class)->getQueryBuilder();
$query->insert('files_trash')
->setValue('id', $query->createNamedParameter($filename))
->setValue('timestamp', $query->createNamedParameter($timestamp))
->setValue('location', $query->createNamedParameter($location))
->setValue('user', $query->createNamedParameter($owner))
->setValue('deleted_by', $query->createNamedParameter($user));
->setValue('deleted_by', $query->createNamedParameter($deletedBy));
$result = $query->executeStatement();
if (!$result) {
Server::get(LoggerInterface::class)->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
Expand Down Expand Up @@ -1182,6 +1189,29 @@ private static function getNodeForPath(string $user, string $path, string $baseD
}
}

/**
* in case the request is authed, and user token is from a federated share
* we use shared_with as initiator of the deletion
*/
private static function overwriteDeletedBy(string $user) {
try {
$request = Server::get(IRequest::class);
/** @psalm-suppress NoInterfaceProperties */
$token = $request->server['PHP_AUTH_USER'] ?? '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this somehow allow forging the value, so it looks like someone else deleted the file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the webdav request is authed, it might be by using the share token.
I only check if this is the case so I can assign a name to the deleter.

Yes, if you know the share token, you can delete the file (if the share has permission), but this is the expected behavior

if ($token === '') {
return $user;
}

$federatedShareProvider = Server::get(\OCA\FederatedFileSharing\FederatedShareProvider::class);
$share = $federatedShareProvider->getShareByToken($token);

return $share->getSharedWith();
} catch (NotFoundExceptionInterface|ContainerExceptionInterface|ShareNotFound) {
}

return $user;
}

public function handle(Event $event): void {
if ($event instanceof BeforeNodeDeletedEvent) {
self::ensureFileScannedHook($event->getNode());
Expand Down
Loading