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 the169.254.169.254metadata endpoint), or private-network hosts reachable from the device.This sanitizer allows only
http/httpsURLs whose host does not resolve to an internal address (see isInternalAddress), and returnsnull(block) otherwise. Public icon/overlay URLs continue to load unchanged.
-
-
Constructor Summary
Constructors Constructor Description DefaultKmlUrlSanitizer()
-
Method Summary
Modifier and Type Method Description StringsanitizeUrl(String url)Sanitizes a URL before it is used to fetch a resource. static booleanisInternalAddress(InetAddress address)Returns trueifaddressis one that a fetch triggered by an untrusted document must never reach.-
-
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
trueifaddressis 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
InetAddressdoes not classify but are still internal or special-purpose:fc00::/7IPv6 Unique Local Addresses (RFC 4193) not covered byisSiteLocalAddress().100.64.0.0/10IPv4 Carrier-Grade NAT / shared address space (RFC 6598).192.0.0.0/24IETF protocol assignments (RFC 6890), which includes NAT64 and other internal-only special-use addresses.
-
-
-
-