about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2020-03-01 14:09:51 -0600
committermultiple creatures <dev@multiple-creature.party>2020-03-01 14:09:51 -0600
commit014b6c95919bba62aa48aa54e093a9b0838278a9 (patch)
tree185bfef9a32b70ca8f6a99822579c4d653d8e41b
parent4666080b3bfa388adf22480d1e7819e0b69f9153 (diff)
immediately drop announces & creates whose object domain is blocked
-rw-r--r--app/lib/activitypub/activity.rb6
-rw-r--r--app/lib/activitypub/activity/announce.rb2
-rw-r--r--app/lib/activitypub/activity/create.rb2
3 files changed, 8 insertions, 2 deletions
diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb
index 12e925965..9366cc984 100644
--- a/app/lib/activitypub/activity.rb
+++ b/app/lib/activitypub/activity.rb
@@ -205,6 +205,12 @@ class ActivityPub::Activity
     account.manual_only?
   end
 
+  def blocked?
+    uri = object_uri.start_with?('http') ? object_uri : @object['url']
+    domain = uri.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*/).first
+    domain.blank? ? true : DomainBlock.suspend?(domain)
+  end
+
   def reject_payload!
     Rails.logger.info("Rejected #{@json['type']} activity #{@json['id']} from #{@account.uri}#{@options[:relayed_through_account] && "via #{@options[:relayed_through_account].uri}"}")
     nil
diff --git a/app/lib/activitypub/activity/announce.rb b/app/lib/activitypub/activity/announce.rb
index c9471f703..d15f3ee90 100644
--- a/app/lib/activitypub/activity/announce.rb
+++ b/app/lib/activitypub/activity/announce.rb
@@ -2,7 +2,7 @@
 
 class ActivityPub::Activity::Announce < ActivityPub::Activity
   def perform
-    return reject_payload! if !@options[:imported] && (delete_arrived_first?(@json['id']) || !related_to_local_activity?)
+    return reject_payload! if blocked? || !@options[:imported] && (delete_arrived_first?(@json['id']) || !related_to_local_activity?)
 
     original_status = status_from_object(announced_by: @account, local_only: !@account.known?)
 
diff --git a/app/lib/activitypub/activity/create.rb b/app/lib/activitypub/activity/create.rb
index 27f7e553f..8fd429059 100644
--- a/app/lib/activitypub/activity/create.rb
+++ b/app/lib/activitypub/activity/create.rb
@@ -2,7 +2,7 @@
 
 class ActivityPub::Activity::Create < ActivityPub::Activity
   def perform
-    return reject_payload! if unsupported_object_type? || !@options[:imported] && (invalid_origin?(@object['id']) || Tombstone.exists?(uri: @object['id']) || !related_to_local_activity?)
+    return reject_payload! if blocked? || unsupported_object_type? || !@options[:imported] && (invalid_origin?(@object['id']) || Tombstone.exists?(uri: @object['id']) || !related_to_local_activity?)
 
     unless known?
       if @options[:announced_by].nil?