urlutil

package
v0.0.0-...-75bc046 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHost

func ExtractHost(rawURL string) string

ExtractHost extracts and lowercases the host from a URL string. Returns empty string if URL is invalid or has no host.

func ExtractHostname

func ExtractHostname(host string) string

ExtractHostname extracts the hostname from a host string, removing the port if present. Input is a host string (NOT a full URL), e.g., "example.com:8080" or "example.com". Handles IPv6 addresses correctly - does not strip the port portion of an IPv6 literal.

func IsPrivateIP

func IsPrivateIP(ip net.IP) bool

IsPrivateIP returns true if the given IP belongs to a private or reserved range.

func IsSameOrigin

func IsSameOrigin(baseHost, requestHost string) bool

IsSameOrigin returns true if hosts are the same domain or one is a subdomain of the other. Strips ports before comparison. Both hosts should already be lowercased.

func ValidateHostNotPrivateIP

func ValidateHostNotPrivateIP(hostname string) error

ValidateHostNotPrivateIP checks if a hostname is a private IP literal. It does NOT perform DNS resolution -- only rejects IP addresses that parse directly to private ranges. Domain names pass through (use ValidateResolvedIP after DNS resolution for full protection).

func ValidateResolvedIP

func ValidateResolvedIP(ip net.IP) error

ValidateResolvedIP checks if a resolved IP address belongs to a private or reserved range. Use this after DNS resolution to block DNS rebinding attacks.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL