From eff605b1f33b9a39f23983bef941c427b37f7641 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 26 Jul 2023 07:50:15 +0200 Subject: [PATCH] Prevent post mirroring by blocked users --- src/Model/Item.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index 9028c9f853..a2304056d3 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -21,6 +21,7 @@ namespace Friendica\Model; +use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Hook; @@ -2333,16 +2334,15 @@ class Item return; } - $cdata = Contact::getPublicAndUserContactID($item['author-id'], $item['uid']); - if (empty($cdata['user']) || ($cdata['user'] != $item['contact-id'])) { + if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => LocalRelationship::MIRROR_NATIVE_RESHARE])) { return; } - if (!DBA::exists('contact', ['id' => $cdata['user'], 'remote_self' => Contact::MIRROR_NATIVE_RESHARE])) { + if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) { return; } - if (!in_array($item['network'], [Protocol::ACTIVITYPUB, Protocol::DFRN])) { + if (User::getById($item['uid'], ['blocked'])['blocked'] ?? false) { return; } @@ -2353,7 +2353,7 @@ class Item public static function isRemoteSelf(array $contact, array &$datarray): bool { - if ($contact['remote_self'] != Contact::MIRROR_OWN_POST) { + if ($contact['remote_self'] != LocalRelationship::MIRROR_OWN_POST) { return false; } @@ -2380,6 +2380,11 @@ class Item return false; } + if (User::getById($contact['uid'], ['blocked'])['blocked'] ?? false) { + Logger::info('User is blocked', ['contact' => $contact]); + return false; + } + $datarray2 = $datarray; Logger::info('remote-self start', ['contact' => $contact['url'], 'remote_self' => $contact['remote_self'], 'item' => $datarray]); @@ -3222,7 +3227,7 @@ class Item $shared_html = substr($s, $pos + strlen(BBCode::SHARED_ANCHOR)); $s = substr($s, 0, $pos); } - + $s = self::addGallery($s, $attachments, $item['uri-id']); $s = self::addVisualAttachments($attachments, $item, $s, false); $s = self::addLinkAttachment($item['uri-id'], $attachments, $body, $s, false, $shared_links); @@ -3628,9 +3633,9 @@ class Item } $author = [ - 'uid' => 0, + 'uid' => 0, 'id' => $item['author-id'], - 'network' => $item['author-network'], + 'network' => $item['author-network'], 'url' => $item['author-link'], 'alias' => $item['author-alias'] ]; @@ -3721,9 +3726,9 @@ class Item if (!empty($plink) && ($item['private'] == self::PRIVATE)) { $author = [ - 'uid' => 0, + 'uid' => 0, 'id' => $item['author-id'], - 'network' => $item['author-network'], + 'network' => $item['author-network'], 'url' => $item['author-link'], 'alias' => $item['author-alias'], ]; -- 2.39.5