Skip to content

Commit ccca7d2

Browse files
authored
Merge pull request #5205 from nextcloud/backport/5202/stable32
[stable32] fix: Properly handle authenticated links being an array
2 parents 1f85ad7 + 9078d4e commit ccca7d2

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/Controller/DocumentAPIController.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,11 @@ public function create(string $mimeType, string $fileName, string $directoryPath
6565
$share = $this->shareManager->getShareByToken($shareToken);
6666

6767
if ($share->getPassword()) {
68-
if (!$this->session->exists('public_link_authenticated')
69-
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
70-
) {
68+
$authenticatedLinks = $this->session->get('public_link_authenticated');
69+
70+
$isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
71+
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
72+
if (!$isAuthenticated) {
7173
throw new Exception('Invalid password');
7274
}
7375
}

lib/Controller/DocumentController.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,11 @@ public function remote(string $shareToken, string $remoteServer, string $remoteS
242242
$share = $this->shareManager->getShareByToken($shareToken);
243243
// not authenticated ?
244244
if ($share->getPassword()) {
245-
if (!$this->session->exists('public_link_authenticated')
246-
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
247-
) {
245+
$authenticatedLinks = $this->session->get('public_link_authenticated');
246+
247+
$isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
248+
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
249+
if (!$isAuthenticated) {
248250
throw new Exception('Invalid password');
249251
}
250252
}
@@ -459,9 +461,12 @@ private function getFileForUser(int $fileId, ?string $path = null): File {
459461
private function getFileForShare(IShare $share, ?int $fileId, ?string $path = null): File {
460462
// not authenticated ?
461463
if ($share->getPassword()) {
462-
if (!$this->session->exists('public_link_authenticated')
463-
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
464-
) {
464+
$authenticatedLinks = $this->session->get('public_link_authenticated');
465+
466+
$isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
467+
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
468+
469+
if (!$isAuthenticated) {
465470
throw new NotPermittedException('Invalid password');
466471
}
467472
}

0 commit comments

Comments
 (0)