Skip to content

Commit

Permalink
fix: attachment visibility for authenticated users via shared links
Browse files Browse the repository at this point in the history
Signed-off-by: ailkiv <[email protected]>
  • Loading branch information
AIlkiv committed Feb 2, 2025
1 parent be3ff42 commit e089475
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/Middleware/SessionMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,14 @@ private function assertDocumentSession(ISessionAwareController $controller): voi
private function assertUserOrShareToken(ISessionAwareController $controller): void {
$documentId = (int)$this->request->getParam('documentId');
if (null !== $userId = $this->userSession->getUser()?->getUID()) {
// Check if user has access to document
if ($this->rootFolder->getUserFolder($userId)->getFirstNodeById($documentId) === null) {
throw new InvalidSessionException();
if ($this->rootFolder->getUserFolder($userId)->getFirstNodeById($documentId) !== null) {
$controller->setUserId($userId);
$controller->setDocumentId($documentId);
return;
}
$controller->setUserId($userId);
} elseif ('' !== $shareToken = (string)$this->request->getParam('shareToken')) {
}

if ('' !== $shareToken = (string)$this->request->getParam('shareToken')) {
try {
$share = $this->shareManager->getShareByToken($shareToken);
} catch (ShareNotFound) {
Expand All @@ -155,11 +157,12 @@ private function assertUserOrShareToken(ISessionAwareController $controller): vo
if ($attributes !== null && $attributes->getAttribute('permissions', 'download') === false) {
throw new InvalidSessionException();
}
} else {
throw new InvalidSessionException();

$controller->setDocumentId($documentId);
return;
}

$controller->setDocumentId($documentId);
throw new InvalidSessionException();
}

public function afterException($controller, $methodName, \Exception $exception): JSONResponse|Response {
Expand Down

0 comments on commit e089475

Please sign in to comment.