gearheads
/
mastodon
Archived
2
0
Fork 0

Fix situations in which instance actor can be set to a Mastodon-incompatible name (#22307)

* Validate internal actor

* Use “internal.actor” by default for the server actor username

* Fix instance actor username on the fly if it includes ':'

* Change actor name from internal.actor to mastodon.internal
gh/stable
Claire 2023-01-18 16:33:03 +01:00 committed by GitHub
parent 9b3e22c40d
commit d1387579b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -84,8 +84,8 @@ class Account < ApplicationRecord
validates :username, presence: true validates :username, presence: true
validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? } validates_with UniqueUsernameValidator, if: -> { will_save_change_to_username? }
# Remote user validations # Remote user validations, also applies to internal actors
validates :username, format: { with: USERNAME_ONLY_RE }, if: -> { !local? && will_save_change_to_username? } validates :username, format: { with: USERNAME_ONLY_RE }, if: -> { (!local? || actor_type == 'Application') && will_save_change_to_username? }
# Local user validations # Local user validations
validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' } validates :username, format: { with: /\A[a-z0-9_]+\z/i }, length: { maximum: 30 }, if: -> { local? && will_save_change_to_username? && actor_type != 'Application' }

View File

@ -13,9 +13,11 @@ module AccountFinderConcern
end end
def representative def representative
Account.find(-99).tap(&:ensure_keys!) actor = Account.find(-99).tap(&:ensure_keys!)
actor.update!(username: 'mastodon.internal') if actor.username.include?(':')
actor
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
Account.create!(id: -99, actor_type: 'Application', locked: true, username: Rails.configuration.x.local_domain) Account.create!(id: -99, actor_type: 'Application', locked: true, username: 'mastodon.internal')
end end
def find_local(username) def find_local(username)

View File

@ -1 +1 @@
Account.create_with(actor_type: 'Application', locked: true, username: ENV['LOCAL_DOMAIN'] || Rails.configuration.x.local_domain).find_or_create_by(id: -99) Account.create_with(actor_type: 'Application', locked: true, username: 'mastodon.internal').find_or_create_by(id: -99)