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:
2026-11-12 17:49:54 -05:00
co-authored by Claude Opus 5.5
parent f795ee3fa5
commit 9e653f213c
15 changed files with 573 additions and 2 deletions
+37
View File
@@ -0,0 +1,37 @@
## Runs ParserFuzz (test/net/parser_fuzz.gd) over many malformed messages and fails on
## any engine or script error, or if memory grows by more than 16 MiB past warm-up.
##
## tools/godot.sh --script res://tools/fuzz_parsers.gd -- --messages=N --seed=N
##
## `make fuzz` runs 1,000,000. Prints one JSON line; exits 0 when clean, 1 otherwise.
extends SceneTree
const MAX_GROWTH_BYTES: int = 16 * 1024 * 1024
func _init() -> void:
var count: int = 1000000
var fuzz_seed: int = 1
for arg: String in OS.get_cmdline_user_args():
if arg.begins_with("--messages="):
count = arg.get_slice("=", 1).to_int()
elif arg.begins_with("--seed="):
fuzz_seed = arg.get_slice("=", 1).to_int()
var errors: ErrorCounter = ErrorCounter.new()
OS.add_logger(errors)
var started: int = Time.get_ticks_msec()
var fuzz: ParserFuzz = ParserFuzz.new(fuzz_seed)
fuzz.run(count)
var growth: int = fuzz.memory_end - fuzz.memory_start
var ok: bool = errors.count() == 0 and growth <= MAX_GROWTH_BYTES and fuzz.listed() == 0
var report: Dictionary = {
"event": "fuzz", "ok": ok, "messages": fuzz.messages, "seeds": fuzz.seeds.size(),
"accepted": fuzz.accepted, "errors": errors.count(), "memory_growth_bytes": growth,
"memory_peak_bytes": fuzz.memory_peak, "listed": fuzz.listed(), "seed": fuzz_seed,
"wall_ms": Time.get_ticks_msec() - started,
}
if errors.count() > 0:
report["first_error"] = errors.first()
print(JSON.stringify(report))
OS.remove_logger(errors)
quit(0 if ok else 1)