From 960f3849f24c30d02d482e1c66addc79d9ea5cbd Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Mon, 11 Nov 2024 21:47:47 -0700 Subject: [PATCH] Update AP helpers, reject statuses with invalid dates --- app/Util/ActivityPub/Helpers.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index 782404836..c54dc8e3d 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -298,6 +298,21 @@ class Helpers return null; } + public static function validateTimestamp($timestamp) + { + try { + $date = Carbon::parse($timestamp); + $now = Carbon::now(); + $tenYearsAgo = $now->copy()->subYears(10); + $isMoreThanTenYearsOld = $date->lt($tenYearsAgo); + $tomorrow = $now->copy()->addDay(); + $isMoreThanOneDayFuture = $date->gt($tomorrow); + return !($isMoreThanTenYearsOld || $isMoreThanOneDayFuture); + } catch (\Exception $e) { + return false; + } + } + public static function statusFirstOrFetch($url, $replyTo = false) { $url = self::validateUrl($url); @@ -329,6 +344,10 @@ class Helpers return; } + if(!self::validateTimestamp($res['published'])) { + 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) {