]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/Notifier.php
Avoid local network communication / invalid url requests
[friendica.git] / src / Worker / Notifier.php
index 2d21a0937c748fab73102d3cf646e9010aea72a9..e4189c2c75c4b2fb12e1c09c8d2a8ff466c734f9 100644 (file)
@@ -42,6 +42,7 @@ use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\Delivery;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
+use Friendica\Util\LDSignature;
 use Friendica\Util\Network;
 use Friendica\Util\Strings;
 
@@ -516,7 +517,11 @@ class Notifier
 
                foreach ($contacts as $contact) {
                        // Direct delivery of local contacts
-                       if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::DELETION, Delivery::MAIL]) && $target_uid = User::getIdForURL($contact['url'])) {
+                       if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::MAIL]) && $target_uid = User::getIdForURL($contact['url'])) {
+                               if ($cmd == Delivery::DELETION) {
+                                       Logger::info('No need to deliver deletions internally', ['uid' => $target_uid, 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'uri' => $target_item['uri']]);
+                                       continue;
+                               }
                                if ($target_item['origin'] || ($target_item['network'] != Protocol::ACTIVITYPUB)) {
                                        if ($target_uid != $target_item['uid']) {
                                                $fields = ['protocol' => Conversation::PARCEL_LOCAL_DFRN, 'direction' => Conversation::PUSH, 'post-reason' => Item::PR_DIRECT];
@@ -795,6 +800,7 @@ class Notifier
                        }
 
                        Logger::info('Origin item will be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
+                       $check_signature = false;
                } elseif (!Post\Activity::exists($target_item['uri-id'])) {
                        Logger::info('Remote item is no AP post. It will not be distributed.', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
                        return ['count' => 0, 'contacts' => []];
@@ -806,6 +812,7 @@ class Notifier
                        }
 
                        Logger::info('Remote item will be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
+                       $check_signature = ($target_item['gravity'] == Item::GRAVITY_ACTIVITY); 
                } else {
                        Logger::info('Remote activity will not be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
                        return ['count' => 0, 'contacts' => []];
@@ -817,12 +824,17 @@ class Notifier
                }
 
                // Fill the item cache
-               $cache = ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
-               if (empty($cache)) {
+               $activity = ActivityPub\Transmitter::createCachedActivityFromItem($target_item['id'], true);
+               if (empty($activity)) {
                        Logger::info('Item cache was not created. The post will not be distributed.', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
                        return ['count' => 0, 'contacts' => []];
                }
 
+               if ($check_signature && !LDSignature::isSigned($activity)) {
+                       Logger::info('Unsigned remote activity will not be distributed', ['id' => $target_item['id'], 'url' => $target_item['uri'], 'verb' => $target_item['verb']]);
+                       return ['count' => 0, 'contacts' => []];
+               }
+
                $delivery_queue_count = 0;
                $contacts = [];
 
@@ -831,7 +843,11 @@ class Notifier
 
                        if ((count($receivers) == 1) && Network::isLocalLink($inbox)) {
                                $contact = Contact::getById($receivers[0], ['url']);
-                               if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::DELETION, Delivery::MAIL]) && ($target_uid = User::getIdForURL($contact['url']))) {
+                               if (!in_array($cmd, [Delivery::RELOCATION, Delivery::SUGGESTION, Delivery::MAIL]) && ($target_uid = User::getIdForURL($contact['url']))) {
+                                       if ($cmd == Delivery::DELETION) {
+                                               Logger::info('No need to deliver deletions internally', ['uid' => $target_uid, 'guid' => $target_item['guid'], 'uri-id' => $target_item['uri-id'], 'uri' => $target_item['uri']]);
+                                               continue;
+                                       }
                                        if ($target_item['origin'] || ($target_item['network'] != Protocol::ACTIVITYPUB)) {
                                                if ($target_uid != $target_item['uid']) {
                                                        $fields = ['protocol' => Conversation::PARCEL_LOCAL_DFRN, 'direction' => Conversation::PUSH, 'post-reason' => Item::PR_BCC];