mirror of
https://github.com/axllent/mailpit.git
synced 2026-03-06 01:37:01 +00:00
By default all internal HTTP requests are now blocked, unless mailpit is started with the `--allow-internal-http-requests` flag (env `MP_ALLOW_INTERNAL_HTTP_REQUESTS=true`).
29 lines
952 B
Go
29 lines
952 B
Go
package tools
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
)
|
|
|
|
// IsInternalIP checks if the given IP address is an internal IP address (e.g., loopback, private, link-local, or multicast).
|
|
// IsLoopback — 127.0.0.0/8, ::1
|
|
// IsPrivate — 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7
|
|
// IsLinkLocalUnicast — 169.254.0.0/16, fe80::/10 (covers cloud metadata 169.254.169.254)
|
|
// IsLinkLocalMulticast — 224.0.0.0/24, ff02::/16
|
|
// IsUnspecified — 0.0.0.0, ::
|
|
// IsMulticast — 224.0.0.0/4, ff00::/8
|
|
func IsInternalIP(ip net.IP) bool {
|
|
return ip.IsLoopback() ||
|
|
ip.IsPrivate() ||
|
|
ip.IsLinkLocalUnicast() ||
|
|
ip.IsLinkLocalMulticast() ||
|
|
ip.IsUnspecified() ||
|
|
ip.IsMulticast()
|
|
}
|
|
|
|
// IsValidLinkURL checks if the provided string is a valid URL with http or https scheme and a non-empty hostname.
|
|
func IsValidLinkURL(str string) bool {
|
|
u, err := url.Parse(str)
|
|
return err == nil && (u.Scheme == "http" || u.Scheme == "https") && u.Hostname() != ""
|
|
}
|