]> git.mxchange.org Git - friendica.git/commitdiff
Prevent endless loops and long running feed processing
authorMichael <heluecht@pirati.ca>
Sun, 22 Mar 2020 13:05:35 +0000 (13:05 +0000)
committerMichael <heluecht@pirati.ca>
Sun, 22 Mar 2020 13:05:35 +0000 (13:05 +0000)
src/Model/GContact.php
src/Protocol/ActivityPub.php
src/Protocol/Feed.php
static/defaults.config.php

index 2606edb9e43803fd4dc2a3349267602a150aa095..09eeda4a2ad22a3d3e03cf9a704dc4b08300be96 100644 (file)
@@ -884,11 +884,11 @@ class GContact
                        $items = $outbox['orderedItems'];
                } elseif (!empty($outbox['first']['orderedItems'])) {
                        $items = $outbox['first']['orderedItems'];
-               } elseif (!empty($outbox['first']['href'])) {
+               } elseif (!empty($outbox['first']['href']) && ($outbox['first']['href'] != $feed)) {
                        self::updateFromOutbox($outbox['first']['href'], $data);
                        return;
                } elseif (!empty($outbox['first'])) {
-                       if (is_string($outbox['first'])) {
+                       if (is_string($outbox['first']) && ($outbox['first'] != $feed)) {
                                self::updateFromOutbox($outbox['first'], $data);
                        } else {
                                Logger::warning('Unexpected data', ['outbox' => $outbox]);
index 894c7f6d36c7d29f89a23f8cc2c675848a7e38ee..6f835e7e8fb32befed0a53d90a03e80f6c9068a8 100644 (file)
@@ -231,7 +231,7 @@ class ActivityPub
                        $items = $data['orderedItems'];
                } elseif (!empty($data['first']['orderedItems'])) {
                        $items = $data['first']['orderedItems'];
-               } elseif (!empty($data['first']) && is_string($data['first'])) {
+               } elseif (!empty($data['first']) && is_string($data['first']) && ($data['first'] != $url)) {
                        return self::fetchItems($data['first'], $uid);
                } else {
                        $items = [];
index 4eb6c729499cafacb76fdf3dfb8da8392492d256..397edf3b41b4817f288dd1504db41526636ba9e7 100644 (file)
@@ -232,8 +232,16 @@ class Feed {
                }
 
                $items = [];
+
+               // Limit the number of items that are about to be fetched
+               $total_items = ($entries->length - 1);
+               $max_items = DI::config()->get('system', 'max_feed_items');
+               if (($max_items > 0) && ($total_items > $max_items)) {
+                       $total_items = $max_items;
+               }
+
                // Importing older entries first
-               for ($i = $entries->length - 1; $i >= 0; --$i) {
+               for ($i = $total_items; $i >= 0; --$i) {
                        $entry = $entries->item($i);
 
                        $item = array_merge($header, $author);
index 110c016eb0b2e1bf626879b63d17dac3dd612ed0..66805a121b1069ea13d349d86c7f78e32b63902e 100644 (file)
@@ -273,6 +273,10 @@ return [
                // Maximum number of queue items for a single contact before subsequent messages are discarded.
                'max_contact_queue' => 500,
 
+               // max_feed_items (Integer)
+               // Maximum number of feed items that are fetched and processed. For unlimited items set to 0.
+               'max_feed_items' => 10,
+
                // max_image_length (Integer)
                // An alternate way of limiting picture upload sizes.
                // Specify the maximum pixel  length that pictures are allowed to be (for non-square pictures, it will apply to the longest side).