Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Block the hidden folder from being shared
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Aug 23, 2022
commit 816d45bb32114c83e18a808eadecfd49971b376c
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
'OCA\\Files\\Event\\LoadSidebar' => $baseDir . '/../lib/Event/LoadSidebar.php',
'OCA\\Files\\Exception\\TransferOwnershipException' => $baseDir . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => $baseDir . '/../lib/Helper.php',
'OCA\\Files\\Listener\\HiddenFolderListener' => $baseDir . '/../lib/Listener/HiddenFolderListener.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => $baseDir . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => $baseDir . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => $baseDir . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
1 change: 1 addition & 0 deletions apps/files/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class ComposerStaticInitFiles
'OCA\\Files\\Event\\LoadSidebar' => __DIR__ . '/..' . '/../lib/Event/LoadSidebar.php',
'OCA\\Files\\Exception\\TransferOwnershipException' => __DIR__ . '/..' . '/../lib/Exception/TransferOwnershipException.php',
'OCA\\Files\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
'OCA\\Files\\Listener\\HiddenFolderListener' => __DIR__ . '/..' . '/../lib/Listener/HiddenFolderListener.php',
'OCA\\Files\\Listener\\LegacyLoadAdditionalScriptsAdapter' => __DIR__ . '/..' . '/../lib/Listener/LegacyLoadAdditionalScriptsAdapter.php',
'OCA\\Files\\Listener\\LoadSidebarListener' => __DIR__ . '/..' . '/../lib/Listener/LoadSidebarListener.php',
'OCA\\Files\\Migration\\Version11301Date20191205150729' => __DIR__ . '/..' . '/../lib/Migration/Version11301Date20191205150729.php',
Expand Down
8 changes: 8 additions & 0 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCA\Files\Controller\ApiController;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCA\Files\Event\LoadSidebar;
use OCA\Files\Listener\HiddenFolderListener;
use OCA\Files\Listener\LegacyLoadAdditionalScriptsAdapter;
use OCA\Files\Listener\LoadSidebarListener;
use OCA\Files\Notification\Notifier;
Expand All @@ -65,6 +66,7 @@
use OCP\Share\IManager as IShareManager;
use OCP\Util;
use Psr\Container\ContainerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

class Application extends App implements IBootstrap {
public const APP_ID = 'files';
Expand Down Expand Up @@ -128,6 +130,7 @@ public function boot(IBootContext $context): void {
$this->registerTemplates();
$context->injectFn(Closure::fromCallable([$this, 'registerNavigation']));
$this->registerHooks();
$context->injectFn(Closure::fromCallable([$this, 'registerLegacyEvents']));
}

private function registerCollaboration(IProviderManager $providerManager): void {
Expand Down Expand Up @@ -183,4 +186,9 @@ private function registerNavigation(IL10N $l10n): void {
private function registerHooks(): void {
Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
}

private function registerLegacyEvents(EventDispatcherInterface $dispatcher): void {
$listener = new HiddenFolderListener();
$dispatcher->addListener('OCP\Share::preShare', [$listener, 'handlePreShare']);
}
}
44 changes: 44 additions & 0 deletions apps/files/lib/Listener/HiddenFolderListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <[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\Files\Listener;

use OC\Files\Filesystem;
use OCP\Share\IShare;
use Symfony\Component\EventDispatcher\GenericEvent;

class HiddenFolderListener {
public function handlePreShare(GenericEvent $event): void {

$share = $event->getSubject();
if (!$share instanceof IShare) {
return;
}

$hiddenName = Filesystem::getHiddenFolderName();
if ($share->getNode()->getName() === $hiddenName) {
$event->stopPropagation();
$event->setArgument("error", "hidden root folder can't be shared");
}
}
}
9 changes: 9 additions & 0 deletions build/integration/features/bootstrap/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,13 @@ public function theCommandErrorOutputContainsTheText($text) {
throw new \Exception('The command did not output the expected text on stderr "' . $exceptionText . '"');
}
}

/**
* @Given /^system parameter "([^"]*)" is set to "([^"]*)"$/
* @param string $parameter
* @param string $value
*/
public function setSystemConfig(string $parameter, string $value) {
$this->runOcc(['config:system:set', $parameter, '--value', $value]);
}
}
9 changes: 0 additions & 9 deletions build/integration/features/bootstrap/CommandLineContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,4 @@ public function usingTransferFolderAsDavPath($user) {
public function transferFolderNameContains($text) {
Assert::assertContains($text, $this->lastTransferPath);
}

/**
* @Given /^system parameter "([^"]*)" is set to "([^"]*)"$/
* @param string $parameter
* @param string $value
*/
public function setSystemConfig(string $parameter, string $value) {
$this->runOcc(['config:system:set', $parameter, '--value', $value]);
}
}
18 changes: 18 additions & 0 deletions build/integration/sharing_features/hidden-folder.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Feature: Hidden folder sharing
Background:
Given using api version "1"
And user "user0" exists
And system parameter "instanceid" is set to "dummy"
And User "user0" created a folder "/.hidden_instance"
And system parameter "instanceid" is set to "instance"

Scenario: Share the hidden folder fails
Given user "user0" exists
And user "user1" exists
And As an "user0"
When creating a share with
| path | .hidden_instance |
| shareWith | user1 |
| shareType | 0 |
Then the OCS status code should be "403"
And the HTTP status code should be "200"