Skip to content

Commit

Permalink
Check that the owner of a link share still has share permissions on a…
Browse files Browse the repository at this point in the history
…ccess
  • Loading branch information
icewind1991 authored and DeepDiver1975 committed Jan 15, 2016
1 parent 6a7be4d commit 92b02b8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 2 deletions.
5 changes: 4 additions & 1 deletion apps/dav/appinfo/v1/publicwebdav.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

$requestUri = \OC::$server->getRequest()->getRequestUri();

$server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function () use ($authBackend) {
$server = $serverFactory->createServer($baseuri, $requestUri, $authBackend, function (\Sabre\DAV\Server $server) use ($authBackend) {
$isAjax = (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] === 'XMLHttpRequest');
if (OCA\Files_Sharing\Helper::isOutgoingServer2serverShareEnabled() === false && !$isAjax) {
// this is what is thrown when trying to access a non-existing share
Expand All @@ -68,6 +68,9 @@
OC_Util::setupFS($owner);
$ownerView = \OC\Files\Filesystem::getView();
$path = $ownerView->getPath($fileId);
$fileInfo = $ownerView->getFileInfo($path);

$server->addPlugin(new \OCA\DAV\Files\Sharing\PublicLinkCheckPlugin($share, $fileInfo));

return new \OC\Files\View($ownerView->getAbsolutePath($path));
});
Expand Down
2 changes: 1 addition & 1 deletion apps/dav/lib/connector/sabre/serverfactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function createServer($baseUri,
\OC::$server->getUserFolder();

/** @var \OC\Files\View $view */
$view = $viewCallBack();
$view = $viewCallBack($server);
$rootInfo = $view->getFileInfo('');

// Create ownCloud Dir
Expand Down
66 changes: 66 additions & 0 deletions apps/dav/lib/files/sharing/publicsharecheckplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
/**
* @author Robin Appelman <icewind@owncloud.com>
*
* @copyright Copyright (c) 2015, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

namespace OCA\DAV\Files\Sharing;

use OCP\Files\FileInfo;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ServerPlugin;
use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;

/**
* Verify that the public link share is valid
*/
class PublicLinkCheckPlugin extends ServerPlugin {
/**
* @var FileInfo
*/
private $fileInfo;

/**
* PublicLinkCheckPlugin constructor.
*
* @param FileInfo $fileInfo fileinfo for the shared file or folder from the owner
*/
public function __construct(FileInfo $fileInfo) {
$this->fileInfo = $fileInfo;
}


/**
* This initializes the plugin.
*
* @param \Sabre\DAV\Server $server Sabre server
*
* @return void
*/
public function initialize(\Sabre\DAV\Server $server) {
$server->on('beforeMethod', [$this, 'beforeMethod']);
}

public function beforeMethod(RequestInterface $request, ResponseInterface $response){
// verify that the owner didn't have his share permissions revoked
if (!$this->fileInfo->isShareable()) {
throw new NotFound();
}
}
}

0 comments on commit 92b02b8

Please sign in to comment.