mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 22:41:27 +00:00
Update AP helpers, reject statuses with invalid dates
This commit is contained in:
parent
3e68a88426
commit
960f3849f2
1 changed files with 19 additions and 0 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue