diff options
author | Joas Schilling <213943+nickvergessen@users.noreply.github.com> | 2024-09-26 12:33:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-09-26 12:33:34 +0200 |
commit | 5cc1fb9d0b56850dc8c84a85387c6683815568a5 (patch) | |
tree | 22b8e4edd00ba1ffbc41df59c19e172dc9043ae0 /lib | |
parent | 97527e698f96de54e630957e1767ca3a188aca5a (diff) | |
parent | 0551919bcedc4cd62fdeb011ffb2a291673ece8c (diff) | |
download | nextcloud-server-5cc1fb9d0b56850dc8c84a85387c6683815568a5.tar.gz nextcloud-server-5cc1fb9d0b56850dc8c84a85387c6683815568a5.zip |
Merge pull request #48142 from nextcloud/backport/47265/stable30
[stable30] feat(share): ensure unique share tokens with dynamic length adjustment
Diffstat (limited to 'lib')
-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 55e10602e72..ce0dbd9b17a 100644 --- a/lib/private/Share20/Manager.php +++ b/lib/private/Share20/Manager.php @@ -665,13 +665,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); |