mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 02:47:48 +08:00
error out if attempting connection to loopback
This commit is contained in:
parent
cb2fb9cfe6
commit
094baf6fbf
@ -8,6 +8,7 @@ import (
|
||||
manet "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr/net"
|
||||
|
||||
peer "github.com/jbenet/go-ipfs/peer"
|
||||
"github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
// Dial connects to a particular peer, over a given network
|
||||
@ -23,6 +24,10 @@ func (d *Dialer) Dial(ctx context.Context, network string, remote peer.Peer) (Co
|
||||
return nil, fmt.Errorf("No remote address for network %s", network)
|
||||
}
|
||||
|
||||
if util.IsLoopbackAddr(raddr.String()) {
|
||||
return nil, fmt.Errorf("Attempted to connect to loopback address: %s", raddr)
|
||||
}
|
||||
|
||||
remote, err := d.Peerstore.Add(remote)
|
||||
if err != nil {
|
||||
log.Errorf("Error putting peer into peerstore: %s", remote)
|
||||
|
||||
@ -113,7 +113,13 @@ func GetenvBool(name string) bool {
|
||||
}
|
||||
|
||||
func IsLoopbackAddr(addr string) bool {
|
||||
return addr == "/ip4/127.0.0.1" || addr == "/ip6/::1"
|
||||
loops := []string{"/ip4/127.0.0.1", "/ip6/::1", "/ip4/0.0.0.0"}
|
||||
for _, loop := range loops {
|
||||
if strings.HasPrefix(addr, loop) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func GetLocalAddresses() ([]ma.Multiaddr, error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user