From eed00998bee846aefa3e86d9d0699ba41622f88b Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 13:27:05 -0600 Subject: [PATCH 1/6] Update AP Inbox, log activities --- app/Util/ActivityPub/Inbox.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 195b8d6ef..247f40d3a 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -40,6 +40,10 @@ class Inbox public function handle() { $this->handleVerb(); + + (new Activity())->save([ + 'data' => json_encode($this->payload) + ]); } public function handleVerb() From ef575ed483d9a994f37f3c400a577b147fdb3cf1 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 13:29:45 -0600 Subject: [PATCH 2/6] Update Activity model, add fillable attribute --- app/Activity.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Activity.php b/app/Activity.php index 130d947f5..4a2794ec8 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -7,6 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Activity extends Model { protected $dates = ['processed_at']; + protected $fillable = ['*']; public function toProfile() { From 155e960f54a4d5547e31795190f1d2b1ee7cac22 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 13:31:47 -0600 Subject: [PATCH 3/6] Update AP helpers, update user agent --- app/Util/ActivityPub/Helpers.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index f98647e97..c2a7a6da3 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -181,9 +181,11 @@ class Helpers { public static function zttpUserAgent() { + $version = config('pixelfed.version'); + $url = config('app.url'); return [ 'Accept' => 'application/activity+json', - 'User-Agent' => 'PixelfedBot - https://pixelfed.org', + 'User-Agent' => "(Pixelfed/{$version}; +{$url})", ]; } @@ -236,10 +238,6 @@ class Helpers { $activity = ['object' => $res]; } - if(isset($activity['object']['content']) == false) { - abort(400, 'Invalid object'); - } - $scope = 'private'; $cw = isset($res['sensitive']) ? (bool) $res['sensitive'] : false; From 28cbadf197c6970465317d72542f174d635bfc90 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 13:47:03 -0600 Subject: [PATCH 4/6] Update AP Helper --- app/Util/ActivityPub/Helpers.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index c2a7a6da3..034c7bbf7 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -285,10 +285,10 @@ class Helpers { } } - if(!self::validateUrl($res['id']) || + if(!self::validateUrl($activity['object']['id']) || !self::validateUrl($activity['object']['attributedTo']) ) { - abort(400, 'Invalid object url'); + return; } $idDomain = parse_url($res['id'], PHP_URL_HOST); @@ -300,7 +300,7 @@ class Helpers { $actorDomain !== $urlDomain || $idDomain !== $actorDomain ) { - abort(400, 'Invalid object'); + return; } $profile = self::profileFirstOrNew($activity['object']['attributedTo']); From 3063eb249a04b94d59b8b20446d700ea59c8eb3a Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 15:29:10 -0600 Subject: [PATCH 5/6] Update AP logger --- app/Activity.php | 2 +- app/Util/ActivityPub/Inbox.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Activity.php b/app/Activity.php index 4a2794ec8..18a4e74de 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -7,7 +7,7 @@ use Illuminate\Database\Eloquent\Model; class Activity extends Model { protected $dates = ['processed_at']; - protected $fillable = ['*']; + protected $fillable = ['data', 'to_id', 'from_id', 'object_type']; public function toProfile() { diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 247f40d3a..61de2536a 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -41,7 +41,7 @@ class Inbox { $this->handleVerb(); - (new Activity())->save([ + (new Activity())->create([ 'data' => json_encode($this->payload) ]); } From d0fefe242b7f90b3196eaba03dc19c211f191cae Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Wed, 29 Apr 2020 15:35:48 -0600 Subject: [PATCH 6/6] Update Inbox handler --- app/Util/ActivityPub/Inbox.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 61de2536a..802c1e5cb 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -311,6 +311,8 @@ class Inbox $id = $this->payload['object']['id']; switch ($type) { case 'Person': + // todo: fix race condition + return; $profile = Helpers::profileFetch($actor); if(!$profile || $profile->private_key != null) { return; @@ -327,8 +329,6 @@ class Inbox break; case 'Tombstone': - // todo: fix race condition - return; $profile = Helpers::profileFetch($actor); $status = Status::whereProfileId($profile->id) ->whereUri($id)