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:
@@ -27,6 +27,11 @@ var packets: Array[Dictionary] = []
|
||||
var max_packets_per_poll: int = 32
|
||||
## Malformed or unexpected packets dropped so far.
|
||||
var bad_packets: int = 0
|
||||
## New connections allowed from one address per window. Generous enough for a LAN
|
||||
## party behind one router joining at once; a flood from one address is turned away.
|
||||
var connect_limiter: SourceLimiter = SourceLimiter.new(32, 10000, 4096)
|
||||
## Connections from one address still in the handshake at once.
|
||||
var max_guests_per_address: int = 8
|
||||
|
||||
var _host: ENetConnection = null
|
||||
## Peers that haven't finished the handshake: ENetPacketPeer -> msec they connected.
|
||||
@@ -103,6 +108,10 @@ func poll(now_msec: int = -1) -> void:
|
||||
match kind:
|
||||
ENetConnection.EVENT_CONNECT:
|
||||
peer.set_timeout(0, peer_timeout_min_msec, peer_timeout_max_msec)
|
||||
var address: String = peer.get_remote_address()
|
||||
if not connect_limiter.allow(address, now) or _guests_from(address) >= max_guests_per_address:
|
||||
_refuse(peer, NetProtocol.REASON_BUSY)
|
||||
continue
|
||||
_guests[peer] = now
|
||||
ENetConnection.EVENT_DISCONNECT:
|
||||
_gone(peer, int(event[2]))
|
||||
@@ -209,6 +218,14 @@ func _gone(peer: ENetPacketPeer, data: int) -> void:
|
||||
_handle_of.erase(peer)
|
||||
|
||||
|
||||
func _guests_from(address: String) -> int:
|
||||
var count: int = 0
|
||||
for peer: ENetPacketPeer in _guests:
|
||||
if peer.get_remote_address() == address:
|
||||
count += 1
|
||||
return count
|
||||
|
||||
|
||||
## `wanted`, or `wanted` with a number after it if someone here already has that name.
|
||||
func _unique_name(wanted: String) -> String:
|
||||
var taken: Dictionary = {}
|
||||
|
||||
Reference in New Issue
Block a user