mirror of
https://github.com/owncast/owncast.git
synced 2026-03-13 09:51:16 +08:00
* feat(ap): add support for shared inboxes to reduce outbound load * feat(db): refactor ap followers db into followers repository * fix(ap): use the updated activity library to pull out the shared inbox endpoint * chore(deps): point at updated build of owncast/activity * fix(ap): typeless endpoints * feat(test): update ActivityPub test to support shared inboxes * chore(test): remove unused variable * fix: feedback from review. Guard against SSRF/non-HTTPS/local and handle transaction errors
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
package utils
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
"sync"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
var (
|
|
allowInternalFederation bool
|
|
allowInternalFederationOnce sync.Once
|
|
)
|
|
|
|
// AllowInternalFederation returns true if the OWNCAST_ALLOW_INTERNAL_FEDERATION
|
|
// environment variable is set to "true". This is used for testing purposes only.
|
|
func AllowInternalFederation() bool {
|
|
allowInternalFederationOnce.Do(func() {
|
|
allowInternalFederation = os.Getenv("OWNCAST_ALLOW_INTERNAL_FEDERATION") == "true"
|
|
})
|
|
return allowInternalFederation
|
|
}
|
|
|
|
// IsHostnameInternal will attempt to determine if the hostname is internal to
|
|
// this server's network or is the loopback address.
|
|
// Returns false if OWNCAST_ALLOW_INTERNAL_FEDERATION is set to "true".
|
|
func IsHostnameInternal(hostname string) bool {
|
|
// Allow internal federation for testing purposes.
|
|
if AllowInternalFederation() {
|
|
return false
|
|
}
|
|
// If this is already an IP address don't try to resolve it
|
|
if ip := net.ParseIP(hostname); ip != nil {
|
|
return isIPAddressInternal(ip)
|
|
}
|
|
|
|
ips, err := net.LookupIP(hostname)
|
|
if err != nil {
|
|
// Default to false if we can't resolve the hostname.
|
|
log.Debugln("Unable to resolve hostname:", hostname)
|
|
return false
|
|
}
|
|
|
|
for _, ip := range ips {
|
|
if isIPAddressInternal(ip) {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
func isIPAddressInternal(ip net.IP) bool {
|
|
return ip.IsLoopback() || ip.IsPrivate()
|
|
}
|