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:
2026-11-14 02:36:36 -05:00
co-authored by Claude Opus 5.5
parent e3c0d2814c
commit 9b5064d7a8
14 changed files with 515 additions and 23 deletions
+31
View File
@@ -103,3 +103,34 @@ func test_bad_bytes_are_refused_without_errors() -> void:
var short: PackedByteArray = good.duplicate()
short.encode_u32(8 + head_size, CommandLog.RECORD_SIZE * 40)
assert_null(CommandLog.from_bytes(short))
## H5: a header whose fields are the wrong kind of JSON is refused, never an error.
func test_a_header_with_the_wrong_types_is_refused_without_errors() -> void:
var good: PackedByteArray = _log().to_bytes()
var head_size: int = good.decode_u32(4)
var head: Dictionary = JSON.parse_string(good.slice(8, 8 + head_size).get_string_from_utf8())
var records: PackedByteArray = good.slice(8 + head_size)
var bad_rule: Dictionary = head.duplicate(true)
bad_rule["rules"]["max_players"] = [1, 2]
var bad_winner: Dictionary = head.duplicate(true)
bad_winner["winners"] = [{"x": 1}]
var bad_tick: Dictionary = head.duplicate(true)
bad_tick["final_tick"] = {"x": 1}
for changed: Dictionary in [bad_rule, bad_winner]:
assert_null(CommandLog.from_bytes(_with_head(changed, records)))
var read: CommandLog = CommandLog.from_bytes(_with_head(bad_tick, records))
assert_not_null(read, "a bad final tick alone still leaves a usable log")
assert_eq(read.final_tick, 0)
assert_eq(read.count(), 3)
func _with_head(head: Dictionary, records: PackedByteArray) -> PackedByteArray:
var text: PackedByteArray = JSON.stringify(head).to_utf8_buffer()
var out: StreamPeerBuffer = StreamPeerBuffer.new()
out.big_endian = false
out.put_data(CommandLog.MAGIC.to_ascii_buffer())
out.put_u32(text.size())
out.put_data(text)
out.put_data(records)
return out.data_array