Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fix(share): Ensure unique share tokens
- check for token collisions and retry up to three times.
- throw after 3 attempts without finding a unique token.

Signed-off-by: ernolf <[email protected]>
  • Loading branch information
ernolf authored and backportbot[bot] committed Sep 26, 2024
commit 0a9cad04554d841fbe7ae3bd6dabf5039f951fa1
22 changes: 17 additions & 5 deletions lib/private/Share20/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,13 +697,25 @@ public function createShare(IShare $share) {
$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);
Expand Down