diff --git a/app/lib/request.rb b/app/lib/request.rb index d7da9fe63c..a12e6e3747 100644 --- a/app/lib/request.rb +++ b/app/lib/request.rb @@ -334,14 +334,10 @@ class Request def check_private_address(address, host) 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) end - - def private_address_exceptions - @private_address_exceptions = (ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(/(?:\s*,\s*|\s+)/).map { |addr| IPAddr.new(addr) } - end end end diff --git a/config/initializers/allowed_private_addresses.rb b/config/initializers/allowed_private_addresses.rb new file mode 100644 index 0000000000..65c7af03b4 --- /dev/null +++ b/config/initializers/allowed_private_addresses.rb @@ -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