Exploit databaseDownload repository ZIP
GH-8c7f0e4b0e998904a1d6f7dcd99e3e7d
d-xuan/cve-2024-52510
Sources for CVE-2024-52510
1 sourcePreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars.
Repository files5
d-xuan/cve-2024-52510Revision 6c0d89756ae0
- ↑..Parent directory
- V1/
- EncryptionController.php
- KeyController.php
- LockingController.php
- MetaDataController.php
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
apps/end_to_end_encryption/lib/Controller/LockingController.php
PHP · 6,512 bytes<?php
declare(strict_types=1);
/**
* SPDX-License-Identifier: AGPL-3.0+
*
* @copyright Copyright (c) 2017 Bjoern Schiessle <[email protected]>
* @copyright Copyright (c) 2020 Georg Ehrke <[email protected]>
*
* @author Bjoern Schiessle <[email protected]>
* @author Georg Ehrke <[email protected]>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\EndToEndEncryption\Controller;
use OC\User\NoUserException;
use OCA\EndToEndEncryption\Exceptions\FileLockedException;
use OCA\EndToEndEncryption\Exceptions\FileNotLockedException;
use OCA\EndToEndEncryption\FileService;
use OCA\EndToEndEncryption\IMetaDataStorage;
use OCA\EndToEndEncryption\LockManager;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCS\OCSBadRequestException;
use OCP\AppFramework\OCS\OCSForbiddenException;
use OCP\AppFramework\OCS\OCSNotFoundException;
use OCP\AppFramework\OCS\OCSPreconditionFailedException;
use OCP\AppFramework\OCSController;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\IL10N;
use OCP\IRequest;
use OCP\Share\IManager as ShareManager;
use Psr\Log\LoggerInterface;
class LockingController extends OCSController {
private ?string $userId;
private IMetaDataStorage $metaDataStorage;
private IRootFolder $rootFolder;
private FileService $fileService;
private LockManager $lockManager;
private IL10N $l10n;
private LoggerInterface $logger;
private ShareManager $shareManager;
public function __construct(
string $AppName,
IRequest $request,
?string $userId,
IMetaDataStorage $metaDataStorage,
LockManager $lockManager,
IRootFolder $rootFolder,
FileService $fileService,
LoggerInterface $logger,
IL10N $l10n,
ShareManager $shareManager
) {
parent::__construct($AppName, $request);
$this->userId = $userId;
$this->metaDataStorage = $metaDataStorage;
$this->rootFolder = $rootFolder;
$this->fileService = $fileService;
$this->lockManager = $lockManager;
$this->logger = $logger;
$this->l10n = $l10n;
$this->shareManager = $shareManager;
}
/**
* Lock folder
*
* @NoAdminRequired
* @E2ERestrictUserAgent
* @PublicPage
*
* @param int $id file ID
*
* @return DataResponse
* @throws OCSForbiddenException
*/
public function lockFolder(int $id, ?string $shareToken = null): DataResponse {
$e2eToken = $this->request->getParam('e2e-token', '');
$e2eCounter = (int)$this->request->getHeader('X-NC-E2EE-COUNTER');
if ($e2eCounter === 0) {
throw new OCSPreconditionFailedException($this->l10n->t('X-NC-E2EE-COUNTER is missing in the request'));
}
$ownerId = $this->getOwnerId($shareToken);
try {
$userFolder = $this->rootFolder->getUserFolder($ownerId);
} catch (NoUserException $e) {
throw new OCSForbiddenException($this->l10n->t('You are not allowed to create the lock'));
}
if ($userFolder->getId() === $id) {
$e = new OCSForbiddenException($this->l10n->t('You are not allowed to lock the root'));
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw $e;
}
$nodes = $userFolder->getById($id);
if (!isset($nodes[0]) || !$nodes[0] instanceof Folder) {
throw new OCSForbiddenException($this->l10n->t('You are not allowed to create the lock'));
}
$newToken = $this->lockManager->lockFile($id, $e2eToken, $e2eCounter, $ownerId);
if ($newToken === null) {
throw new OCSForbiddenException($this->l10n->t('File already locked'));
}
return new DataResponse(['e2e-token' => $newToken]);
}
/**
* Unlock folder
*
* @NoAdminRequired
* @E2ERestrictUserAgent
* @PublicPage
*
* @param int $id file ID
*
* @return DataResponse
* @throws OCSForbiddenException
* @throws OCSNotFoundException
*/
public function unlockFolder(int $id, ?string $shareToken = null): DataResponse {
$abort = $this->request->getParam('abort') === 'true';
$token = $this->request->getHeader('e2e-token');
if ($token === '') {
throw new OCSPreconditionFailedException($this->l10n->t('e2e-token is empty'));
}
$ownerId = $this->getOwnerId($shareToken);
try {
$userFolder = $this->rootFolder->getUserFolder($ownerId);
} catch (NoUserException $e) {
throw new OCSForbiddenException($this->l10n->t('You are not allowed to remove the lock'));
}
$nodes = $userFolder->getById($id);
if (!isset($nodes[0]) || !$nodes[0] instanceof Folder) {
throw new OCSForbiddenException($this->l10n->t('You are not allowed to remove the lock'));
}
$touchFoldersIds = $this->metaDataStorage->getTouchedFolders($token);
foreach ($touchFoldersIds as $folderId) {
if ($abort) {
$this->fileService->revertChanges($userFolder->getById($folderId)[0]);
$this->metaDataStorage->deleteIntermediateFile($ownerId, $folderId);
} else {
$this->fileService->finalizeChanges($userFolder->getById($folderId)[0]);
$this->metaDataStorage->saveIntermediateFile($ownerId, $folderId);
}
}
$this->metaDataStorage->clearTouchedFolders($token);
try {
$this->lockManager->unlockFile($id, $token);
} catch (FileLockedException $e) {
throw new OCSForbiddenException($this->l10n->t('You are not allowed to remove the lock'));
} catch (FileNotLockedException $e) {
throw new OCSNotFoundException($this->l10n->t('File not locked'));
}
return new DataResponse();
}
private function getOwnerId(?string $shareToken = null): string {
if ($shareToken !== null) {
$share = $this->shareManager->getShareByToken($shareToken);
if (!($share->getPermissions() & \OCP\Constants::PERMISSION_CREATE)) {
throw new OCSForbiddenException("Can't lock share without create permission");
}
return $share->getShareOwner();
} elseif ($this->userId !== null) {
return $this->userId;
} else {
throw new OCSBadRequestException("Couldn't find the owner of the encrypted folder");
}
}
}