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:
@@ -177,6 +177,36 @@ during results, becomes a watcher (`Match.watch()`): they spectate a living play
|
||||
and take a place ahead of any bots when the next lobby opens. The server still turns
|
||||
people away when `NetServer.max_players` people are connected.
|
||||
|
||||
## Trusting nothing from clients
|
||||
|
||||
Tidewall is open source, so anyone can build a client that sends whatever bytes it
|
||||
likes. The server's defences, and the tests that attack them
|
||||
(`test/server/test_hostile_client.gd`, `test/net/test_net_handshake.gd`,
|
||||
`test/net/test_parser_fuzz.gd`, `make fuzz`):
|
||||
|
||||
- **Intent only.** A command carries movement axes, look, buttons, a slot, a
|
||||
material and a view lag. There is no position, velocity, hit, target or item in
|
||||
it, so speed, teleport, aimbot-by-claim and duplication can't even be expressed.
|
||||
Every field is clamped on decode, and the simulation applies its own limits:
|
||||
sprint speed, the weapon's fire interval, build reach (`Tuning.BUILD_RANGE`) and
|
||||
material cost, pickup reach, one pickup or drop per press, lag compensation at
|
||||
most `Tuning.LAG_COMPENSATION_MAX_TICKS`.
|
||||
- **One command per tick.** Each tick's command is taken once, the first time it
|
||||
arrives. A tick already past or more than `Tuning.MAX_COMMAND_LEAD_TICKS` ahead is
|
||||
ignored, and a far-future tick can't move the dedupe marker and lock out the real
|
||||
ones.
|
||||
- **Bounded messages.** An INPUT has at most `NetSnapshot.MAX_INPUT_COMMANDS`
|
||||
commands and an exact length, or it is dropped whole. At most 32 game packets per
|
||||
player are kept per poll. Anything on the control channel after the handshake is
|
||||
dropped.
|
||||
- **Bounded connections.** At most 32 new connections per address per 10 s and 8
|
||||
handshakes in progress per address (`REASON_BUSY`), a 5 s handshake timeout, and
|
||||
ENet's own peer limit.
|
||||
- **Parsers.** Every decoder refuses malformed input by returning an empty result,
|
||||
never by raising an error. `make fuzz` feeds 1,000,000 mutated and random messages
|
||||
to all of them, the snapshot receiver and the list server, and checks for engine
|
||||
errors and memory growth.
|
||||
|
||||
## Snapshot format
|
||||
|
||||
`NetSnapshot` (`src/net/`) owns the layouts. An entity travels as a **record**: a list
|
||||
|
||||
Reference in New Issue
Block a user