Class URLValidator
java.lang.Object
org.springframework.ai.bedrock.converse.api.URLValidator
Utility class for detecting and normalizing URLs. Intended for use with multimodal user
inputs.
- Since:
- 1.0.0
- Author:
- Christian Tzolov
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidResolves all IP addresses for the given hostname and throwsSecurityExceptionif any resolve to a loopback, link-local, site-local, or wildcard address.static booleanisBlockedAddress(InetAddress address) Returnstrueif the given address is a loopback, link-local, site-local, or wildcard address.static booleanisValidURLBasic(String urlString) Deprecated.This method is not sufficient for security-sensitive URL validation and should not be relied upon for security-critical checks.static booleanisValidURLStrict(String urlString) Thorough validation using URL class More comprehensive but might be slower Validates protocol, host, port, and basic structurestatic @Nullable StringnormalizeURL(@Nullable String urlString) Attempts to fix common URL issues Adds protocol if missing, removes extra spaces
-
Method Details
-
isValidURLBasic
Deprecated.This method is not sufficient for security-sensitive URL validation and should not be relied upon for security-critical checks. UseisValidURLStrict(String)instead for robust validation.Check if the string looks like a URL using a simple regex pattern to disstinct it from base64 or other text. This is a quick check to avoid unnecessary URL parsing for clearly non-URL strings. -
isValidURLStrict
Thorough validation using URL class More comprehensive but might be slower Validates protocol, host, port, and basic structure -
assertNoInternalAddress
Resolves all IP addresses for the given hostname and throwsSecurityExceptionif any resolve to a loopback, link-local, site-local, or wildcard address. Protects against SSRF via internal network access (including IPv6 equivalents) and limits exposure from DNS rebinding by checking all returned addresses.- Parameters:
host- the hostname to check- Throws:
SecurityException- if the host resolves to a blocked internal address or cannot be resolved
-
isBlockedAddress
Returnstrueif the given address is a loopback, link-local, site-local, or wildcard address. Covers both IPv4 and IPv6 private/internal ranges.- Parameters:
address- the address to test- Returns:
trueif the address should be blocked
-
normalizeURL
Attempts to fix common URL issues Adds protocol if missing, removes extra spaces
-