Skip to content

Commit

Permalink
Merge pull request #466 from imas/feature/reject-spam
Browse files Browse the repository at this point in the history
リモートインスタンスからのスパムっぽいactivityを無視する
  • Loading branch information
takayamaki authored Feb 19, 2024
2 parents c9776db + cc476bc commit 8720c0a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions app/lib/activitypub/activity/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,15 @@ def process_status
ApplicationRecord.transaction do
@status = Status.create!(@params)
attach_tags(@status)

if seems_spam?
@status = nil
raise ActiveRecord::Rollback
end
end

return if @status.nil?

resolve_thread(@status)
fetch_replies(@status)
distribute
Expand Down Expand Up @@ -426,4 +433,14 @@ def increment_voters_count!
poll.reload
retry
end

SPAM_FILTER_MINIMUM_FOLLOWERS = ENV.fetch('SPAM_FILTER_MINIMUM_FOLLOWERS', 2).to_i
SPAM_FILTER_MINIMUM_CREATE_DAYS = ENV.fetch('SPAM_FILTER_MINIMUM_CREATE_DAYS', 2).to_i
SPAM_FILTER_MINIMUM_MENTIONS = ENV.fetch('SPAM_FILTER_MINIMUM_MENTIONS', 2).to_i
def seems_spam?
!@status.account.local? &&
@status.account.followers_count <= SPAM_FILTER_MINIMUM_FOLLOWERS &&
SPAM_FILTER_MINIMUM_CREATE_DAYS.day.ago <= @status.account.created_at &&
SPAM_FILTER_MINIMUM_MENTIONS <= @mentions.count
end
end

0 comments on commit 8720c0a

Please sign in to comment.