Move `ALLOWED_PRIVATE_ADDRESSES` parsing to an initializer (#32850)

pull/2898/head
Claire 2024-11-12 14:00:52 +01:00 committed by GitHub
parent 32e5e1d3f1
commit f5f6273d2b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View File

@ -334,14 +334,10 @@ class Request
def check_private_address(address, host) def check_private_address(address, host)
addr = IPAddr.new(address.to_s) addr = IPAddr.new(address.to_s)
return if Rails.env.development? || private_address_exceptions.any? { |range| range.include?(addr) } return if Rails.env.development? || Rails.configuration.x.private_address_exceptions.any? { |range| range.include?(addr) }
raise Mastodon::PrivateNetworkAddressError, host if PrivateAddressCheck.private_address?(addr) raise Mastodon::PrivateNetworkAddressError, host if PrivateAddressCheck.private_address?(addr)
end end
def private_address_exceptions
@private_address_exceptions = (ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(/(?:\s*,\s*|\s+)/).map { |addr| IPAddr.new(addr) }
end
end end
end end

View File

@ -0,0 +1,5 @@
# frozen_string_literal: true
Rails.application.configure do
config.x.private_address_exceptions = (ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(/(?:\s*,\s*|\s+)/).map { |addr| IPAddr.new(addr) }
end