Skip to content
Prev Previous commit
Next Next commit
Prevent access to shareinfo if share if read-only
  • Loading branch information
LukasReschke committed Jun 9, 2016
commit 075bf73c80882943acc6c73abbcc026046e6b226
7 changes: 7 additions & 0 deletions apps/files_sharing/ajax/publicpreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@
}

$linkedItem = \OCP\Share::getShareByToken($token);
$shareManager = \OC::$server->getShareManager();
$share = $shareManager->getShareByToken($token);
if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
OCP\JSON::error(array('data' => 'Share is not readable.'));
exit();
}

if($linkedItem === false || ($linkedItem['item_type'] !== 'file' && $linkedItem['item_type'] !== 'folder')) {
\OC_Response::setStatus(\OC_Response::STATUS_NOT_FOUND);
\OCP\Util::writeLog('core-preview', 'Passed token parameter is not valid', \OCP\Util::DEBUG);
Expand Down
5 changes: 5 additions & 0 deletions apps/files_sharing/ajax/shareinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@
$share = $shareManager->getShareByToken($token);
$sharePermissions= (int)$share->getPermissions();

if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
OCP\JSON::error(array('data' => 'Share is not readable.'));
exit();
}

/**
* @param \OCP\Files\FileInfo $dir
* @param \OC\Files\View $view
Expand Down
8 changes: 7 additions & 1 deletion apps/files_sharing/lib/Controllers/ShareController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ private function validateShare(\OCP\Share\IShare $share) {
* @param string $path
* @return TemplateResponse|RedirectResponse
* @throws NotFoundException
* @throws \Exception
*/
public function showShare($token, $path = '') {
\OC_User::setIncognitoMode(true);
Expand Down Expand Up @@ -373,13 +374,18 @@ public function showShare($token, $path = '') {
* @param string $files
* @param string $path
* @param string $downloadStartSecret
* @return void|RedirectResponse
* @return void|OCP\AppFramework\Http\Response
* @throws NotFoundException
*/
public function downloadShare($token, $files = null, $path = '', $downloadStartSecret = '') {
\OC_User::setIncognitoMode(true);

$share = $this->shareManager->getShareByToken($token);

if(!($share->getPermissions() & \OCP\Constants::PERMISSION_READ)) {
return new OCP\AppFramework\Http\DataResponse('Share is read-only');
}

// Share is password protected - check whether the user is permitted to access the share
if ($share->getPassword() !== null && !$this->linkShareAuth($share)) {
return new RedirectResponse($this->urlGenerator->linkToRoute('files_sharing.sharecontroller.authenticate',
Expand Down