From 2179df3372a4b0736b1d136d21d1bae9499a4a84 Mon Sep 17 00:00:00 2001 From: netkas Date: Thu, 27 Mar 2025 13:40:58 -0400 Subject: [PATCH] Normalize username and domain inputs to lowercase in various classes --- .../Classes/Configuration/InstanceConfiguration.php | 2 +- .../Classes/StandardMethods/Core/ResolvePeer.php | 7 ++++++- src/Socialbox/Objects/PeerAddress.php | 9 ++------- src/Socialbox/Socialbox.php | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Socialbox/Classes/Configuration/InstanceConfiguration.php b/src/Socialbox/Classes/Configuration/InstanceConfiguration.php index 7609e49..ce7471e 100644 --- a/src/Socialbox/Classes/Configuration/InstanceConfiguration.php +++ b/src/Socialbox/Classes/Configuration/InstanceConfiguration.php @@ -47,7 +47,7 @@ */ public function getDomain(): ?string { - return $this->domain; + return strtolower($this->domain); } /** diff --git a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php index 92c15b7..63b8cf8 100644 --- a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php +++ b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php @@ -34,13 +34,18 @@ // Check if host is making the request & the identifier is not empty try { + $identifyAs = null; if ($request->getPeer()->getUsername() === ReservedUsernames::HOST->value && $request->getIdentifyAs() !== null) { $identifyAs = $request->getIdentifyAs(); } else { - $identifyAs = $request->getPeer()->getAddress(); + $requestingPeer = $request->getPeer(); + if($requestingPeer->getUsername() !== ReservedUsernames::HOST->value) + { + $identifyAs = $requestingPeer->getAddress(); + } } } catch (DatabaseOperationException $e) diff --git a/src/Socialbox/Objects/PeerAddress.php b/src/Socialbox/Objects/PeerAddress.php index 27e7b22..95edbbe 100644 --- a/src/Socialbox/Objects/PeerAddress.php +++ b/src/Socialbox/Objects/PeerAddress.php @@ -20,8 +20,8 @@ */ public function __construct(string $username, string $domain) { - $this->username = $username; - $this->domain = $domain; + $this->username = strtolower($username); + $this->domain = strtolower($domain); } /** @@ -78,11 +78,6 @@ */ public function isExternal(): bool { - if($this->isHost()) - { - return false; - } - return $this->domain !== Configuration::getInstanceConfiguration()->getDomain(); } diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index 3afb2f2..3aeaabe 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -978,12 +978,12 @@ */ public static function resolvePeer(PeerAddress|string $peerAddress, null|PeerAddress|string $identifiedAs=null): Peer { - if($peerAddress->getDomain() !== Configuration::getInstanceConfiguration()->getDomain()) + if(strtolower($peerAddress->getDomain()) !== strtolower(Configuration::getInstanceConfiguration()->getDomain())) { return self::resolveExternalPeer($peerAddress, $identifiedAs); } - if($peerAddress->getUsername() === ReservedUsernames::HOST->value) + if(strtolower($peerAddress->getUsername()) === strtolower(ReservedUsernames::HOST->value)) { return new Peer([ 'address' => sprintf('%s@%s', ReservedUsernames::HOST->value, Configuration::getInstanceConfiguration()->getDomain()),