about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/helpers/autoreject_helper.rb40
1 files changed, 4 insertions, 36 deletions
diff --git a/app/helpers/autoreject_helper.rb b/app/helpers/autoreject_helper.rb
index 264fd94e2..ec88a4825 100644
--- a/app/helpers/autoreject_helper.rb
+++ b/app/helpers/autoreject_helper.rb
@@ -1,8 +1,6 @@
 module AutorejectHelper
   include ModerationHelper
 
-  AUTOBLOCK_TRIGGERS = [:context, :context_starts_with, :context_contains]
-
 	def should_reject?(uri = nil)
     if uri.nil?
       if @object
@@ -13,14 +11,15 @@ module AutorejectHelper
     end
 
     return if uri.nil?
+    return unless @json || @object
 
     domain = uri.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*/).first
     blocks = DomainBlock.suspend
     return [:domain, uri] if blocks.where(domain: domain).or(blocks.where('domain LIKE ?', "%.#{domain}")).exists?
 
-    return unless @json || @object
-
-    context = @object['@context'] if @object
+    domain = uri.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*/).first
+    blocks = DomainBlock.suspend
+    return [:domain, uri] if blocks.where(domain: domain).or(blocks.where('domain LIKE ?', "%.#{domain}")).exists?
 
     if @json
       oid = @json['id']
@@ -41,20 +40,6 @@ module AutorejectHelper
         return [:username_starts_with, uri] if ENV.fetch('REJECT_IF_USERNAME_STARTS_WITH', '').split.any? { |r| username.start_with?(r) }
         return [:username_contains, uri] if ENV.fetch('REJECT_IF_USERNAME_CONTAINS', '').split.any? { |r| r.in?(username) }
       end
-
-      context = @json['@context'] unless @object && context
-    end
-
-    return unless context
-
-    if context.is_a?(Array)
-      inline_context = context.find { |item| item.is_a?(Hash) }
-      if inline_context
-        keys = inline_context.keys
-        return [:context, uri] if ENV.fetch('REJECT_IF_CONTEXT_EQUALS', '').split.any? { |r| r.in?(keys) }
-        return [:context_starts_with, uri] if ENV.fetch('REJECT_IF_CONTEXT_STARTS_WITH', '').split.any? { |r| keys.any? { |k| k.start_with?(r) } }
-        return [:context_contains, uri] if ENV.fetch('REJECT_IF_CONTEXT_CONTAINS', '').split.any? { |r| keys.any? { |k| r.in?(k) } }
-      end
     end
 
     nil
@@ -74,34 +59,17 @@ module AutorejectHelper
       "the author's username starts with a blocked phrase"
     when :username_contains
       "the author's username contains a blocked phrase"
-    when :context
-      "the object's JSON-LD context has a key matching a blocked phrase"
-    when :context_starts_with
-      "the object's JSON-LD context has a key starting with a blocked phrase"
-    when :context_contains
-      "the object's JSON-LD context has a key containing a blocked phrase"
     else
       "of an undefined reason"
     end
   end
 
-  def should_autoblock?(reason)
-    @json['type'] == 'Create' && reason.in?(AUTOBLOCK_TRIGGERS)
-  end
-
-  def autoblock!(uri, reason)
-    return if uri.nil?
-    domain = uri.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*/).first
-    domain_policy(uri, :suspend, "Sent an ActivityPub payload (#{uri}) where #{reason}.")
-  end
-
   def autoreject?(uri = nil)
     return false if @options && @options[:imported]
     reason, uri = should_reject?(uri)
     if reason
       reason = reject_reason(reason)
       if @json
-        autoblock!(uri, reason) if should_autoblock?(reason)
         Rails.logger.info("Rejected an incoming '#{@json['type']}#{@object && " #{@object['type']}".rstrip}' from #{@json['id']} because #{reason}.")
       elsif uri
         Rails.logger.info("Rejected an outgoing request to #{uri} because #{reason}.")