summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoas Schilling <213943+nickvergessen@users.noreply.github.com>2024-09-26 15:19:25 +0200
committerGitHub <noreply@github.com>2024-09-26 15:19:25 +0200
commit5729488f0a0076b0f9fea04e22283b11bc7901e9 (patch)
tree4695734af01a2578a18e28b2459ad6d606333a30
parentc9f58fc19f7e4f2fec857f342ff247e4ee5e214e (diff)
parent0a9cad04554d841fbe7ae3bd6dabf5039f951fa1 (diff)
downloadnextcloud-server-5729488f0a0076b0f9fea04e22283b11bc7901e9.tar.gz
nextcloud-server-5729488f0a0076b0f9fea04e22283b11bc7901e9.zip
Merge pull request #48380 from nextcloud/backport/48142/stable29
[stable29] feat(share): ensure unique share tokens with dynamic length adjustment
-rw-r--r--lib/private/Share20/Manager.php22
1 files changed, 17 insertions, 5 deletions
diff --git a/lib/private/Share20/Manager.php b/lib/private/Share20/Manager.php
index 16ada8c6c7a..bd35729cb3c 100644
--- a/lib/private/Share20/Manager.php
+++ b/lib/private/Share20/Manager.php
@@ -697,13 +697,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);