From 1d6820a4f1d68355606fa06f022899d747a1ab93 Mon Sep 17 00:00:00 2001 From: netkas Date: Wed, 12 Mar 2025 00:33:42 -0400 Subject: [PATCH] Refactor AddressBookAddContact to prevent adding self and reserved usernames as contacts https://github.com/nosial/Socialbox-PHP/issues/30 --- .../StandardMethods/AddressBook/AddressBookAddContact.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookAddContact.php b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookAddContact.php index 328599e..df37c61 100644 --- a/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookAddContact.php +++ b/src/Socialbox/Classes/StandardMethods/AddressBook/AddressBookAddContact.php @@ -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);