Class DefaultKmlUrlSanitizer

  • All Implemented Interfaces:
    com.google.maps.android.data.kml.KmlUrlSanitizer

    
    public class DefaultKmlUrlSanitizer
     implements KmlUrlSanitizer
                        

    Default, secure KmlUrlSanitizer used when a layer loads remote icons/overlays.

    Icon and GroundOverlay <href> values come from the parsed KML/GeoJSON document, which is frequently untrusted (downloaded, user-provided, or shared). Fetching those URLs without validation is a Server-Side Request Forgery (SSRF) primitive: a crafted document can make the app issue requests to loopback, link-local (including the 169.254.169.254 metadata endpoint), or private-network hosts reachable from the device.

    This sanitizer allows only http/https URLs whose host does not resolve to an internal address (see isInternalAddress), and returns null (block) otherwise. Public icon/overlay URLs continue to load unchanged.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      String sanitizeUrl(String url) Sanitizes a URL before it is used to fetch a resource.
      static boolean isInternalAddress(InetAddress address) Returns true if address is one that a fetch triggered by an untrusted document must never reach.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DefaultKmlUrlSanitizer

        DefaultKmlUrlSanitizer()
    • Method Detail

      • sanitizeUrl

         String sanitizeUrl(String url)

        Sanitizes a URL before it is used to fetch a resource.

        Parameters:
        url - The raw URL from the KML.
        Returns:

        A safe, validated URL string, or null to block this resource.

      • isInternalAddress

         static boolean isInternalAddress(InetAddress address)

        Returns true if address is one that a fetch triggered by an untrusted document must never reach.

        Covers the ranges recognized by InetAddress (loopback, wildcard/any-local, link-local, IPv4 RFC 1918 site-local, multicast) plus ranges that InetAddress does not classify but are still internal or special-purpose:

        • fc00::/7 IPv6 Unique Local Addresses (RFC 4193) not covered by isSiteLocalAddress().
        • 100.64.0.0/10 IPv4 Carrier-Grade NAT / shared address space (RFC 6598).
        • 192.0.0.0/24 IETF protocol assignments (RFC 6890), which includes NAT64 and other internal-only special-use addresses.