diff options
author | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-01-29 19:52:05 +0100 |
---|---|---|
committer | Ferdinand Thiessen <opensource@fthiessen.de> | 2025-02-07 12:41:49 +0100 |
commit | 96384cd9502bef255e4a64ce5429e0805fb1854f (patch) | |
tree | babd084b4f3255bd239741db86cd2d2136a89a6e /lib | |
parent | 57fc8f11822d50899cf6809d873338ea61fdc626 (diff) | |
download | nextcloud-server-96384cd9502bef255e4a64ce5429e0805fb1854f.tar.gz nextcloud-server-96384cd9502bef255e4a64ce5429e0805fb1854f.zip |
fix(FediverseAction): Ensure valid fediverse links are generated
Harden also for existing values of the profile.
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/Profile/Actions/FediverseAction.php | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/private/Profile/Actions/FediverseAction.php b/lib/private/Profile/Actions/FediverseAction.php index 1076027629d..b48f1db5c50 100644 --- a/lib/private/Profile/Actions/FediverseAction.php +++ b/lib/private/Profile/Actions/FediverseAction.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace OC\Profile\Actions; use OCP\Accounts\IAccountManager; +use OCP\Accounts\PropertyDoesNotExistException; use OCP\IURLGenerator; use OCP\IUser; use OCP\L10N\IFactory; @@ -27,8 +28,13 @@ class FediverseAction implements ILinkAction { } public function preload(IUser $targetUser): void { - $account = $this->accountManager->getAccount($targetUser); - $this->value = $account->getProperty(IAccountManager::PROPERTY_FEDIVERSE)->getValue(); + try { + $account = $this->accountManager->getAccount($targetUser); + $this->value = $account->getProperty(IAccountManager::PROPERTY_FEDIVERSE)->getValue(); + } catch (PropertyDoesNotExistException) { + // `getTarget` will return null to skip this action + $this->value = ''; + } } public function getAppId(): string { @@ -57,11 +63,18 @@ class FediverseAction implements ILinkAction { } public function getTarget(): ?string { - if (empty($this->value)) { + if ($this->value === '') { + return null; + } + + $handle = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; + [$username, $instance] = [...explode('@', $handle, 2), '']; + + if (($username === '') || ($instance === '')) { + return null; + } elseif (str_contains($username, '/') || str_contains($instance, '/')) { return null; } - $username = $this->value[0] === '@' ? substr($this->value, 1) : $this->value; - [$username, $instance] = explode('@', $username); return 'https://' . $instance . '/@' . $username; } } |