N9: Server-side cheat and abuse protection
- A hostile test client crafts INPUT packets byte by byte and sends them through NetGame.take_input() into a real match: extreme axes, the same tick claimed repeatedly, the whole lead window at once, past, far-future and maximum ticks, fire toggled every tick with slot swaps, builds aimed anywhere with junk kinds and materials and no materials, and pickup/drop/select tricks. Speed stays within sprint speed per tick, shots within the weapon's rate, pieces within build reach and paid for, and every item is conserved. - Fix: a command tick beyond the simulation's lead window no longer moves NetGame's dedupe marker, so one bogus far-future tick can't lock out a player's real commands. - Connections are rate-limited per address (32 per 10 s, 8 handshakes in progress) with a new REASON_BUSY and a message for it. - ParserFuzz mutates real messages from a bot match and random bytes and feeds them to every network decoder, the snapshot receiver and the list server. 20,000 per make check; make fuzz runs 1,000,000 (about 40 s): no errors, 2.9 KB of memory growth. - ARCHITECTURE.md: "Trusting nothing from clients". Closes #40 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -300,3 +300,36 @@ func test_two_servers_cannot_share_a_port() -> void:
|
||||
assert_ne(other.listen(server.port(), HOST), OK)
|
||||
assert_false(other.is_listening())
|
||||
assert_true(server.is_listening())
|
||||
|
||||
|
||||
func test_a_burst_of_connections_from_one_address_is_turned_away() -> void:
|
||||
server.connect_limiter = SourceLimiter.new(3, 60000)
|
||||
var burst: Array[NetClient] = []
|
||||
for index: int in 5:
|
||||
burst.append(_client("Wave %d" % index))
|
||||
assert_true(_pump(func() -> bool:
|
||||
var settled: int = 0
|
||||
for client: NetClient in burst:
|
||||
if client.state == NetClient.JOINED or client.state == NetClient.CLOSED:
|
||||
settled += 1
|
||||
return settled == burst.size()))
|
||||
var joined: int = 0
|
||||
for client: NetClient in burst:
|
||||
if client.state == NetClient.JOINED:
|
||||
joined += 1
|
||||
else:
|
||||
assert_eq(client.close_reason, NetProtocol.REASON_BUSY)
|
||||
assert_eq(joined, 3)
|
||||
assert_eq(server.player_count(), 3)
|
||||
assert_true(NetProtocol.reason_text(NetProtocol.REASON_BUSY).begins_with("Too many connections"))
|
||||
|
||||
|
||||
func test_handshakes_held_open_from_one_address_are_capped() -> void:
|
||||
server.max_guests_per_address = 2
|
||||
# Raw peers that connect and never say hello.
|
||||
for _index: int in 4:
|
||||
_raw()
|
||||
assert_true(_pump(func() -> bool: return _events("refused").size() >= 2))
|
||||
assert_eq(server.guest_count(), 2)
|
||||
for event: Dictionary in _events("refused"):
|
||||
assert_eq(event["reason"], NetProtocol.REASON_BUSY)
|
||||
|
||||
Reference in New Issue
Block a user