Improve federated ID validation (#8372)
* Fix URI not being sufficiently validated with prefetched JSON * Add additional id validation to OStatus documents, when possible
This commit is contained in:
@ -7,7 +7,7 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
return [nil, false]
|
||||
end
|
||||
|
||||
return [nil, false] if @account.suspended?
|
||||
return [nil, false] if @account.suspended? || invalid_origin?
|
||||
|
||||
RedisLock.acquire(lock_options) do |lock|
|
||||
if lock.acquired?
|
||||
@ -204,6 +204,15 @@ class OStatus::Activity::Creation < OStatus::Activity::Base
|
||||
end
|
||||
end
|
||||
|
||||
def invalid_origin?
|
||||
return false unless id.start_with?('http') # Legacy IDs cannot be checked
|
||||
|
||||
needle = Addressable::URI.parse(id).normalized_host
|
||||
|
||||
!(needle.casecmp(@account.domain).zero? ||
|
||||
needle.casecmp(Addressable::URI.parse(@account.remote_url.presence || @account.uri).normalized_host).zero?)
|
||||
end
|
||||
|
||||
def lock_options
|
||||
{ redis: Redis.current, key: "create:#{id}" }
|
||||
end
|
||||
|
Reference in New Issue
Block a user