class ActionDispatch::HostAuthorization::Permissions
:nodoc:
def allows?(host)
def allows?(host) @hosts.any? do |allowed| if allowed.is_a?(IPAddr) begin allowed === extract_hostname(host) rescue # IPAddr#=== raises an error if you give it a hostname instead of # IP. Treat similar errors as blocked access. false end else allowed === host end end end
def empty?
def empty? @hosts.empty? end
def extract_hostname(host)
def extract_hostname(host) host.slice(VALID_IP_HOSTNAME, "host") || host end
def initialize(hosts)
def initialize(hosts) @hosts = sanitize_hosts(hosts) end
def sanitize_hosts(hosts)
def sanitize_hosts(hosts) Array(hosts).map do |host| case host when Regexp then sanitize_regexp(host) when String then sanitize_string(host) else host end end end
def sanitize_regexp(host)
def sanitize_regexp(host) /\A#{host}#{PORT_REGEX}?\z/ end
def sanitize_string(host)
def sanitize_string(host) if host.start_with?(".") /\A#{SUBDOMAIN_REGEX}?#{Regexp.escape(host[1..-1])}#{PORT_REGEX}?\z/i else /\A#{Regexp.escape host}#{PORT_REGEX}?\z/i end end