Merge pull request #5202 from nextcloud/fix/5199

fix: Properly handle authenticated links being an array
This commit is contained in:
Julius Knorr 2025-11-27 09:57:58 +01:00 committed by GitHub
commit fcbf00a8d6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

View file

@ -65,9 +65,11 @@ class DocumentAPIController extends \OCP\AppFramework\OCSController {
$share = $this->shareManager->getShareByToken($shareToken); $share = $this->shareManager->getShareByToken($shareToken);
if ($share->getPassword()) { if ($share->getPassword()) {
if (!$this->session->exists('public_link_authenticated') $authenticatedLinks = $this->session->get('public_link_authenticated');
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
) { $isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
if (!$isAuthenticated) {
throw new Exception('Invalid password'); throw new Exception('Invalid password');
} }
} }

View file

@ -242,9 +242,11 @@ class DocumentController extends Controller {
$share = $this->shareManager->getShareByToken($shareToken); $share = $this->shareManager->getShareByToken($shareToken);
// not authenticated ? // not authenticated ?
if ($share->getPassword()) { if ($share->getPassword()) {
if (!$this->session->exists('public_link_authenticated') $authenticatedLinks = $this->session->get('public_link_authenticated');
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
) { $isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
if (!$isAuthenticated) {
throw new Exception('Invalid password'); throw new Exception('Invalid password');
} }
} }
@ -459,9 +461,12 @@ class DocumentController extends Controller {
private function getFileForShare(IShare $share, ?int $fileId, ?string $path = null): File { private function getFileForShare(IShare $share, ?int $fileId, ?string $path = null): File {
// not authenticated ? // not authenticated ?
if ($share->getPassword()) { if ($share->getPassword()) {
if (!$this->session->exists('public_link_authenticated') $authenticatedLinks = $this->session->get('public_link_authenticated');
|| $this->session->get('public_link_authenticated') !== (string)$share->getId()
) { $isAuthenticated = (is_array($authenticatedLinks) && in_array($share->getId(), $authenticatedLinks));
$isAuthenticated = $isAuthenticated || ($authenticatedLinks === (string)$share->getId());
if (!$isAuthenticated) {
throw new NotPermittedException('Invalid password'); throw new NotPermittedException('Invalid password');
} }
} }