diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-07-22 21:12:54 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-07-22 21:12:54 -0500 |
commit | 2822fbc443addf08651961543e1a63abdd409d87 (patch) | |
tree | ab981650f9cd87a3fb919e0ddadb40051a3a3800 /app/lib | |
parent | 86f29a68fbf5344291b21253f597a914cec18f02 (diff) |
move autoreject check to own module & check for reject before pulling resources
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/activitypub/activity.rb | 34 |
1 files changed, 1 insertions, 33 deletions
diff --git a/app/lib/activitypub/activity.rb b/app/lib/activitypub/activity.rb index d7a805ab3..fee8fcd25 100644 --- a/app/lib/activitypub/activity.rb +++ b/app/lib/activitypub/activity.rb @@ -2,6 +2,7 @@ class ActivityPub::Activity include JsonLdHelper + include AutorejectHelper include Redisable SUPPORTED_TYPES = %w(Note Question).freeze @@ -185,37 +186,4 @@ class ActivityPub::Activity Rails.logger.info("Rejected #{@json['type']} activity #{@json['id']} from #{@account.uri}#{@options[:relayed_through_account] && "via #{@options[:relayed_through_account].uri}"}") nil end - - def should_reject? - return unless @object - - oid = @json['id'] - return true if ENV.fetch('REJECT_IF_ID_STARTS_WITH', '').split.any? { |r| oid.start_with?(r) } - return true if ENV.fetch('REJECT_IF_ID_CONTAINS', '').split.any? { |r| r.in?(oid) } - - url = object_uri.start_with?('http') ? object_uri : @object['url'] - return if url.nil? - - domain = url.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*/).first - blocks = DomainBlock.suspend - return true if blocks.where(domain: domain).or(blocks.where('domain LIKE ?', "%.#{domain}")).exists? - - if @object['@context'].is_a?(Array) - inline_context = @object['@context'].find { |item| item.is_a?(Hash) } - if inline_context - keys = inline_context.keys - return true if ENV.fetch('REJECT_IF_CONTEXT_EQUALS', '').split.any? { |r| r.in?(keys) } - return true if ENV.fetch('REJECT_IF_CONTEXT_STARTS_WITH', '').split.any? { |r| keys.any? { |k| k.start_with?(r) } } - return true if ENV.fetch('REJECT_IF_CONTEXT_CONTAINS', '').split.any? { |r| keys.any? { |k| r.in?(k) } } - end - end - end - - def autoreject? - if @options[:imported] || should_reject? - Rails.logger.info("Auto-rejected #{@json['type']} activity #{@json['id']}") - return true - end - false - end end |