From 3250407f2bc723d23a6c4b33dc9cfea30e06fde3 Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 26 Mar 2025 13:11:56 -0400 Subject: [PATCH] Refactor peer identification logic in ResolvePeer and Socialbox for clarity and improved error messaging --- src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php | 5 ++++- src/Socialbox/Socialbox.php | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php index 8ed8206..92c15b7 100644 --- a/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php +++ b/src/Socialbox/Classes/StandardMethods/Core/ResolvePeer.php @@ -34,11 +34,14 @@ // 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(); + } } catch (DatabaseOperationException $e) { diff --git a/src/Socialbox/Socialbox.php b/src/Socialbox/Socialbox.php index 00a5fc4..10c0ce7 100644 --- a/src/Socialbox/Socialbox.php +++ b/src/Socialbox/Socialbox.php @@ -541,13 +541,13 @@ // First check if the client is identifying as the host elseif($hostPeer->getAddress() !== ReservedUsernames::HOST->value) { - self::returnError(403, StandardError::FORBIDDEN, 'Forbidden: External servers must identify as a host'); + self::returnError(403, StandardError::FORBIDDEN, 'Cannot identify as a peer when not identifying as the host'); return; } // Secondly, check if the peer's server belongs to another server than the server is identified as elseif($hostPeer->getServer() !== $clientRequest->getIdentifyAs()->getDomain()) { - self::returnError(403, StandardError::FORBIDDEN, 'Forbidden: Not allowed to identify as a peer outside from the host server'); + self::returnError(403, StandardError::FORBIDDEN, 'Not allowed to identify as a peer outside from the host server'); return; }