Skip to content
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

Improve share_folder checks in rmdir #36170

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions lib/private/Files/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,13 @@ protected function renameUpdate(Storage $sourceStorage, Storage $targetStorage,
*/
public function rmdir($path) {
return $this->emittingCall(function () use (&$path) {
if (($path !== '') &&
(\strpos($this->config->getSystemValue('share_folder', '/'), $path) !== false)) {
Util::writeLog("core", "The folder $path could not be deleted as it is configured as share_folder in config.", Util::WARN);
return false;
if ($path !== '') {
$shareFolder = \trim($this->config->getSystemValue('share_folder', '/'), '/');
$trimmedPath = \trim($path, '/');
if ((\strpos("$shareFolder/", "$trimmedPath/") === 0)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems the condition we want is $shareFolder === $trimmedPath, anything I'm missing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If share_folder is /Company/Stuff/ReceivedShares and path is /Company or /Company/Stuff then those parent folders of ReceivedShares are also not allowed to be deleted.

See the unit test data provider test cases.

Util::writeLog("core", "The folder $path could not be deleted as it is configured as share_folder in config.", Util::WARN);
return false;
}
}
$absolutePath = $this->getAbsolutePath($path);
$mount = Filesystem::getMountManager()->find($absolutePath);
Expand Down
38 changes: 38 additions & 0 deletions tests/lib/Files/ViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2681,7 +2681,10 @@ public function testFopenFail() {
public function providesShareFolder() {
return [
['/MyTestShareFolder', '/MyTestShareFolder'],
['MyTestShareFolder', '/MyTestShareFolder'],
['/MyTestShareFolder/Share/Foo', '/MyTestShareFolder'],
['MyTestShareFolder/Share/Foo', 'MyTestShareFolder'],
['/MyTestShareFolder/Share/Foo', '/MyTestShareFolder/Share'],
];
}

Expand All @@ -2701,4 +2704,39 @@ public function testDeleteShareFolder($shareFolder, $deleteFolder) {
$view->mkdir($shareFolder);
$this->assertFalse($view->rmdir($deleteFolder));
}

public function providesNonShareFolder() {
return [
['/', 'AnotherFolder'],
['/', 'AnotherFolder/Subfolder'],
['/MyTestShareFolder', 'AnotherFolder'],
['/MyTestShareFolder/Share/Foo', '/MyTest'],
['/MyTestShareFolder/Share/Foo', '/Share'],
['/MyTestShareFolder/Share/Foo', 'Share'],
['/MyTestShareFolder/Share/Foo', '/Share/Foo'],
['/MyTestShareFolder/Share/Foo', '/Fo'],
['/MyTestShareFolder/Share/Foo', '/Foo'],
['/MyTestShareFolder/Share/Foo', '/Foo/Share'],
];
}

/**
* @dataProvider providesNonShareFolder
*/
public function testDeleteNonShareFolder($shareFolder, $deleteFolder) {
/**
* Using overwriteService in this method instead of setUp, because there
* are other methods in the test's which might get affected if we use it
* in setUp.
*/
$this->overwriteService('AllConfig', $this->config);
$this->config->method('getSystemValue')
->willReturn($shareFolder);
$storage1 = $this->getTestStorage();
Filesystem::mount($storage1, [], '/');
$view = new View('');
$view->mkdir($shareFolder);
$view->mkdir($deleteFolder);
$this->assertTrue($view->rmdir($deleteFolder));
}
}