Files
tidewall/test/net/test_source_limiter.gd
T
claudeandClaude Opus 5.5 9b5064d7a8 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>
2026-11-14 02:36:36 -05:00

36 lines
1.8 KiB
GDScript

extends TestCase
## H5: the rate limiter counts sources, and an IPv6 sender counts with its whole /64.
func test_sources_group_ipv6_by_its_64_and_keep_ipv4_whole() -> void:
assert_eq(SourceLimiter.source_of("192.0.2.7"), "192.0.2.7")
assert_eq(SourceLimiter.source_of("::ffff:192.0.2.7"), "192.0.2.7", "IPv4-mapped counts as the IPv4 address")
assert_eq(SourceLimiter.source_of("2001:db8:0:1::5"), "2001:db8:0:1::/64")
assert_eq(SourceLimiter.source_of("2001:0DB8:0000:0001:ffff:1:2:3"), "2001:db8:0:1::/64")
assert_eq(SourceLimiter.source_of("2001:db8::1"), "2001:db8:0:0::/64")
assert_eq(SourceLimiter.source_of("::1"), "0:0:0:0::/64")
assert_eq(SourceLimiter.source_of("fe80::1%eth0"), "fe80:0:0:0::/64")
assert_eq(SourceLimiter.source_of("2001:db8:1:2:3:4:192.0.2.1"), "2001:db8:1:2::/64")
assert_ne(SourceLimiter.source_of("2001:db8:0:1::5"), SourceLimiter.source_of("2001:db8:0:2::5"))
# Not an address: left as it is, never an error.
for odd: String in ["", "x", "1:2:3", "1::2::3", "zzzz::1", "12345::1"]:
assert_eq(SourceLimiter.source_of(odd), odd)
func test_one_ipv6_64_shares_one_allowance() -> void:
var limiter: SourceLimiter = SourceLimiter.new(3, 1000, 16)
for index: int in 3:
assert_true(limiter.allow("2001:db8:0:1::%x" % (index + 1), 0))
assert_false(limiter.allow("2001:db8:0:1::ffff", 0), "a fourth address in the same /64 is over the limit")
assert_true(limiter.allow("2001:db8:0:2::1", 0), "the next /64 has its own allowance")
assert_eq(limiter.tracked(), 2)
func test_rotating_addresses_in_one_64_cannot_fill_the_table() -> void:
var limiter: SourceLimiter = SourceLimiter.new(1000000, 1000, 4)
for index: int in 5000:
limiter.allow("2001:db8:0:1:%x::1" % index, 0)
assert_eq(limiter.tracked(), 1)
assert_true(limiter.allow("192.0.2.1", 0), "others are still let in")