Fix #4666: Broken network link for some IPs.

This commit is contained in:
evazion
2021-03-01 18:09:15 -06:00
parent 92b8f24724
commit 52adf87489
5 changed files with 94 additions and 57 deletions

View File

@@ -24,6 +24,20 @@ module Danbooru
end
end
# If we're being reverse proxied behind Cloudflare, then Tor connections
# will appear to originate from 2405:8100:8000::/48.
# https://blog.cloudflare.com/cloudflare-onion-service/
def is_tor?
Danbooru::IpAddress.new("2405:8100:8000::/48").include?(ip_address)
end
def include?(other)
other = Danbooru::IpAddress.new(other)
return false if (ipv4? && other.ipv6?) || (ipv6? && other.ipv4?)
ip_address.include?(other.ip_address)
end
# "1.2.3.4/24" if the address is a subnet, "1.2.3.4" otherwise.
def to_s
ip_address.size > 1 ? ip_address.to_string : ip_address.to_s

View File

@@ -17,6 +17,7 @@ class IpLookup
def ip_info
return {} if ip_addr.is_local?
return {} if ip_addr.is_tor?
return {} if response.blank?
{
@@ -45,6 +46,7 @@ class IpLookup
end
def is_proxy?
return true if ip_addr.is_tor?
response[:security].present? && response[:security].values.any?
end