Skip to content
This repository was archived by the owner on Aug 18, 2020. It is now read-only.

Commit 8485432

Browse files
committed
network-transport-tcp: conditionalie the peer host address check
1 parent ce49dba commit 8485432

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

infra/src/Pos/Infra/Diffusion/Transport/TCP.hs

+10-5
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,31 @@ import Pos.Util.Trace (Trace, traceWith)
2121
-- - Given connection timeout in us
2222
-- - Given address (possibly unaddressable)
2323
-- - A fair QDisc
24-
-- - Check the peer host against resolved host (prevents easy denial-of-service)
24+
-- - Optionally check the peer host against resolved host, which prevents easy
25+
-- denial-of-service attacks
2526
-- - Do not crash the server if 'accept' fails; instead, use the given
2627
-- 'Trace' to log the reason and continue trying to accept new connections
2728
bracketTransportTCP
2829
:: Trace IO Text
2930
-> Microsecond
3031
-> TCP.TCPAddr
32+
-> Bool
3133
-> (NT.Transport -> IO a)
3234
-> IO a
33-
bracketTransportTCP logTrace connectionTimeout tcpAddr k = bracket
34-
(createTransportTCP logTrace connectionTimeout tcpAddr)
35+
bracketTransportTCP logTrace connectionTimeout tcpAddr checkPeerHost k = bracket
36+
(createTransportTCP logTrace connectionTimeout tcpAddr checkPeerHost)
3537
NT.closeTransport
3638
k
3739

3840
createTransportTCP
3941
:: Trace IO Text -- ^ Whenever there's an error accepting a new connection.
4042
-> Microsecond -- ^ Connection timeout
4143
-> TCP.TCPAddr
44+
-> Bool -- ^ Whether to perform the TCP peer address consistency.
4245
-> IO NT.Transport
43-
createTransportTCP logTrace connectionTimeout addrInfo = do
46+
createTransportTCP logTrace connectionTimeout addrInfo checkPeerHost = do
47+
unless checkPeerHost $ do
48+
traceWith logTrace "DANGER: peer host address check disabled! Node is vulnerable to DoS attacks."
4449
let tcpParams =
4550
(TCP.defaultTCPParameters
4651
{ TCP.transportConnectTimeout =
@@ -49,7 +54,7 @@ createTransportTCP logTrace connectionTimeout addrInfo = do
4954
-- Will check the peer's claimed host against the observed host
5055
-- when new connections are made. This prevents an easy denial
5156
-- of service attack.
52-
, TCP.tcpCheckPeerHost = True
57+
, TCP.tcpCheckPeerHost = checkPeerHost
5358
, TCP.tcpServerExceptionHandler = \e ->
5459
traceWith logTrace (sformat ("Exception in tcp server: " % shown) e)
5560
})

infra/src/Pos/Infra/Network/CLI.hs

+11
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,10 @@ data NetworkConfigOpts = NetworkConfigOpts
7878
-- address.
7979
, ncoExternalAddress :: !(Maybe NetworkAddress)
8080
-- ^ A node must be addressable on the network.
81+
, ncoCheckPeerHost :: !Bool
82+
-- ^ Whether to perform the peer host address consistency check.
83+
-- The check is necessary to avoid easy denial-of-service attacks,
84+
-- but can be restrictive in certain scenarios.
8185
} deriving (Show)
8286

8387
----------------------------------------------------------------------------
@@ -123,6 +127,12 @@ networkConfigOption = do
123127
, Opt.metavar "FILEPATH"
124128
, Opt.help "Path to a YAML file containing the network policies"
125129
]
130+
ncoCheckPeerHost <- (not <$>) .
131+
Opt.switch $
132+
mconcat
133+
[ Opt.long "disable-peer-host-check"
134+
, Opt.help "DANGER: disable the peer host address consistency check. Makes your node vulnerable"
135+
]
126136
ncoExternalAddress <- optional $ externalNetworkAddressOption Nothing
127137
ncoBindAddress <- optional $ listenNetworkAddressOption Nothing
128138
pure $ NetworkConfigOpts {..}
@@ -375,6 +385,7 @@ intNetworkConfigOpts logTrace cfg@NetworkConfigOpts{..} = do
375385
, ncDequeuePolicy = dequeuePolicy
376386
, ncFailurePolicy = failurePolicy
377387
, ncTcpAddr = tcpAddr
388+
, ncCheckPeerHost = ncoCheckPeerHost
378389
}
379390

380391
pure networkConfig

infra/src/Pos/Infra/Network/Types.hs

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ data NetworkConfig kademlia = NetworkConfig
109109
, ncTcpAddr :: !TCP.TCPAddr
110110
-- ^ External TCP address of the node.
111111
-- It encapsulates both bind address and address visible to other nodes.
112+
, ncCheckPeerHost :: !Bool
113+
-- ^ Whether to perform the peer host address consistency check.
114+
-- The check is necessary to avoid easy denial-of-service attacks,
115+
-- but can be restrictive in certain scenarios.
112116
}
113117

114118
instance Show kademlia => Show (NetworkConfig kademlia) where

lib/src/Pos/Diffusion/Full.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ diffusionLayerFull fdconf networkConfig mEkgNodeMetrics mkLogic k = do
149149
logTrace :: Trace IO Text
150150
logTrace = contramap ((,) Error) $ named $
151151
appendName "transport" (fdcTrace fdconf)
152-
bracketTransportTCP logTrace (fdcConvEstablishTimeout fdconf) (ncTcpAddr networkConfig) $ \transport -> do
152+
bracketTransportTCP logTrace (fdcConvEstablishTimeout fdconf) (ncTcpAddr networkConfig) (ncCheckPeerHost networkConfig) $ \transport -> do
153153
rec (fullDiffusion, internals) <-
154154
diffusionLayerFullExposeInternals fdconf
155155
transport

0 commit comments

Comments
 (0)