From 74cc41d4fae0575ffe6e3d1fd549511f9e9406be Mon Sep 17 00:00:00 2001 From: noellabo Date: Mon, 2 May 2022 23:36:12 +0900 Subject: [PATCH 1/2] Add Content-Type and User-Agent for activity delivery --- app/Jobs/DeletePipeline/FanoutDeletePipeline.php | 7 ++++++- app/Jobs/SharePipeline/SharePipeline.php | 7 ++++++- app/Jobs/SharePipeline/UndoSharePipeline.php | 7 ++++++- app/Jobs/StatusPipeline/StatusActivityPubDeliver.php | 7 ++++++- app/Jobs/StatusPipeline/StatusDelete.php | 7 ++++++- app/Jobs/StoryPipeline/StoryDelete.php | 7 ++++++- app/Jobs/StoryPipeline/StoryExpire.php | 7 ++++++- app/Jobs/StoryPipeline/StoryFanout.php | 8 +++++++- app/Services/ActivityPubDeliveryService.php | 7 ++++++- 9 files changed, 55 insertions(+), 9 deletions(-) diff --git a/app/Jobs/DeletePipeline/FanoutDeletePipeline.php b/app/Jobs/DeletePipeline/FanoutDeletePipeline.php index e1a9a6d1..a5ee65ac 100644 --- a/app/Jobs/DeletePipeline/FanoutDeletePipeline.php +++ b/app/Jobs/DeletePipeline/FanoutDeletePipeline.php @@ -63,7 +63,12 @@ class FanoutDeletePipeline implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/SharePipeline/SharePipeline.php b/app/Jobs/SharePipeline/SharePipeline.php index 5425ce97..1534a9f0 100644 --- a/app/Jobs/SharePipeline/SharePipeline.php +++ b/app/Jobs/SharePipeline/SharePipeline.php @@ -129,7 +129,12 @@ class SharePipeline implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/SharePipeline/UndoSharePipeline.php b/app/Jobs/SharePipeline/UndoSharePipeline.php index 04b2ede2..589a34fe 100644 --- a/app/Jobs/SharePipeline/UndoSharePipeline.php +++ b/app/Jobs/SharePipeline/UndoSharePipeline.php @@ -92,7 +92,12 @@ class UndoSharePipeline implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php index 759f5c72..21295beb 100644 --- a/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php +++ b/app/Jobs/StatusPipeline/StatusActivityPubDeliver.php @@ -87,7 +87,12 @@ class StatusActivityPubDeliver implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/StatusPipeline/StatusDelete.php b/app/Jobs/StatusPipeline/StatusDelete.php index 7ae3a822..e0dc2a71 100644 --- a/app/Jobs/StatusPipeline/StatusDelete.php +++ b/app/Jobs/StatusPipeline/StatusDelete.php @@ -144,7 +144,12 @@ class StatusDelete implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/StoryPipeline/StoryDelete.php b/app/Jobs/StoryPipeline/StoryDelete.php index a66fafd4..8f4353e5 100644 --- a/app/Jobs/StoryPipeline/StoryDelete.php +++ b/app/Jobs/StoryPipeline/StoryDelete.php @@ -108,7 +108,12 @@ class StoryDelete implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/StoryPipeline/StoryExpire.php b/app/Jobs/StoryPipeline/StoryExpire.php index 52e1c8e6..494d0d5d 100644 --- a/app/Jobs/StoryPipeline/StoryExpire.php +++ b/app/Jobs/StoryPipeline/StoryExpire.php @@ -125,7 +125,12 @@ class StoryExpire implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Jobs/StoryPipeline/StoryFanout.php b/app/Jobs/StoryPipeline/StoryFanout.php index 28073fe3..12f37cbf 100644 --- a/app/Jobs/StoryPipeline/StoryFanout.php +++ b/app/Jobs/StoryPipeline/StoryFanout.php @@ -79,7 +79,13 @@ class StoryFanout implements ShouldQueue $requests = function($audience) use ($client, $activity, $profile, $payload) { foreach($audience as $url) { - $headers = HttpSignature::sign($profile, $url, $activity); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $proxy = config(''); + $headers = HttpSignature::sign($profile, $url, $activity, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); yield function() use ($client, $url, $headers, $payload) { return $client->postAsync($url, [ 'curl' => [ diff --git a/app/Services/ActivityPubDeliveryService.php b/app/Services/ActivityPubDeliveryService.php index 00d6aa62..ead3316e 100644 --- a/app/Services/ActivityPubDeliveryService.php +++ b/app/Services/ActivityPubDeliveryService.php @@ -49,7 +49,12 @@ class ActivityPubDeliveryService $body = $this->payload; $payload = json_encode($body); - $headers = HttpSignature::sign($this->sender, $this->to, $body); + $version = config('pixelfed.version'); + $appUrl = config('app.url'); + $headers = HttpSignature::sign($this->sender, $this->to, $body, [ + 'Content-Type' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'User-Agent' => "(Pixelfed/{$version}; +{$appUrl})", + ]); $ch = curl_init($this->to); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); From b0cb6d20780e656c5efbf103d1ff37cc36b0cf47 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 2 May 2022 17:08:11 -0600 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 315cb737..6b355162 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -126,6 +126,7 @@ - Updated AP Inbox, fixes #3332. ([f8931dc7](https://github.com/pixelfed/pixelfed/commit/f8931dc7)) - Updated AdminReportController, add account delete button. ([563817a9](https://github.com/pixelfed/pixelfed/commit/563817a9)) - Updated ApiV1Controller, added /api/v2/media endpoint, fixes #3405 ([f07cc14c](https://github.com/pixelfed/pixelfed/commit/f07cc14c)) +- Updated AP fanout, added Content-Type and User-Agent for activity delivery ([@noellabo](https://github.com/noellabo)) ([209c125](https://github.com/pixelfed/pixelfed/commit/209c125)) - ([](https://github.com/pixelfed/pixelfed/commit/)) ## [v0.11.2 (2022-01-09)](https://github.com/pixelfed/pixelfed/compare/v0.11.1...v0.11.2)