Add: プロキシアカウントを動的に識別する簡易的な仕組み

This commit is contained in:
KMY 2023-10-07 13:07:35 +09:00
parent 22d03b06da
commit 41c1aaf54d
3 changed files with 72 additions and 2 deletions

View file

@ -30,7 +30,7 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
follow_request = FollowRequest.create!(account: @account, target_account: target_account, uri: @json['id'])
if target_account.locked? || @account.silenced? || block_straight_follow? || (@account.bot? && target_account.user&.setting_lock_follow_from_bot)
if target_account.locked? || @account.silenced? || block_straight_follow? || ((@account.bot? || proxy_account?) && target_account.user&.setting_lock_follow_from_bot)
LocalNotificationWorker.perform_async(target_account.id, follow_request.id, 'FollowRequest', 'follow_request')
else
AuthorizeFollowService.new.call(@account, target_account)
@ -50,4 +50,24 @@ class ActivityPub::Activity::Follow < ActivityPub::Activity
def block_new_follow?
@block_new_follow ||= DomainBlock.reject_new_follow?(@account.domain)
end
def proxy_account?
(@account.username.downcase.include?('proxy') ||
@account.username.downcase.include?('followbot') ||
@account.display_name&.downcase&.include?('proxy') ||
@account.display_name&.include?('プロキシ') ||
@account.note&.downcase&.include?('proxy') ||
@account.note&.include?('プロキシ')) && proxyable_software?
end
def proxyable_software?
info = instance_info
return false if info.nil?
%w(misskey calckey firefish meisskey cherrypick).include?(info.software)
end
def instance_info
@instance_info ||= InstanceInfo.find_by(domain: @account.domain)
end
end

View file

@ -4,7 +4,8 @@ require 'rails_helper'
RSpec.describe ActivityPub::Activity::Follow do
let(:actor_type) { 'Person' }
let(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/inbox', actor_type: actor_type) }
let(:note) { '' }
let(:sender) { Fabricate(:account, domain: 'example.com', inbox_url: 'https://example.com/inbox', actor_type: actor_type, note: note) }
let(:recipient) { Fabricate(:account) }
let(:json) do
@ -103,6 +104,54 @@ RSpec.describe ActivityPub::Activity::Follow do
end
end
context 'when unlocked misskey proxy account but locked from bot' do
let(:note) { 'i am proxy.' }
before do
Fabricate(:instance_info, domain: 'example.com', software: 'misskey')
recipient.user.settings['lock_follow_from_bot'] = true
recipient.user.save!
subject.perform
end
it 'does not create a follow from sender to recipient' do
expect(sender.following?(recipient)).to be false
end
it 'creates a follow request' do
expect(sender.requested?(recipient)).to be true
expect(sender.follow_requests.find_by(target_account: recipient).uri).to eq 'foo'
end
end
context 'when unlocked mastodon proxy account but locked from bot' do
let(:note) { 'i am proxy.' }
before do
Fabricate(:instance_info, domain: 'example.com', software: 'mastodon')
recipient.user.settings['lock_follow_from_bot'] = true
recipient.user.save!
subject.perform
end
it 'does not create a follow from sender to recipient' do
expect(sender.following?(recipient)).to be true
end
end
context 'when unlocked misskey normal account but locked from bot' do
before do
Fabricate(:instance_info, domain: 'example.com', software: 'misskey')
recipient.user.settings['lock_follow_from_bot'] = true
recipient.user.save!
subject.perform
end
it 'does not create a follow from sender to recipient' do
expect(sender.following?(recipient)).to be true
end
end
context 'when domain block reject_straight_follow' do
before do
Fabricate(:domain_block, domain: 'example.com', reject_straight_follow: true)

View file

@ -21,6 +21,7 @@ RSpec.describe ActivityPub::ProcessAccountService, type: :service do
searchableBy: searchable_by,
indexable: indexable,
summary: sender_bio,
actor_type: 'Person',
}.with_indifferent_access
end