From 1832397363a5f61ecc0d57c8051156a68bf817a2 Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Sun, 19 Dec 2021 19:45:38 +0000 Subject: [PATCH] [ActivityPub] Include recent actor type attribute in its creation Improve debug logs --- plugins/ActivityPub/Controller/Inbox.php | 21 ++++++++++++--------- plugins/ActivityPub/Util/Model/Actor.php | 6 ++++-- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/plugins/ActivityPub/Controller/Inbox.php b/plugins/ActivityPub/Controller/Inbox.php index d87662ff7b..b93f366592 100644 --- a/plugins/ActivityPub/Controller/Inbox.php +++ b/plugins/ActivityPub/Controller/Inbox.php @@ -63,7 +63,10 @@ class Inbox extends Controller */ public function handle(?int $gsactor_id = null): TypeResponse { - $error = fn(string $m): TypeResponse => new TypeResponse(json_encode(['error' => $m])); + $error = function (string $m, ?Exception $e = null): TypeResponse { + Log::error('ActivityPub Error Answer: ' . ($json = json_encode(['error' => $m, 'exception' => var_export($e, true)]))); + return new TypeResponse($json, 400); + }; $path = Router::url('activitypub_inbox', type: Router::ABSOLUTE_PATH); if (!is_null($gsactor_id)) { @@ -94,7 +97,7 @@ class Inbox extends Controller } unset($resource_parts); } catch (Exception $e) { - return $error('Invalid actor: ' . $e->getMessage()); + return $error('Invalid actor.', $e); } $activitypub_rsa = ActivitypubRsa::getByActor($actor); @@ -108,7 +111,7 @@ class Inbox extends Controller if (!isset($headers['signature'])) { Log::debug('ActivityPub Inbox: HTTP Signature: Missing Signature header.'); - return $error('Missing Signature header.', 400); + return $error('Missing Signature header.'); // TODO: support other methods beyond HTTP Signatures } @@ -117,7 +120,7 @@ class Inbox extends Controller Log::debug('ActivityPub Inbox: HTTP Signature Data: ' . print_r($signatureData, true)); if (isset($signatureData['error'])) { Log::debug('ActivityPub Inbox: HTTP Signature: ' . json_encode($signatureData, JSON_PRETTY_PRINT)); - return $error(json_encode($signatureData, JSON_PRETTY_PRINT), 400); + return $error(json_encode($signatureData, JSON_PRETTY_PRINT)); } [$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body); @@ -127,15 +130,15 @@ class Inbox extends Controller try { $res = Explorer::get_remote_user_activity($ap_actor->getUri()); if (is_null($res)) { - return $error('Invalid remote actor.'); + return $error('Invalid remote actor (null response).'); } - } catch (Exception) { - return $error('Invalid remote actor.'); + } catch (Exception $e) { + return $error('Invalid remote actor.', $e); } try { ActivitypubActor::update_profile($ap_actor, $actor, $activitypub_rsa, $res); - } catch (Exception) { - return $error('Failed to updated remote actor information.'); + } catch (Exception $e) { + return $error('Failed to updated remote actor information.', $e); } [$verified, /*$headers*/] = HTTPSignature::verify($actor_public_key, $signatureData, $headers, $path, $body); diff --git a/plugins/ActivityPub/Util/Model/Actor.php b/plugins/ActivityPub/Util/Model/Actor.php index 057710e81e..a8f2b927d9 100644 --- a/plugins/ActivityPub/Util/Model/Actor.php +++ b/plugins/ActivityPub/Util/Model/Actor.php @@ -38,7 +38,7 @@ use App\Core\GSFile; use App\Core\HTTPClient; use App\Core\Log; use App\Core\Router\Router; -use App\Core\Security; +use App\Core\UserRoles; use App\Entity\Actor as GSActor; use App\Util\Exception\ServerException; use App\Util\Formatting; @@ -79,8 +79,10 @@ class Actor extends Model 'nickname' => $person->get('preferredUsername'), 'fullname' => !empty($person->get('name')) ? $person->get('name') : null, 'created' => new DateTime($person->get('published') ?? 'now'), - 'bio' => $person->has('summary') ? mb_substr(Security::sanitize($person->get('summary')), 0, 1000) : null, + 'bio' => $person->get('summary'), 'is_local' => false, + 'type' => GSActor::PERSON, + 'roles' => UserRoles::USER, 'modified' => new DateTime(), ];