diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-09-26 15:18:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 15:18:54 +0200 |
commit | 1dbd72dcc0f420a605dc0bbaf59e2e6c81c87003 (patch) | |
tree | 2f999be418d2004480852a3cc746ab3848b9ff1b /lib/private | |
parent | 80d5cdef041cbeb84e7eec39baa9d7ab3a339012 (diff) | |
parent | 614210c536d30d9587005b51341082b499e7f12d (diff) | |
download | nextcloud-server-1dbd72dcc0f420a605dc0bbaf59e2e6c81c87003.tar.gz nextcloud-server-1dbd72dcc0f420a605dc0bbaf59e2e6c81c87003.zip |
Merge pull request #48379 from nextcloud/backport/48142/stable28
[stable28] feat(share): ensure unique share tokens with dynamic length adjustment
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Share20/Manager.php | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php index d11f2db338f..d965a7c2f2b 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -689,13 +689,25 @@ class Manager implements IManager { $this->linkCreateChecks($share); $this->setLinkParent($share); - // For now ignore a set token. - $share->setToken( - $this->secureRandom->generate( + for ($i = 0; $i <= 3; $i++) { + $token = $this->secureRandom->generate( \OC\Share\Constants::TOKEN_LENGTH, \OCP\Security\ISecureRandom::CHAR_HUMAN_READABLE - ) - ); + ); + + try { + $this->getShareByToken($token); + } catch (\OCP\Share\Exceptions\ShareNotFound $e) { + // Set the unique token + $share->setToken($token); + break; + } + + // Abort after 3 failed attempts + if ($i >= 3) { + throw new \Exception('Unable to generate a unique share token after 3 attempts.'); + } + } // Verify the expiration date $share = $this->validateExpirationDateLink($share); |