Refactor peer identification logic in ResolvePeer and Socialbox for clarity and improved error messaging

This commit is contained in:
netkas 2025-03-26 13:11:56 -04:00
parent 5de651bbcb
commit 3250407f2b
Signed by: netkas
GPG key ID: 4D8629441B76E4CC
2 changed files with 6 additions and 3 deletions

View file

@ -34,11 +34,14 @@
// Check if host is making the request & the identifier is not empty // Check if host is making the request & the identifier is not empty
try try
{ {
$identifyAs = null;
if ($request->getPeer()->getUsername() === ReservedUsernames::HOST->value && $request->getIdentifyAs() !== null) if ($request->getPeer()->getUsername() === ReservedUsernames::HOST->value && $request->getIdentifyAs() !== null)
{ {
$identifyAs = $request->getIdentifyAs(); $identifyAs = $request->getIdentifyAs();
} }
else
{
$identifyAs = $request->getPeer()->getAddress();
}
} }
catch (DatabaseOperationException $e) catch (DatabaseOperationException $e)
{ {

View file

@ -541,13 +541,13 @@
// First check if the client is identifying as the host // First check if the client is identifying as the host
elseif($hostPeer->getAddress() !== ReservedUsernames::HOST->value) 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; return;
} }
// Secondly, check if the peer's server belongs to another server than the server is identified as // Secondly, check if the peer's server belongs to another server than the server is identified as
elseif($hostPeer->getServer() !== $clientRequest->getIdentifyAs()->getDomain()) 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; return;
} }