Skip to content

Commit 75044c9

Browse files
committed
fix: fail uploads when uri does not match session
This is a cosmetic change that can cause false security reports: the current implementation of the upload root collection returns UploadHome in every case, based on the current session, either the one of the logged in user, or for the share. The former allows uploading files in what looks like the upload folder of another user, but is in reality the one of the logged in user. Those requests will now fail with a 403 instead. Signed-off-by: Salvatore Martire <4652631+salmart-dev@users.noreply.github.com>
1 parent 83130ab commit 75044c9

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

apps/dav/lib/Upload/RootCollection.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212

1313
use OCP\Files\IRootFolder;
1414
use OCP\IUserSession;
15+
use OCP\Server;
1516
use OCP\Share\IManager;
17+
use Sabre\DAV\Exception\Forbidden;
18+
use Sabre\DAV\INode;
1619
use Sabre\DAVACL\AbstractPrincipalCollection;
1720
use Sabre\DAVACL\PrincipalBackend;
1821

@@ -34,7 +37,14 @@ public function __construct(
3437
* @inheritdoc
3538
*/
3639
#[\Override]
37-
public function getChildForPrincipal(array $principalInfo): UploadHome {
40+
public function getChildForPrincipal(array $principalInfo): INode|UploadHome {
41+
[$prefix, $name] = \Sabre\Uri\split($principalInfo['uri']);
42+
$user = Server::get(IUserSession::class)->getUser();
43+
if ($prefix !== 'principals/shares' && $user?->getUID() !== $name) {
44+
// if the request is not using a share token and the URL does not match the user, error out
45+
throw new Forbidden('Not allowed');
46+
}
47+
3848
return new UploadHome(
3949
$principalInfo,
4050
$this->cleanupService,

0 commit comments

Comments
 (0)