Bash.tv → GitHub → itch.io

Validate game state and stop common cheating in browser multiplayer games. Server authority, message schemas, size limits and safe parsing, rate limits and strike counts, input sequence checks against replays and spam, clamping inputs, movement plausibility, hidden information, signed run tokens and plausible-score checks for leaderboards, cleaning player names and chat, origin checks, secrets,...

Download skill (.zip) Files on GitHub

Multiplayer security

The browser belongs to the player. Anything in it (code, memory, messages, storage) can be read and changed. Security means the server decides what is true, and checks everything a browser sends.

Server authority

Client sends Server does
Inputs (dx, dy, fire) Moves the player with its own rules and speed
“I want to buy X” Checks price, money and stock, then changes state
“I shot at angle a” Checks cooldown and ammo, does the hit check itself (with lag compensation)
Never: positions, damage, scores, “I won”, “I’m host”  

Hidden information (other hands, fog, roles, answers) never goes to a client that shouldn’t see it. Hiding it in the UI is not enough; it’s readable in the browser’s tools.

assets/guard.js

import { schema, rateLimit, sequenceGuard, checkMove, clampStick, cleanName, plausibleScore, parseMessage, strikes } from "./guard.js";
const p = parseMessage(raw, 4096);                       // size before JSON.parse; must be an object
const bad = schema({ t: "str", seq: "int", dx: ["num", -1, 1], dy: ["num", -1, 1], fire: "bool?" })(msg);   // null or a reason
const limit = rateLimit({ rate: 90, burst: 180 }); if (!limit.take(playerId)) drop();
const fresh = sequenceGuard(); if (!fresh(playerId, msg.seq)) drop();          // old, repeated or jumping sequence numbers
const strike = strikes({ limit: 25 }); if (strike(playerId, 2)) socket.close(1008, "bad input");
cleanName("<b>x</b>\u202E") ;  plausibleScore({ score, seconds, maxPerSecond: 50 })

assets/run-token.mjs (leaderboards)

The server signs a token when a run starts; a score is accepted once per token, only from the same player, and only if the time played makes it possible. See leaderboard-system for the full server.

Also

What you can’t fully stop

Aim bots, auto-clickers and modified clients that play “legally” but superhumanly. Limit the damage: server-checked replays for top scores, reports, and statistical flags (accuracy or score rate far above everyone else).

Tested

Node tests: schema (ranges, extra fields, NaN, optional), token-bucket rate limits and refill, sequence guard, speed-hack clamping, stick clamping, name cleaning (HTML, invisible characters, length), plausible scores, size-limited parsing, strikes, run tokens (valid, used twice, forged, wrong player). With real sockets: out-of-range input refused, 150 queued inputs can’t outrun the speed limit, malformed and oversize messages ignored, a 600-message flood disconnected.