Skip to content

Commit

Permalink
Merge pull request #6878 from AIlkiv/fix/attachments-authenticated-view
Browse files Browse the repository at this point in the history
fix: attachment visibility for authenticated users via shared links
  • Loading branch information
max-nextcloud authored Feb 5, 2025
2 parents 5ab02b2 + e089475 commit 40a655a
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 40a655a

Please sign in to comment.