Skip to content

Commit e4c5e7e

Browse files
authored
Merge pull request #6504 from nextcloud/backport/6487/stable27
[stable27] fix: Apply checks on shares in the middleware
2 parents 5104e8d + 72af0ea commit e4c5e7e

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

lib/Middleware/SessionMiddleware.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
use OCP\AppFramework\Http\JSONResponse;
1717
use OCP\AppFramework\Http\Response;
1818
use OCP\AppFramework\Middleware;
19+
use OCP\Constants;
1920
use OCP\Files\IRootFolder;
2021
use OCP\Files\NotPermittedException;
2122
use OCP\IL10N;
2223
use OCP\IRequest;
24+
use OCP\ISession;
2325
use OCP\IUserSession;
2426
use OCP\Share\Exceptions\ShareNotFound;
2527
use OCP\Share\IManager as ShareManager;
@@ -31,6 +33,7 @@ public function __construct(
3133
private IRequest $request,
3234
private SessionService $sessionService,
3335
private DocumentService $documentService,
36+
private ISession $session,
3437
private IUserSession $userSession,
3538
private IRootFolder $rootFolder,
3639
private ShareManager $shareManager,
@@ -125,10 +128,28 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
125128
} catch (ShareNotFound) {
126129
throw new InvalidSessionException();
127130
}
131+
128132
// Check if shareToken has access to document
129133
if (count($this->rootFolder->getUserFolder($share->getShareOwner())->getById($documentId)) === 0) {
130134
throw new InvalidSessionException();
131135
}
136+
137+
/** @psalm-suppress RedundantConditionGivenDocblockType */
138+
if ($share->getPassword() !== null) {
139+
$shareId = $this->session->get('public_link_authenticated');
140+
if ($share->getId() !== $shareId) {
141+
throw new InvalidSessionException();
142+
}
143+
}
144+
145+
if (($share->getPermissions() & Constants::PERMISSION_READ) !== Constants::PERMISSION_READ) {
146+
throw new InvalidSessionException();
147+
}
148+
149+
$attributes = $share->getAttributes();
150+
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
151+
throw new InvalidSessionException();
152+
}
132153
} else {
133154
throw new InvalidSessionException();
134155
}

0 commit comments

Comments
 (0)