From 9b1918c650b44f435ae8f157e4de52e109c3c385 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 2 Oct 2020 03:35:22 +0000 Subject: [PATCH] Don't accept ignored author via relay --- src/Protocol/ActivityPub/Processor.php | 5 ++++- src/Protocol/DFRN.php | 2 +- src/Protocol/Diaspora.php | 2 +- src/Protocol/Relay.php | 14 +++++++++++++- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index ab1b27d331..c7310d9eb8 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -806,6 +806,9 @@ class Processor return true; } + $attributed_to = JsonLD::fetchElement($activity['as:object'], 'as:attributedTo', '@id'); + $authorid = Contact::getIdForURL($attributed_to); + $body = HTML::toBBCode(JsonLD::fetchElement($activity['as:object'], 'as:content', '@value')); $messageTags = []; @@ -819,7 +822,7 @@ class Processor } } - return Relay::isSolicitedPost($messageTags, $body, $id, Protocol::ACTIVITYPUB); + return Relay::isSolicitedPost($messageTags, $body, $authorid, $id, Protocol::ACTIVITYPUB); } /** diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 0b763d1aa3..4ba6aa2a25 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -2277,7 +2277,7 @@ class DFRN $taglist = Tag::getByURIId($item['uri-id'], [Tag::HASHTAG]); $tags = array_column($taglist, 'name'); - return Relay::isSolicitedPost($tags, $item['body'], $item['uri'], Protocol::DFRN); + return Relay::isSolicitedPost($tags, $item['body'], $item['author-id'], $item['uri'], Protocol::DFRN); } /** diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 6b2bd9f70a..fd668b1f30 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -2807,7 +2807,7 @@ class Diaspora $taglist = Tag::getByURIId($uriid, [Tag::HASHTAG]); $tags = array_column($taglist, 'name'); - return Relay::isSolicitedPost($tags, $body, $url, Protocol::DIASPORA); + return Relay::isSolicitedPost($tags, $body, $contact['id'], $url, Protocol::DIASPORA); } /** diff --git a/src/Protocol/Relay.php b/src/Protocol/Relay.php index 3184528cc5..fb838f9176 100644 --- a/src/Protocol/Relay.php +++ b/src/Protocol/Relay.php @@ -24,6 +24,7 @@ namespace Friendica\Protocol; use Friendica\Content\Text\BBCode; use Friendica\Core\Logger; use Friendica\DI; +use Friendica\Model\Contact; use Friendica\Model\Search; /** @@ -36,10 +37,11 @@ class Relay * * @param array $tags * @param string $body + * @param int $authorid * @param string $url * @return boolean "true" is the post is wanted by the system */ - public static function isSolicitedPost(array $tags, string $body, string $url, string $network = '') + public static function isSolicitedPost(array $tags, string $body, int $authorid, string $url, string $network = '') { $config = DI::config(); @@ -55,6 +57,16 @@ class Relay return false; } + if (Contact::isBlocked($authorid)) { + Logger::info('Author is blocked - rejected', ['author' => $authorid, 'network' => $network, 'url' => $url]); + return false; + } + + if (Contact::isHidden($authorid)) { + Logger::info('Author is hidden - rejected', ['author' => $authorid, 'network' => $network, 'url' => $url]); + return false; + } + $systemTags = []; $userTags = []; $denyTags = [];