Refactor AddressBookAddContact to prevent adding self and reserved usernames as contacts

https://github.com/nosial/Socialbox-PHP/issues/30
This commit is contained in:
netkas 2025-03-12 00:33:42 -04:00
parent 86050e2201
commit 1d6820a4f1
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

View file

@ -4,6 +4,7 @@
use InvalidArgumentException;
use Socialbox\Abstracts\Method;
use Socialbox\Enums\ReservedUsernames;
use Socialbox\Enums\StandardError;
use Socialbox\Enums\Types\ContactRelationshipType;
use Socialbox\Exceptions\DatabaseOperationException;
@ -54,6 +55,10 @@
{
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Cannot add self as contact');
}
elseif($peer->getUsername() === ReservedUsernames::HOST->value)
{
return $rpcRequest->produceError(StandardError::FORBIDDEN, 'Cannot add host as contact');
}
// Resolve the peer, this would throw a StandardException if something goes wrong
Socialbox::resolvePeer($peerAddress);