From 40b45b2a115fa1fa6b923e55e55db7615ae2d472 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 16 Feb 2024 02:15:39 -0700 Subject: [PATCH 1/2] Update Autospam, add live filters to block remote activities based on comma separated keywords --- app/Util/ActivityPub/Helpers.php | 17 +++++++++++++++++ app/Util/ActivityPub/Inbox.php | 16 ++++++++++++++++ config/autospam.php | 5 +++++ 3 files changed, 38 insertions(+) diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index 6f5b8ae11..e25fd93b7 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -315,6 +315,23 @@ class Helpers { return; } + if(config('autospam.live_filters.enabled')) { + $filters = config('autospam.live_filters.filters'); + if(!empty($filters) && isset($res['content']) && !empty($res['content']) && strlen($filters) > 3) { + $filters = array_map('trim', explode(',', $filters)); + $content = $res['content']; + foreach($filters as $filter) { + $filter = trim($filter); + if(!$filter || !strlen($filter)) { + continue; + } + if(str_contains($content, $filter)) { + return; + } + } + } + } + if(isset($res['object'])) { $activity = $res; } else { diff --git a/app/Util/ActivityPub/Inbox.php b/app/Util/ActivityPub/Inbox.php index 5c9959e17..b6ae80893 100644 --- a/app/Util/ActivityPub/Inbox.php +++ b/app/Util/ActivityPub/Inbox.php @@ -197,6 +197,22 @@ class Inbox public function handleCreateActivity() { $activity = $this->payload['object']; + if(config('autospam.live_filters.enabled')) { + $filters = config('autospam.live_filters.filters'); + if(!empty($filters) && isset($activity['content']) && !empty($activity['content']) && strlen($filters) > 3) { + $filters = array_map('trim', explode(',', $filters)); + $content = $activity['content']; + foreach($filters as $filter) { + $filter = trim($filter); + if(!$filter || !strlen($filter)) { + continue; + } + if(str_contains($content, $filter)) { + return; + } + } + } + } $actor = $this->actorFirstOrCreate($this->payload['actor']); if(!$actor || $actor->domain == null) { return; diff --git a/config/autospam.php b/config/autospam.php index 39975ec9b..bc0ce4681 100644 --- a/config/autospam.php +++ b/config/autospam.php @@ -33,5 +33,10 @@ return [ 'nlp' => [ 'enabled' => false, 'spam_sample_limit' => env('PF_AUTOSPAM_NLP_SPAM_SAMPLE_LIMIT', 200), + ], + + 'live_filters' => [ + 'enabled' => env('PF_AUTOSPAM_LIVE_FILTERS_ENABLED', false), + 'filters' => env('PF_AUTOSPAM_LIVE_FILTERS_CSV', ''), ] ]; From 83eadbb811c098e84ac108188f9262cfeced4e40 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Fri, 16 Feb 2024 02:20:11 -0700 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 322e5ff49..ab6220584 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.11.11...dev) +### Features +- Autospam Live Filters - block remote activities based on comma separated keywords ([40b45b2a](https://github.com/pixelfed/pixelfed/commit/40b45b2a)) + ### Updated - Update ApiV1Controller, fix network timeline ([0faf59e3](https://github.com/pixelfed/pixelfed/commit/0faf59e3))