From 6b374c32a2b05bf65311ac704ef1b6db3ea85834 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 6 Oct 2018 13:16:52 +0000
Subject: [PATCH 1/2] Improved AP distribution / Only process trusted content

---
 src/Protocol/ActivityPub/Receiver.php |  1 +
 src/Worker/Notifier.php               | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php
index 9ffd9c3bc4..d3b38f9ee3 100644
--- a/src/Protocol/ActivityPub/Receiver.php
+++ b/src/Protocol/ActivityPub/Receiver.php
@@ -208,6 +208,7 @@ class Receiver
 
 		if (!$trust_source) {
 			logger('No trust for activity type "' . $activity['type'] . '", so we quit now.', LOGGER_DEBUG);
+			return;
 		}
 
 		switch ($activity['type']) {
diff --git a/src/Worker/Notifier.php b/src/Worker/Notifier.php
index d40d9068fa..b57c81db77 100644
--- a/src/Worker/Notifier.php
+++ b/src/Worker/Notifier.php
@@ -20,6 +20,7 @@ use Friendica\Protocol\ActivityPub;
 use Friendica\Protocol\Diaspora;
 use Friendica\Protocol\OStatus;
 use Friendica\Protocol\Salmon;
+use Friendica\Model\Conversation;
 
 require_once 'include/dba.php';
 require_once 'include/items.php';
@@ -514,6 +515,12 @@ class Notifier
 
 		if ($target_item['origin']) {
 			$inboxes = ActivityPub\Transmitter::fetchTargetInboxes($target_item, $uid);
+			logger('Origin item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG);
+		} elseif (!DBA::exists('conversation', ['item-uri' => $target_item['uri'], 'protocol' => Conversation::PARCEL_ACTIVITYPUB])) {
+			logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' is no AP post. It will not be distributed.', LOGGER_DEBUG);
+			return;
+		} else {
+			logger('Remote item ' . $item_id . ' with URL ' . $target_item['uri'] . ' will be distributed.', LOGGER_DEBUG);
 		}
 
 		if ($parent['origin']) {
@@ -521,6 +528,11 @@ class Notifier
 			$inboxes = array_merge($inboxes, $parent_inboxes);
 		}
 
+		if (empty($inboxes)) {
+			logger('No inboxes found for item ' . $item_id . ' with URL ' . $target_item['uri'] . '. It will not be distributed.', LOGGER_DEBUG);
+			return;
+		}
+
 		// Fill the item cache
 		ActivityPub\Transmitter::createCachedActivityFromItem($item_id);
 

From a413ce15aa14480f9c1b98f8f856b883fc6bb5d6 Mon Sep 17 00:00:00 2001
From: Michael <heluecht@pirati.ca>
Date: Sat, 6 Oct 2018 13:28:17 +0000
Subject: [PATCH 2/2] "name" must be plaintext

---
 src/Protocol/ActivityPub/Transmitter.php | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php
index 7d9d6626ce..081ba0b739 100644
--- a/src/Protocol/ActivityPub/Transmitter.php
+++ b/src/Protocol/ActivityPub/Transmitter.php
@@ -773,7 +773,7 @@ class Transmitter
 		$data['context'] = self::fetchContextURLForItem($item);
 
 		if (!empty($item['title'])) {
-			$data['name'] = BBCode::convert($item['title'], false, 7);
+			$data['name'] = BBCode::toPlaintext($item['title'], false);
 		}
 
 		$body = $item['body'];