@@ -21,26 +21,31 @@ import Pos.Util.Trace (Trace, traceWith)
21
21
-- - Given connection timeout in us
22
22
-- - Given address (possibly unaddressable)
23
23
-- - 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
25
26
-- - Do not crash the server if 'accept' fails; instead, use the given
26
27
-- 'Trace' to log the reason and continue trying to accept new connections
27
28
bracketTransportTCP
28
29
:: Trace IO Text
29
30
-> Microsecond
30
31
-> TCP. TCPAddr
32
+ -> Bool
31
33
-> (NT. Transport -> IO a )
32
34
-> 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 )
35
37
NT. closeTransport
36
38
k
37
39
38
40
createTransportTCP
39
41
:: Trace IO Text -- ^ Whenever there's an error accepting a new connection.
40
42
-> Microsecond -- ^ Connection timeout
41
43
-> TCP. TCPAddr
44
+ -> Bool -- ^ Whether to perform the TCP peer address consistency.
42
45
-> 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."
44
49
let tcpParams =
45
50
(TCP. defaultTCPParameters
46
51
{ TCP. transportConnectTimeout =
@@ -49,7 +54,7 @@ createTransportTCP logTrace connectionTimeout addrInfo = do
49
54
-- Will check the peer's claimed host against the observed host
50
55
-- when new connections are made. This prevents an easy denial
51
56
-- of service attack.
52
- , TCP. tcpCheckPeerHost = True
57
+ , TCP. tcpCheckPeerHost = checkPeerHost
53
58
, TCP. tcpServerExceptionHandler = \ e ->
54
59
traceWith logTrace (sformat (" Exception in tcp server: " % shown) e)
55
60
})
0 commit comments