Add shared inbox support for ActivityPub delivery (#4755)
* 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
This commit is contained in:
@@ -2,13 +2,34 @@ 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)
|
||||
|
||||
Reference in New Issue
Block a user