Skip to content

Commit

Permalink
fix(dav): Validate target path before doing a MOVE
Browse files Browse the repository at this point in the history
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
  • Loading branch information
susnux committed Aug 26, 2024
1 parent 63e897a commit 3d131d9
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions apps/dav/lib/Connector/Sabre/FilesPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
namespace OCA\DAV\Connector\Sabre;

use OC\AppFramework\Http\Request;
use OCA\DAV\Connector\Sabre\Exception\InvalidPath;
use OCP\Constants;
use OCP\Files\ForbiddenException;
use OCP\Files\IFilenameValidator;
use OCP\Files\InvalidPathException;
use OCP\Files\StorageNotAvailableException;
use OCP\FilesMetadata\Exceptions\FilesMetadataException;
use OCP\FilesMetadata\Exceptions\FilesMetadataNotFoundException;
Expand Down Expand Up @@ -65,33 +68,26 @@ class FilesPlugin extends ServerPlugin {

/** Reference to main server object */
private ?Server $server = null;
private Tree $tree;
private IUserSession $userSession;

/**
* Whether this is public webdav.
* If true, some returned information will be stripped off.
* @param Tree $tree
* @param IConfig $config
* @param IRequest $request
* @param IPreview $previewManager
* @param IUserSession $userSession
* @param bool $isPublic Whether this is public WebDAV. If true, some returned information will be stripped off.
* @param bool $downloadAttachment
* @return void
*/
private bool $isPublic;
private bool $downloadAttachment;
private IConfig $config;
private IRequest $request;
private IPreview $previewManager;

public function __construct(Tree $tree,
IConfig $config,
IRequest $request,
IPreview $previewManager,
IUserSession $userSession,
bool $isPublic = false,
bool $downloadAttachment = true) {
$this->tree = $tree;
$this->config = $config;
$this->request = $request;
$this->userSession = $userSession;
$this->isPublic = $isPublic;
$this->downloadAttachment = $downloadAttachment;
$this->previewManager = $previewManager;
public function __construct(
private Tree $tree,
private IConfig $config,
private IRequest $request,
private IPreview $previewManager,
private IUserSession $userSession,
private bool $isPublic = false,
private bool $downloadAttachment = true,
) {
}

/**
Expand Down Expand Up @@ -158,7 +154,7 @@ public function checkMove($source, $destination) {
return;
}
[$sourceDir,] = \Sabre\Uri\split($source);
[$destinationDir,] = \Sabre\Uri\split($destination);
[$destinationDir, $destinationName] = \Sabre\Uri\split($destination);

if ($sourceDir !== $destinationDir) {
$sourceNodeFileInfo = $sourceNode->getFileInfo();
Expand All @@ -169,6 +165,13 @@ public function checkMove($source, $destination) {
if (!$sourceNodeFileInfo->isDeletable()) {
throw new Forbidden($source . ' cannot be deleted');
}

$validator = \OCP\Server::get(IFilenameValidator::class);
try {
$validator->validateFilename($destinationName);
} catch (InvalidPathException $e) {
throw new InvalidPath($e->getMessage(), false);
}
}
}

Expand Down

0 comments on commit 3d131d9

Please sign in to comment.