From 6f25785de0075f659828b989cd5c311231ff9aa3 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 19:14:01 +0200 Subject: [PATCH 1/7] Null error on reported post comment notifications (#1118) --- templates/notifications/_blocks.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/notifications/_blocks.html.twig b/templates/notifications/_blocks.html.twig index 47c616867..4e9a157e4 100644 --- a/templates/notifications/_blocks.html.twig +++ b/templates/notifications/_blocks.html.twig @@ -119,7 +119,7 @@ {% elseif notification.report.postComment is defined and notification.report.postComment is not same as null %} {% set postComment = notification.report.postComment %} - {{ post.getShortTitle() }} + {{ postComment.getShortTitle() }} {% endif %} {% endblock %} From a8b8af19c8b131228ee15bf12ef005a5be863888 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:43:41 +0200 Subject: [PATCH 2/7] Fix 3rd miscellaneous bug (#1120) --- src/Service/ActivityPubManager.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php index 7b3f11062..b432d8291 100644 --- a/src/Service/ActivityPubManager.php +++ b/src/Service/ActivityPubManager.php @@ -551,7 +551,7 @@ public function updateMagazine(string $actorUrl): ?Magazine $magazine->apInboxUrl = $actor['endpoints']['sharedInbox'] ?? $actor['inbox']; $magazine->apDomain = parse_url($actor['id'], PHP_URL_HOST); $magazine->apFollowersUrl = $actor['followers'] ?? null; - $magazine->apAttributedToUrl = \is_string($actor['attributedTo']) ? $actor['attributedTo'] : null; + $magazine->apAttributedToUrl = isset($actor['attributedTo']) && \is_string($actor['attributedTo']) ? $actor['attributedTo'] : null; $magazine->apFeaturedUrl = $actor['featured'] ?? null; $magazine->apPreferredUsername = $actor['preferredUsername'] ?? null; $magazine->apDiscoverable = $actor['discoverable'] ?? true; @@ -579,7 +579,7 @@ public function updateMagazine(string $actorUrl): ?Magazine $this->handleModeratorCollection($actorUrl, $magazine); } catch (InvalidArgumentException $ignored) { } - } elseif (\is_array($actor['attributedTo'])) { + } elseif (isset($actor['attributedTo']) && \is_array($actor['attributedTo'])) { $this->handleModeratorArray($magazine, $this->getActorFromAttributedTo($actor['attributedTo'])); } From 4da5315de86aa9e97ffb2a455de92d4b7e1fe4f3 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:45:13 +0200 Subject: [PATCH 3/7] Fix 4th miscellaneous bug (#1121) --- src/Service/ActivityPub/SignatureValidator.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Service/ActivityPub/SignatureValidator.php b/src/Service/ActivityPub/SignatureValidator.php index 84eda3481..e30a094e4 100644 --- a/src/Service/ActivityPub/SignatureValidator.php +++ b/src/Service/ActivityPub/SignatureValidator.php @@ -113,7 +113,11 @@ public function validate(array $request, array $headers, string $body): void $user = $this->activityPubManager->findActorOrCreate($actorUrl); if (!empty($user)) { - $pkey = openssl_pkey_get_public($this->client->getActorObject($user->apProfileId)['publicKey']['publicKeyPem']); + $pem = $this->client->getActorObject($user->apProfileId)['publicKey']['publicKeyPem'] ?? null; + if (null === $pem) { + throw new InvalidUserPublicKeyException($user->apProfileId); + } + $pkey = openssl_pkey_get_public($pem); if (false === $pkey) { throw new InvalidUserPublicKeyException($user->apProfileId); From f415e54ff9d4ce783d7bf7913481927d2944c724 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:47:09 +0200 Subject: [PATCH 4/7] Fix 7th miscellaneous bug (#1123) --- src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php index 70c55acd2..ea2683c84 100644 --- a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php +++ b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php @@ -68,7 +68,7 @@ public function doWork(MessageInterface $message): void $entity = $this->retrieveObject($object['id']); if (!$entity) { - $this->logger->error('could not retrieve all the dependencies of {o}', ['o' => $object]); + $this->logger->error('could not retrieve all the dependencies of {o}', ['o' => $object['id']]); return; } From 822ed4634ad2be7b8d5f28cb8eb5a15ca21bf3e5 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:48:46 +0200 Subject: [PATCH 5/7] Fix 2nd miscellaneous bug (#1124) --- src/Service/ActivityPub/Page.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Service/ActivityPub/Page.php b/src/Service/ActivityPub/Page.php index ca80a0b63..b929a1829 100644 --- a/src/Service/ActivityPub/Page.php +++ b/src/Service/ActivityPub/Page.php @@ -51,6 +51,10 @@ public function __construct( */ public function create(array $object, bool $stickyIt = false): Entry { + $current = $this->repository->findByObjectId($object['id']); + if ($current) { + return $this->entityManager->getRepository($current['type'])->find((int) $current['id']); + } $actorUrl = $this->activityPubManager->getSingleActorFromAttributedTo($object['attributedTo']); if ($this->settingsManager->isBannedInstance($actorUrl)) { throw new InstanceBannedException(); From 30cbcfd404ce16dd34a92bce151bee57db913f50 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:50:25 +0200 Subject: [PATCH 6/7] Fix 6th miscellaneous bug (#1125) --- .../ActivityPub/Inbox/ChainActivityHandler.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php index ea2683c84..d1e9d1796 100644 --- a/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php +++ b/src/MessageHandler/ActivityPub/Inbox/ChainActivityHandler.php @@ -23,6 +23,7 @@ use App\Service\ActivityPub\ApHttpClient; use App\Service\ActivityPub\Note; use App\Service\ActivityPub\Page; +use App\Service\SettingsManager; use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Messenger\Attribute\AsMessageHandler; @@ -38,7 +39,8 @@ public function __construct( private readonly MessageBusInterface $bus, private readonly ApActivityRepository $repository, private readonly Note $note, - private readonly Page $page + private readonly Page $page, + private readonly SettingsManager $settingsManager, ) { parent::__construct($this->entityManager); } @@ -64,8 +66,13 @@ public function doWork(MessageInterface $message): void return; } + try { + $entity = $this->retrieveObject($object['id']); + } catch (InstanceBannedException) { + $this->logger->info('the instance is banned, url: {url}', ['url' => $object['id']]); - $entity = $this->retrieveObject($object['id']); + return; + } if (!$entity) { $this->logger->error('could not retrieve all the dependencies of {o}', ['o' => $object['id']]); @@ -91,6 +98,9 @@ public function doWork(MessageInterface $message): void */ private function retrieveObject(string $apUrl): Entry|EntryComment|Post|PostComment|null { + if ($this->settingsManager->isBannedInstance($apUrl)) { + throw new InstanceBannedException(); + } try { $object = $this->client->getActivityObject($apUrl); if (!$object) { @@ -141,8 +151,8 @@ private function retrieveObject(string $apUrl): Entry|EntryComment|Post|PostComm $this->logger->info('one of the used tags is banned, url: {url}', ['url' => $apUrl]); } catch (EntityNotFoundException $e) { $this->logger->error('There was an exception while getting {url}: {ex} - {m}. {o}', ['url' => $apUrl, 'ex' => \get_class($e), 'm' => $e->getMessage(), 'o' => $e]); - } catch (InstanceBannedException $e) { - $this->logger->info('the user\'s instance is banned, url: {url}', ['url' => $apUrl]); + } catch (InstanceBannedException) { + $this->logger->info('the instance is banned, url: {url}', ['url' => $apUrl]); } return null; From b12adeb5fb0908fb8856ee2d599b66a1e9c72d65 Mon Sep 17 00:00:00 2001 From: BentiGorlich Date: Thu, 12 Sep 2024 20:56:20 +0200 Subject: [PATCH 7/7] Fix 9th miscellaneous bug (#1122) --- src/Service/ActivityPubManager.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Service/ActivityPubManager.php b/src/Service/ActivityPubManager.php index b432d8291..ec10cf293 100644 --- a/src/Service/ActivityPubManager.php +++ b/src/Service/ActivityPubManager.php @@ -284,10 +284,14 @@ public function buildHandle(string $id): string $port = !\is_null(parse_url($id, PHP_URL_PORT)) ? ':'.parse_url($id, PHP_URL_PORT) : ''; + $apObj = $this->apHttpClient->getActorObject($id); + if (!isset($apObj['preferredUsername'])) { + throw new \InvalidArgumentException("webfinger from $id does not supply a valid user object"); + } return \sprintf( '%s@%s%s', - $this->apHttpClient->getActorObject($id)['preferredUsername'], + $apObj['preferredUsername'], parse_url($id, PHP_URL_HOST), $port );