-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add sabre plugin to block dav bind/unbind on the hidden folder
Signed-off-by: Robin Appelman <robin@icewind.nl>
- Loading branch information
1 parent
29e6fde
commit cc132a8
Showing
10 changed files
with
144 additions
and
17 deletions.
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
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 <robin@icewind.nl> | ||
* | ||
* @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\DAV\Files; | ||
|
||
use OC\Files\Filesystem; | ||
use Sabre\DAV\Exception\Forbidden; | ||
use Sabre\DAV\Server; | ||
use Sabre\DAV\ServerPlugin; | ||
|
||
class HiddenFolderPlugin extends ServerPlugin { | ||
public function initialize(Server $server) { | ||
$server->on('beforeBind', [$this, 'onBind'], 1000); | ||
$server->on('beforeUnbind', [$this, 'onBind'], 1000); | ||
} | ||
|
||
public function onBind($path) { | ||
$hiddenName = Filesystem::getHiddenFolderName(); | ||
if (basename($path) === $hiddenName) { | ||
throw new Forbidden("Can't modify hidden base folder"); | ||
} | ||
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
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,33 @@ | ||
Feature: Hidden folder | ||
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: The hidden folder should not be listed in the root | ||
When User "user0" created a folder "/folder" | ||
Then user "user0" should see following elements | ||
| /folder/ | | ||
And user "user0" should not see following elements | ||
| /.hidden_instance/ | | ||
|
||
Scenario: Folders can be created inside the hidden folder | ||
When User "user0" created a folder "/.hidden_instance/sub" | ||
Then the HTTP status code should be "201" | ||
And user "user0" should see following elements in folder "/.hidden_instance/" | ||
| /.hidden_instance/sub/ | | ||
|
||
Scenario: Trying to delete the hidden folder should fail | ||
Given User "user0" deletes folder "/.hidden_instance" | ||
Then the HTTP status code should be "403" | ||
|
||
Scenario: Trying to rename the hidden folder should fail | ||
Given User "user0" moves folder "/.hidden_instance" to "/foo" | ||
Then the HTTP status code should be "403" | ||
|
||
Scenario: Trying to overwrite the hidden folder with a rename should fail | ||
When User "user0" created a folder "/folder" | ||
And User "user0" moves folder "/folder" to "/.hidden_instance" | ||
Then the HTTP status code should be "403" |