Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Commit

Permalink
fix: restrict dials to IP + TCP
Browse files Browse the repository at this point in the history
That is, forbid DNS. See libp2p/go-libp2p#841
  • Loading branch information
Stebalien committed Apr 3, 2020
1 parent ef8a962 commit 8cb6edc
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
var WsProtocol = ma.ProtocolWithCode(ma.P_WS)

// WsFmt is multiaddr formatter for WsProtocol
var WsFmt = mafmt.And(mafmt.TCP, mafmt.Base(WsProtocol.Code))
var WsFmt = mafmt.And(mafmt.TCP, mafmt.Base(ma.P_WS))

// WsCodec is the multiaddr-net codec definition for the websocket transport
var WsCodec = &manet.NetCodec{
Expand All @@ -28,6 +28,10 @@ var WsCodec = &manet.NetCodec{
ParseNetAddr: ParseWebsocketNetAddr,
}

// This is _not_ WsFmt because we want the transport to stick to dialing fully
// resolved addresses.
var dialMatcher = mafmt.And(mafmt.IP, mafmt.Base(ma.P_TCP), mafmt.Base(ma.P_WS))

func init() {
manet.RegisterNetCodec(WsCodec)
}
Expand All @@ -44,7 +48,7 @@ func New(u *tptu.Upgrader) *WebsocketTransport {
}

func (t *WebsocketTransport) CanDial(a ma.Multiaddr) bool {
return WsFmt.Matches(a)
return dialMatcher.Matches(a)
}

func (t *WebsocketTransport) Protocols() []int {
Expand Down

0 comments on commit 8cb6edc

Please sign in to comment.