mirror of
https://github.com/nkanaev/yarr.git
synced 2025-10-13 23:39:58 +00:00
36 lines
522 B
Go
36 lines
522 B
Go
package server
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
"strings"
|
|
)
|
|
|
|
func isInternalFromURL(urlStr string) bool {
|
|
parsedURL, err := url.Parse(urlStr)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
host := parsedURL.Host
|
|
|
|
// Handle "host:port" format
|
|
if strings.Contains(host, ":") {
|
|
host, _, err = net.SplitHostPort(host)
|
|
if err != nil {
|
|
return false
|
|
}
|
|
}
|
|
|
|
if host == "localhost" {
|
|
return true
|
|
}
|
|
|
|
ip := net.ParseIP(host)
|
|
if ip == nil {
|
|
return false
|
|
}
|
|
|
|
return ip.IsPrivate() || ip.IsLoopback() || ip.IsLinkLocalUnicast()
|
|
}
|