Skip to content

Commit

Permalink
autonatv2: don't dial dns addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
sukunrt committed Oct 2, 2024
1 parent 9038a72 commit dea622d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 28 deletions.
4 changes: 2 additions & 2 deletions p2p/protocol/autonatv2/autonat.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const (
DialProtocol = "/libp2p/autonat/2/dial-request"

maxMsgSize = 8192
streamTimeout = time.Minute
streamTimeout = 15 * time.Second
dialBackStreamTimeout = 5 * time.Second
dialBackDialTimeout = 30 * time.Second
dialBackDialTimeout = 10 * time.Second
dialBackMaxMsgSize = 1024
minHandshakeSizeBytes = 30_000 // for amplification attack prevention
maxHandshakeSizeBytes = 100_000
Expand Down
29 changes: 4 additions & 25 deletions p2p/protocol/autonatv2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,31 +309,10 @@ func (ac *client) areAddrsConsistent(connLocalAddr, dialedAddr ma.Multiaddr) boo
return false
}
for i := 0; i < len(localProtos); i++ {
if i == 0 {
switch externalProtos[i].Code {
case ma.P_DNS, ma.P_DNSADDR:
if localProtos[i].Code == ma.P_IP4 || localProtos[i].Code == ma.P_IP6 {
continue
}
return false
case ma.P_DNS4:
if localProtos[i].Code == ma.P_IP4 {
continue
}
return false
case ma.P_DNS6:
if localProtos[i].Code == ma.P_IP6 {
continue
}
return false
}
if localProtos[i].Code != externalProtos[i].Code {
return false
}
} else {
if localProtos[i].Code != externalProtos[i].Code {
return false
}
// TODO: handle sni for websocket addresses. Ideally this should be handled by
// normalize multiaddr.
if localProtos[i].Code != externalProtos[i].Code {
return false
}
}
return true
Expand Down
2 changes: 1 addition & 1 deletion p2p/protocol/autonatv2/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func defaultSettings() *autoNATSettings {
serverPerPeerRPM: 12, // 1 every 5 seconds
serverDialDataRPM: 12, // 1 every 5 seconds
dataRequestPolicy: amplificationAttackPrevention,
amplificatonAttackPreventionDialWait: 3 * time.Second,
amplificatonAttackPreventionDialWait: 5 * time.Second,
now: time.Now,
}
}
Expand Down
6 changes: 6 additions & 0 deletions p2p/protocol/autonatv2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"math/rand"

ma "github.com/multiformats/go-multiaddr"
madns "github.com/multiformats/go-multiaddr-dns"
manet "github.com/multiformats/go-multiaddr/net"
)

Expand Down Expand Up @@ -170,6 +171,11 @@ func (as *server) serveDialRequest(s network.Stream) EventDialRequestCompleted {
if !as.allowPrivateAddrs && !manet.IsPublicAddr(a) {
continue
}
// Don't dial any address with a dns component.
// We may leak some DNS configuration information by DNS resolution.
if madns.Matches(a) {
continue
}
if !as.dialerHost.Network().CanDial(p, a) {
continue
}
Expand Down

0 comments on commit dea622d

Please sign in to comment.