Files
tidewall/test/net/test_parser_fuzz.gd
claudeandClaude Opus 5.5 9e653f213c 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>
2026-11-12 17:49:54 -05:00

22 lines
1.0 KiB
GDScript

extends TestCase
## Issue N9: malformed messages never crash a parser or make memory grow. This runs a
## short pass on every `make check`; `make fuzz` runs 1,000,000 messages.
func test_malformed_messages_are_refused_without_errors_or_growth() -> void:
var fuzz: ParserFuzz = ParserFuzz.new(2026)
fuzz.collect_seeds()
assert_true(fuzz.seeds.size() > 20, "%d real messages to mutate" % fuzz.seeds.size())
# Every seed is a message some parser takes.
for bytes: PackedByteArray in fuzz.seeds:
var before: int = fuzz.accepted
fuzz.feed(bytes)
assert_eq(fuzz.accepted, before + 1, "a seed of %d bytes, type %d, was refused" % [bytes.size(), bytes[0]])
fuzz.run(20000)
assert_eq(fuzz.messages, 20000 + fuzz.seeds.size())
assert_true(fuzz.accepted > fuzz.seeds.size(), "some mutations still parse, so parsers are reached past the first byte")
assert_eq(fuzz.listed(), 0, "no mutation guessed a list server's token")
var growth: int = fuzz.memory_end - fuzz.memory_start
assert_true(growth < 8 * 1024 * 1024, "memory grew %d bytes" % growth)