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

fix: do not accept federated shares where the name is too long #40726

Merged
merged 1 commit into from Apr 4, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -26,6 +26,7 @@

namespace OCA\FederatedFileSharing\Controller;

use OC\Files\View;
use OC\OCS\Result;
use OCA\FederatedFileSharing\Address;
use OCA\FederatedFileSharing\AddressHandler;
Expand All @@ -37,6 +38,7 @@
use OCA\FederatedFileSharing\Ocm\Exception\OcmException;
use OCP\AppFramework\Http;
use OCP\AppFramework\OCSController;
use OCP\Files\InvalidPathException;
use OCP\IRequest;
use OCP\IUserManager;

Expand Down Expand Up @@ -120,7 +122,7 @@ public function createShare() {
]
);

if (!\OCP\Util::isValidFileName($name)) {
if (!$this->isFileNameValid($name)) {
throw new BadRequestException(
'The mountpoint name contains invalid characters.'
);
Expand Down Expand Up @@ -406,4 +408,18 @@ public function updatePermissions($id) {

return new Result();
}

private function isFileNameValid(?string $name): bool {
if ($name === null) {
return false;
}
$v = new View();
try {
# new shares will show up in user home - therefore we test with /
$v->verifyPath('/', $name);
DeepDiver1975 marked this conversation as resolved.
Show resolved Hide resolved
} catch (InvalidPathException $e) {
return false;
}
return true;
}
}