-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add share attributes + prevent download permission #32482
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a95c19e
Add share attributes + prevent download permission
PVince81 9493f86
Fix share controller to accept share attributes alone
PVince81 03b1791
Fix share attribute related tests + code style
PVince81 dbbc426
Attempt to fix sqlite json issue
PVince81 54a0d8f
Don't reset share attributes when not specified
PVince81 92e60e3
Add nc:share-attributes Webdav property
PVince81 a11c6e7
Add share attrs + download permission support in frontend
PVince81 2fb7a1f
Fix adding to empty attributes and duplicate request
juliusknorr 2ee659e
Fix view-only code after code review comments
PVince81 3cfb4cb
Block download when needed on direct download endpoint
PVince81 bbb5043
Inherit hide download from share attributes
PVince81 ab1a205
Enforcing permission during resharing
CarlSchwan 7b72381
Multiple fixes
CarlSchwan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
<?php | ||
/** | ||
* @author Piotr Mrowczynski [email protected] | ||
* | ||
* @copyright Copyright (c) 2019, ownCloud GmbH | ||
* @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\DAV; | ||
|
||
use OCA\DAV\Connector\Sabre\Exception\Forbidden; | ||
use OCA\DAV\Connector\Sabre\File as DavFile; | ||
use OCA\DAV\Meta\MetaFile; | ||
use OCP\Files\FileInfo; | ||
use OCP\Files\NotFoundException; | ||
use Psr\Log\LoggerInterface; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\ServerPlugin; | ||
use Sabre\HTTP\RequestInterface; | ||
use Sabre\DAV\Exception\NotFound; | ||
|
||
/** | ||
* Sabre plugin for restricting file share receiver download: | ||
*/ | ||
class ViewOnlyPlugin extends ServerPlugin { | ||
|
||
private ?Server $server = null; | ||
private LoggerInterface $logger; | ||
|
||
public function __construct(LoggerInterface $logger) { | ||
$this->logger = $logger; | ||
} | ||
|
||
/** | ||
* This initializes the plugin. | ||
* | ||
* This function is called by Sabre\DAV\Server, after | ||
* addPlugin is called. | ||
* | ||
* This method should set up the required event subscriptions. | ||
*/ | ||
public function initialize(Server $server): void { | ||
$this->server = $server; | ||
//priority 90 to make sure the plugin is called before | ||
//Sabre\DAV\CorePlugin::httpGet | ||
$this->server->on('method:GET', [$this, 'checkViewOnly'], 90); | ||
} | ||
|
||
/** | ||
* Disallow download via DAV Api in case file being received share | ||
* and having special permission | ||
* | ||
* @throws Forbidden | ||
* @throws NotFoundException | ||
*/ | ||
public function checkViewOnly(RequestInterface $request): bool { | ||
$path = $request->getPath(); | ||
|
||
try { | ||
assert($this->server !== null); | ||
$davNode = $this->server->tree->getNodeForPath($path); | ||
|
||
if (!($davNode instanceof DavFile)) { | ||
return true; | ||
} | ||
// Restrict view-only to nodes which are shared | ||
$node = $davNode->getNode(); | ||
|
||
$storage = $node->getStorage(); | ||
|
||
if (!$storage->instanceOfStorage(\OCA\Files_Sharing\SharedStorage::class)) { | ||
return true; | ||
} | ||
// Extract extra permissions | ||
/** @var \OCA\Files_Sharing\SharedStorage $storage */ | ||
$share = $storage->getShare(); | ||
|
||
$attributes = $share->getAttributes(); | ||
if ($attributes === null) { | ||
return true; | ||
} | ||
|
||
// Check if read-only and on whether permission can download is both set and disabled. | ||
$canDownload = $attributes->getAttribute('permissions', 'download'); | ||
if ($canDownload !== null && !$canDownload) { | ||
throw new Forbidden('Access to this resource has been denied because it is in view-only mode.'); | ||
} | ||
} catch (NotFound $e) { | ||
$this->logger->warning($e->getMessage(), [ | ||
'exception' => $e, | ||
]); | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / Psalm
PossiblyNullArgument