validate!

in lib/gitlab/url_blocker.rb [22:73]


      def validate!(
        url,
        ports: [],
        schemes: [],
        allow_localhost: false,
        allow_local_network: true,
        ascii_only: false,
        enforce_user: false,
        enforce_sanitization: false,
        dns_rebind_protection: true)
        
        

        return [nil, nil] if url.nil?

        
        uri = parse_url(url)

        validate_html_tags!(uri) if enforce_sanitization

        hostname = uri.hostname
        port = get_port(uri)

        unless internal?(uri)
          validate_scheme!(uri.scheme, schemes)
          validate_port!(port, ports) if ports.any?
          validate_user!(uri.user) if enforce_user
          validate_hostname!(hostname)
          validate_unicode_restriction!(uri) if ascii_only
        end

        begin
          addrs_info = Addrinfo.getaddrinfo(hostname, port, nil, :STREAM).map do |addr|
            addr.ipv6_v4mapped? ? addr.ipv6_to_ipv4 : addr
          end
        rescue SocketError
          return [uri, nil]
        end

        protected_uri_with_hostname = enforce_uri_hostname(addrs_info, uri, hostname, dns_rebind_protection)

        
        return protected_uri_with_hostname if internal?(uri)

        validate_localhost!(addrs_info) unless allow_localhost
        validate_loopback!(addrs_info) unless allow_localhost
        validate_local_network!(addrs_info) unless allow_local_network
        validate_link_local!(addrs_info) unless allow_local_network

        protected_uri_with_hostname
      end