From d3518f49bad2256face1a39a02ecf0647c96da87 Mon Sep 17 00:00:00 2001 From: Sho Kusano Date: Sun, 18 Feb 2024 20:49:29 +0900 Subject: [PATCH] Reject spammer --- app/lib/activitypub/activity/create.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb index 487b6522378ca3..369df6d5f69480 100644 --- a/app/lib/activitypub/activity/create.rb +++ b/app/lib/activitypub/activity/create.rb @@ -83,8 +83,16 @@ def process_status ApplicationRecord.transaction do @status = Status.create!(@params) attach_tags(@status) + + # Delete status on zero follower user and nearly created account with include some replies + if like_a_spam? + @status = nil + raise ActiveRecord::Rollback + end end + return if @status.nil? + resolve_thread(@status) fetch_replies(@status) distribute @@ -426,4 +434,13 @@ def increment_voters_count! poll.reload retry end + + def like_a_spam? + ( + !@status.account.local? && + @status.account.followers_count.zero? && + @status.account.created_at > 1.day.ago && + @mentions.count >= 2 + ) + end end