H5: Security review, and fixes for connection-slot exhaustion
docs/SECURITY_REVIEW.md lists the scope, nine findings and what was done. - High, fixed: a peer that connects and stops answering kept its ENet slot for up to 15 s after being turned away, so one address could fill every slot. Flood refusals now disconnect at once (reason in the disconnect data, which NetClient now honours for REASON_BUSY), peers told to leave get 1 s to acknowledge, and when slots run short the longest-waiting silent guest makes room. - Medium, mitigated: ENet holds half-open slots for spoofed CONNECTs that the script never sees. The host now has 512 slots (NetServer.peer_slots). - Medium, fixed: SourceLimiter, handshakes per source and the list server's per-address cap count an IPv6 /64 as one source. - Low, fixed: CommandLog refuses a header with non-numeric fields instead of raising errors. - tools/godot.sh unsets DISPLAY and WAYLAND_DISPLAY so the engine's error alerts can never reach the host desktop. - A test fixture's 10.0.0.9 is now the documentation address 192.0.2.9. Tests: 4 new handshake tests with real non-acknowledging ENet peers, test_source_limiter (3), a CommandLog type test. make check, make fuzz, make client-check, make discovery-check and make soak-selfcheck pass. Closes #58 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -389,3 +389,97 @@ func test_a_graceful_shutdown_reaches_clients_on_a_lossy_link() -> void:
|
||||
assert_eq(client.close_reason, NetProtocol.REASON_SHUTDOWN, "%s was told the server stopped" % client.player_name)
|
||||
for relay: UdpRelay in relays:
|
||||
relay.close()
|
||||
|
||||
|
||||
## H5: a peer that connects and then never answers again: it doesn't say hello, and
|
||||
## doesn't acknowledge being turned away, so ENet alone would keep its slot for seconds.
|
||||
func _silent(silent: Array[ENetConnection]) -> void:
|
||||
var host: ENetConnection = ENetConnection.new()
|
||||
assert_eq(host.create_host(1, NetProtocol.CHANNEL_COUNT), OK)
|
||||
host.connect_to_host(HOST, server.port(), NetProtocol.CHANNEL_COUNT)
|
||||
silent.append(host)
|
||||
var connected: Array[bool] = [false]
|
||||
_pump(func() -> bool:
|
||||
var event: Array = host.service(0)
|
||||
if event[0] == ENetConnection.EVENT_CONNECT:
|
||||
connected[0] = true
|
||||
return connected[0], 2000)
|
||||
# The acknowledgement goes out on the next service; send it, then never again.
|
||||
host.flush()
|
||||
var before: int = server.guest_count() + _events("refused").size() + server.evicted
|
||||
_pump(func() -> bool: return server.guest_count() + _events("refused").size() + server.evicted > before, 1000)
|
||||
|
||||
|
||||
func _destroy(silent: Array[ENetConnection]) -> void:
|
||||
for host: ENetConnection in silent:
|
||||
host.destroy()
|
||||
|
||||
|
||||
func test_a_flood_from_one_address_cannot_hold_the_slots() -> void:
|
||||
server.close()
|
||||
server.max_players = 2
|
||||
server.peer_slots = 0
|
||||
server.connect_limiter = SourceLimiter.new(3, 60000)
|
||||
server.max_guests_per_address = 3
|
||||
server.handshake_timeout_msec = 60000
|
||||
assert_eq(server.listen(0, HOST), OK)
|
||||
# Ten slots: three silent guests, then peers turned away for flooding.
|
||||
var silent: Array[ENetConnection] = []
|
||||
for _index: int in 9:
|
||||
_silent(silent)
|
||||
assert_eq(server.guest_count(), 3)
|
||||
assert_eq(server.leaving_count(), 0, "peers turned away for flooding don't keep a slot")
|
||||
assert_eq(_events("refused").size(), 6)
|
||||
# The flood has passed; a real player still finds a slot.
|
||||
server.connect_limiter = SourceLimiter.new(32, 10000)
|
||||
server.max_guests_per_address = 8
|
||||
var client: NetClient = _client("After")
|
||||
assert_true(_pump(func() -> bool: return client.state == NetClient.JOINED or client.state == NetClient.CLOSED, 3000))
|
||||
assert_eq(client.state, NetClient.JOINED)
|
||||
_destroy(silent)
|
||||
|
||||
|
||||
func test_silent_guests_make_room_for_a_newcomer() -> void:
|
||||
server.close()
|
||||
server.max_players = 2
|
||||
server.peer_slots = 0
|
||||
server.max_guests_per_address = 64
|
||||
server.handshake_timeout_msec = 60000
|
||||
assert_eq(server.listen(0, HOST), OK)
|
||||
# More silent guests than the ten slots: the oldest make way, one slot stays free.
|
||||
var silent: Array[ENetConnection] = []
|
||||
for _index: int in 12:
|
||||
_silent(silent)
|
||||
assert_true(server.guest_count() <= 9, "a slot is kept free, %d guests" % server.guest_count())
|
||||
assert_true(server.evicted >= 3)
|
||||
var client: NetClient = _client("Newcomer")
|
||||
assert_true(_pump(func() -> bool: return client.state == NetClient.JOINED or client.state == NetClient.CLOSED, 3000))
|
||||
assert_eq(client.state, NetClient.JOINED)
|
||||
assert_eq(server.player_count(), 1)
|
||||
_destroy(silent)
|
||||
|
||||
|
||||
func test_a_peer_that_never_acknowledges_leaving_is_cut_off() -> void:
|
||||
server.close()
|
||||
server.max_players = 2
|
||||
server.handshake_timeout_msec = 100
|
||||
server.leave_grace_msec = 300
|
||||
assert_eq(server.listen(0, HOST), OK)
|
||||
var silent: Array[ENetConnection] = []
|
||||
_silent(silent)
|
||||
assert_true(_pump(func() -> bool: return server.leaving_count() == 1, 2000), "the silent guest was told to go")
|
||||
assert_true(_pump(func() -> bool: return server.leaving_count() == 0, 2000), "and cut off after its grace")
|
||||
assert_eq(server.evicted, 1)
|
||||
_destroy(silent)
|
||||
|
||||
|
||||
## H5: a client turned away for flooding learns why from the disconnect alone.
|
||||
func test_busy_reaches_the_client_without_a_reject_message() -> void:
|
||||
assert_true(NetProtocol.is_server_reason(NetProtocol.REASON_BUSY))
|
||||
assert_false(NetProtocol.is_server_reason(NetProtocol.REASON_NONE))
|
||||
assert_false(NetProtocol.is_server_reason(NetProtocol.REASON_LOST))
|
||||
server.connect_limiter = SourceLimiter.new(1, 60000)
|
||||
var first: NetClient = _client("First")
|
||||
var second: NetClient = _client("Second")
|
||||
assert_true(_pump(func() -> bool: return second.state == NetClient.CLOSED and first.state == NetClient.JOINED))
|
||||
assert_eq(second.close_reason, NetProtocol.REASON_BUSY)
|
||||
|
||||
Reference in New Issue
Block a user