From 63dc6950d4930ea56d24ee83953b583a49c58c56 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Jul 2020 07:15:54 +0000 Subject: [PATCH 1/6] Issue 8860: Activities weren't fetchable all the time --- src/Module/Objects.php | 2 +- src/Protocol/ActivityPub/Transmitter.php | 23 ++++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/Module/Objects.php b/src/Module/Objects.php index b1346b585..8080289f1 100644 --- a/src/Module/Objects.php +++ b/src/Module/Objects.php @@ -57,7 +57,7 @@ class Objects extends BaseModule ['order' => ['origin' => true]] ); // Valid items are original post or posted from this node (including in the case of a forum) - if (!DBA::isResult($item) || !$item['origin'] && !strstr($item['author-link'], DI::baseUrl()->get())) { + if (!DBA::isResult($item) || !$item['origin'] && (parse_url($item['author-link'], PHP_URL_HOST) != parse_url(DI::baseUrl()->get(), PHP_URL_HOST))) { throw new HTTPException\NotFoundException(); } diff --git a/src/Protocol/ActivityPub/Transmitter.php b/src/Protocol/ActivityPub/Transmitter.php index e7a16f052..4bd3ccd4a 100644 --- a/src/Protocol/ActivityPub/Transmitter.php +++ b/src/Protocol/ActivityPub/Transmitter.php @@ -834,7 +834,7 @@ class Transmitter } } - $data = ActivityPub\Transmitter::createActivityFromItem($item_id); + $data = self::createActivityFromItem($item_id); DI::cache()->set($cachekey, $data, Duration::QUARTER_HOUR); return $data; @@ -873,8 +873,21 @@ class Transmitter $conversation = DBA::selectFirst('conversation', ['source'], $condition); if (DBA::isResult($conversation)) { $data = json_decode($conversation['source'], true); - if (!empty($data)) { - return $data; + if (!empty($data['type'])) { + if (in_array($data['type'], ['Create', 'Update'])) { + if ($object_mode) { + unset($data['@context']); + unset($data['signature']); + } + return $data; + } elseif (in_array('as:' . $data['type'], Receiver::CONTENT_TYPES)) { + if (!empty($data['@context'])) { + $context = $data['@context']; + unset($data['@context']); + } + unset($data['actor']); + $object = $data; + } } } @@ -882,7 +895,7 @@ class Transmitter } if (!$object_mode) { - $data = ['@context' => ActivityPub::CONTEXT]; + $data = ['@context' => $context ?? ActivityPub::CONTEXT]; if ($item['deleted'] && ($item['gravity'] == GRAVITY_ACTIVITY)) { $type = 'Undo'; @@ -909,7 +922,7 @@ class Transmitter $data = array_merge($data, self::createPermissionBlockForItem($item, false)); if (in_array($data['type'], ['Create', 'Update', 'Delete'])) { - $data['object'] = self::createNote($item); + $data['object'] = $object ?? self::createNote($item); } elseif ($data['type'] == 'Add') { $data = self::createAddTag($item, $data); } elseif ($data['type'] == 'Announce') { From 01911d9fc65fd2dde4f906d6fd5f547312051bd9 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 11 Jul 2020 09:16:05 -0400 Subject: [PATCH 2/6] Add default value for potentially missing keyhash property in mod/salmon --- mod/salmon.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mod/salmon.php b/mod/salmon.php index ea5c334c0..bc4410434 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -79,7 +79,7 @@ function salmon_post(App $a, $xml = '') { // stash away some other stuff for later $type = $base->data[0]->attributes()->type[0]; - $keyhash = $base->sig[0]->attributes()->keyhash[0]; + $keyhash = $base->sig[0]->attributes()->keyhash[0] ?? ''; $encoding = $base->encoding; $alg = $base->alg; From b4eea625b612281faedd2cec8782c8dffcb43508 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 11 Jul 2020 09:17:23 -0400 Subject: [PATCH 3/6] Add another check for $a->user in Content\Nav - Fix punctuation typo in logging call --- src/Content/Nav.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Nav.php b/src/Content/Nav.php index 4a9c71ce9..335f81bf3 100644 --- a/src/Content/Nav.php +++ b/src/Content/Nav.php @@ -187,7 +187,7 @@ class Nav 'name' => $a->user['username'], ]; } else { - DI::logger()->warning('Empty $a->user for local user'. ['local_user' => local_user(), '$a' => $a]); + DI::logger()->warning('Empty $a->user for local user', ['local_user' => local_user(), '$a' => $a]); } } @@ -256,7 +256,7 @@ class Nav } // The following nav links are only show to logged in users - if (local_user()) { + if (local_user() && !empty($a->user)) { $nav['network'] = ['network', DI::l10n()->t('Network'), '', DI::l10n()->t('Conversations from your friends')]; $nav['home'] = ['profile/' . $a->user['nickname'], DI::l10n()->t('Home'), '', DI::l10n()->t('Your posts and conversations')]; From 32a8f5003fb8d1b13443eafa7033e6d7406af885 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 11 Jul 2020 09:18:18 -0400 Subject: [PATCH 4/6] Add provision for result containing only connector profiles in Contact::getDetailsByURL --- src/Model/Contact.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index b11919b52..46104aaea 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1077,7 +1077,6 @@ class Contact } if (DBA::isResult($r)) { - $authoritativeResult = true; // If there is more than one entry we filter out the connector networks if (count($r) > 1) { foreach ($r as $id => $result) { @@ -1088,7 +1087,10 @@ class Contact } $profile = array_shift($r); + } + if (!empty($profile)) { + $authoritativeResult = true; // "bd" always contains the upcoming birthday of a contact. // "birthday" might contain the birthday including the year of birth. if ($profile["birthday"] > DBA::NULL_DATE) { From 2af20ea17aa62dfc907b0bae7fe590e9fabc2eee Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 11 Jul 2020 09:18:42 -0400 Subject: [PATCH 5/6] Fix wrong condition in Diaspora\Fetch --- src/Module/Diaspora/Fetch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Module/Diaspora/Fetch.php b/src/Module/Diaspora/Fetch.php index aba9d33be..c94badf7e 100644 --- a/src/Module/Diaspora/Fetch.php +++ b/src/Module/Diaspora/Fetch.php @@ -59,7 +59,7 @@ class Fetch extends BaseModule if (empty($item)) { $condition = ['guid' => $guid, 'network' => [Protocol::DFRN, Protocol::DIASPORA]]; $item = Item::selectFirst(['author-link'], $condition); - if (empty($item)) { + if (!empty($item["author-link"])) { $parts = parse_url($item["author-link"]); if (empty($parts["scheme"]) || empty($parts["host"])) { throw new HTTPException\InternalServerErrorException(); From e91daf8f46c298360c1d1d5dea8dbe0653c36248 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sat, 11 Jul 2020 09:19:22 -0400 Subject: [PATCH 6/6] Add logging for unexpected Search::searchGlobalContact return in Module\Search\Acl --- src/Module/Search/Acl.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Module/Search/Acl.php b/src/Module/Search/Acl.php index 82880f83c..cc8df3eab 100644 --- a/src/Module/Search/Acl.php +++ b/src/Module/Search/Acl.php @@ -79,6 +79,11 @@ class Acl extends BaseModule $contacts = []; foreach ($r as $g) { + if (empty($g['name'])) { + DI::logger()->warning('Wrong result item from Search::searchGlobalContact', ['$g' => $g, '$search' => $search, '$mode' => $mode, '$page' => $page]); + continue; + } + $contacts[] = [ 'photo' => ProxyUtils::proxifyUrl($g['photo'], false, ProxyUtils::SIZE_MICRO), 'name' => htmlspecialchars($g['name']),