about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-09-26 20:57:39 +0200
committerGitHub <noreply@github.com>2020-09-26 20:57:39 +0200
commitd60290044ed3f6f5cb84e1dafd317250d5c97d92 (patch)
treeb3c5a9b3f1272c1522353044adc0343d0bd5c0a6
parentff89025979abf3dae40b8e0745b2584cc3feb744 (diff)
Add environment variable to allow requests to some private addresses (#14722)
-rw-r--r--app/lib/request.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/app/lib/request.rb b/app/lib/request.rb
index 89fbeaf95..38048dad7 100644
--- a/app/lib/request.rb
+++ b/app/lib/request.rb
@@ -253,7 +253,15 @@ class Request
       alias new open
 
       def check_private_address(address)
-        raise Mastodon::HostValidationError if PrivateAddressCheck.private_address?(IPAddr.new(address.to_s))
+        addr = IPAddr.new(address.to_s)
+        return if private_address_exceptions.any? { |range| range.include?(addr) }
+        raise Mastodon::HostValidationError if PrivateAddressCheck.private_address?(addr)
+      end
+
+      def private_address_exceptions
+        @private_address_exceptions = begin
+          (ENV['ALLOWED_PRIVATE_ADDRESSES'] || '').split(',').map { |addr| IPAddr.new(addr) }
+        end
       end
     end
   end