Anti-abuse for a solo-dev browser game leaderboard: stopping floods without storing IP addresses
Doodle Stack, our drawing-and-stacking browser game, has global leaderboards and ranked matches with strangers. Both launched on October 19, 2026, and on October 22 we added a round of anti-abuse measures.
This is a record of what we thought about, and what we put where. It's for solo developers who want leaderboards or online play in a small browser game without logins. The leaderboard and matchmaking server is only Cloudflare Pages Functions and D1 (SQLite); we run no dedicated server. (Direct device-to-device play uses PeerJS's public server.)
So as not to help abusers, we don't list actual limits, the blocked words, or detailed ban criteria. Only the thinking and where we got stuck.
The setup
As of October 23, 2026:
| Thing | Details |
|---|---|
| Global leaderboards | Solo records. Per difficulty: pieces stacked or height, this week or all time, plus a board for the Daily Challenge |
| Ranked matches | The server pairs players with similar ratings, then the two devices connect directly. Wins and losses move the rating |
| Identifying players | No login. A random per-device ID saved in the browser, with one best record per ID on the board |
| Versions | Separate boards for the Japanese version and the English version on CrazyGames. Both call the same API |
What prompted the review: the English version went live on CrazyGames, and records started arriving from strangers abroad. We build this site with AI (Claude), and this review and the fixes were done with Claude too.
First decision: we can't stop everything
A browser game's score is just a value the browser sends. The sending side is in the player's hands, so a determined attacker can't be fully stopped. Trying to stop everything leads to logins and heavy verification, too much for a small game. We narrowed it to four goals:
- Make abuse more work: holding down a button or running a script shouldn't be enough
- If it gets abused, we can clean up fast: have review and ban tools ready
- Don't get in normal players' way: set limits where normal play basically never reaches them
- Don't hold personal data: don't store IP addresses
Then we put something at each layer, from intake to display:
| Layer | What we added |
|---|---|
| Intake | Don't read oversized bodies, refuse impossible records, refuse values outside fixed options |
| Names | Blocked words (matching built to resist evasion), no URLs, 10 characters max |
| Counts | Per-IP flood limits and per-device daily limits |
| Operations | A ban table, plus tools for reviewing and banning |
| Display | Short leaderboard cache, device IDs never in any response |
| Matches | "Couldn't connect" reports, a daily cap on decided matches, opponent names and prompts only from the server or the fixed list |
Below, roughly in order of how much trouble each caused.
Stopping floods without storing IP addresses
Store only a "blurred" value and a count
To stop floods, we only need to know that many requests came from the same place in a short time. We don't need the IP itself. So we mix the IP with a secret only the server knows, then hash it into something irreversible.
One mistake here. There are only about 4.3 billion IPv4 addresses. If the secret is known, you can try them all and recover the address. The design kept the secret out of the code, in a production secret setting, but the review found the setting was missing, and it was running on a fixed fallback value in the code. On October 22 we set the production secret; nobody has seen its value. "Works even without the setting" is convenient, and it's also why nobody noticed the setting was missing.
Count per time window
Counts live in a small dedicated table. The key joins what's being counted, the blurred value (or device ID), and a window number: the current time divided by one hour (or one day). When the window changes, the key changes, so counting starts from 0 naturally. Rows from finished windows are deleted in bulk on the next count.
// counter key = kind | blurred IP | time-window number
key = 'post|' + blurredIp + '|' + Math.floor(now / ONE_HOUR)
// 1. Read first. If at the limit, refuse without writing anything
if (count(key) >= LIMIT) return 429
// 2. Otherwise add 1, again only "while below the limit"
// (if two requests both pass step 1 at once, the limit still holds)
INSERT ... ON CONFLICT(key) DO UPDATE SET n = n + 1 WHERE n < LIMIT The key point: at the limit, write nothing. If refused requests still wrote counts or records, the flood itself would load the database. A test checks that a request over the limit increases neither the count nor the records.
Two yardsticks: IP and device ID
We count per blurred IP per hour, and per device ID per day. Clearing browser data changes the device ID, and switching networks changes the IP. Either alone is easy to get around; together they take a lot more effort.
IPv6 needed care. A connection gets a whole block of addresses (usually sharing the first 64 bits) and the device can change the rest freely. Counting full addresses would let someone become "a different person" just by changing the second half. So for IPv6 we count by the first 64 bits only.
Not in the record rows either
The first version (October 19) also wrote the blurred IP into each leaderboard record, for flood counting. But counting only needs the last hour, and keeping it in records keeps it forever.
From October 22, the blurred value lives only in the count table, not in records. Rows written by the earlier version are blanked once they're 2 hours old. What we use and for how long is in our privacy policy.
Blocked words: a contest with evasion
Names on the board go through a blocked-word check. "Refuse if it contains this word" is easy to evade. Evasions we considered:
- Spaces, symbols or zero-width characters between letters
- Mixing full-width and half-width, katakana and hiragana, upper and lower case
- Cyrillic or Greek letters that look like Latin ones
- Writing some letters as digits or symbols (0 for o, and so on)
- Japanese phonetic spellings, or different characters with the same reading
So we keep the stored name unchanged and build normalized forms only for matching:
matchForm = the entered name
-> remove invisible characters (zero-width spaces etc.)
-> remove accents and other marks (keep Japanese voicing marks)
-> map look-alike letters (Cyrillic etc.) to plain Latin letters
-> lowercase, and convert katakana to hiragana
-> remove symbols and spaces
If the name has Latin letters, also make a form with digits/symbols read as letters
If any form contains a blocked word, the name is refused
(the name is stored exactly as entered) Digit-to-letter mapping only applies to names that contain Latin letters, since mapping all-digit names can make plain numbers look like words. Names that leave no letters or digits after normalization (only symbols, emoji or invisible characters) are refused, because they'd be indistinguishable on the board.
The Scunthorpe problem
Substring matching catches ordinary words and names that happen to contain a blocked word. The famous case is the English town whose name contains a vulgar word and got blocked by filters.
To reduce this, we deliberately left out short words that often appear inside normal words. A few bad ones get through, but not being able to use a normal name is worse. Tests also check that names that should pass do pass: Japanese, English, Cyrillic, accented. Some ordinary names still don't pass; if people run into it, we'll add exceptions.
Names containing something shaped like a URL or email address are refused, so the board can't be used for advertising.
Bans and review tools
Without logins, we ban by device ID. The ban table holds the ID, a note and a timestamp. A banned device's records don't appear on any board (this week, all time, Daily Challenge, rating) and new ones aren't saved. It isn't matched in ranked play, and matches involving it aren't decided.
Review and banning use a small Python admin script with six actions: see new records, see top records one by one (not merged per player, to spot suspicious ones), see top ratings, list bans, ban, unban. It runs SQL against production with Cloudflare's official CLI (wrangler). Three things we were careful about:
- Show only the first 8 characters of device IDs. A device ID is a name tag and also a key: knowing it lets you submit as that player. To ban, you give at least 8 characters, and it stops if that doesn't match exactly one player.
- Validate every value before it goes into SQL. That CLI command can't bind parameters safely. So IDs must match a fixed character set and length, options must be one of the fixed set, numbers must be integers, and notes are stripped of control characters, truncated and quote-escaped. Hand-built SQL is risky even in admin tools.
- A dry-run mode. It runs the production SQL against a local SQLite copy first, to avoid breaking the real table with a bad ban query.
Display: caching and never showing IDs
Aggregating on every leaderboard view gets heavy when many people look. So each board's top 20 is kept in the Cloudflare Workers Cache API for 20 seconds. The cache is per data center, so anyone opening the same board within 20 seconds gets it without a query.
The tricky part was marking your own row:
- The board marks your own record.
- But putting the device ID in the cache key would create one cache per person, which defeats the point.
- So the cache key is only the board's conditions (version, difficulty, sort, period), and your row is marked after reading from the cache.
- The cache holds no device IDs, only a blurred marker of each ID, and comparisons use those markers.
Posting a record clears that version and difficulty's cache, so you see yourself right away. On the other hand, a banned record can take up to 20 seconds to disappear, until the cache expires. We accepted that.
Device IDs never appear in any leaderboard response. A test checks every response body for them, every time.
"constructor" caused a 500 error
The review found that sending something like by=constructor to the leaderboard API returned a 500. The table mapping sort names to SQL fragments was a plain JavaScript object.
const ORDER = { count: '...', height: '...' };
ORDER['constructor'] // -> Object's function (looks like it "exists")
Object.hasOwn(ORDER, 'constructor') // -> false (only keys we wrote)
Plain objects also say yes to keys you never wrote, like constructor, so it slipped past the fixed-options check. We now look only at our own keys. The same kind of hole was in the game client: prompts arriving from an opponent's device are now used only if they're really in the game's prompt list, and shown as "?" otherwise.
A hole in ranked play: "couldn't connect"
After the server pairs two players, the devices connect directly. Each device reports its own result.
- If the reports disagree, the match is void (no rating change)
- If only one side reports, after a short wait that report decides it (quitting when you're about to lose counts as a loss)
The review spotted a way to abuse the one-sided rule: after being paired, deliberately don't connect, then report a win. The opponent loses without ever playing.
So the side that couldn't connect now sends a "couldn't connect" report, and if it arrives before the match is decided, the match is void. It's sent when waiting for the opponent times out, when the connection drops before the match starts, or when you press back in the lobby. We also added a timeout for the room creator's side, which had none.
Right after shipping that, we saw the next hole: a loser could send "couldn't connect" after the match and erase the loss. Whether you can connect is clear right after pairing, so the report is now accepted only for a short time after pairing. About 7 minutes passed between committing the anti-abuse changes and committing this fix. A mechanism that closes one hole can open another, so it's worth reviewing again after shipping.
Also in ranked play:
- A cap on matches a device can decide per day; matches beyond it are void
- Opponent names come only from the server's pairing response. In the English version, the opponent's device also sent a CrazyGames username, which hadn't been through our name check. We only show the nickname the server checked.
- Even if an opponent floods half-drawn strokes, we assemble them at most once per frame, so the screen doesn't freeze
Don't break old clients already out there
Update, November 6, 2026: the CrazyGames Basic Launch ended on October 28 without passing, and on October 29 we decided not to submit there again. Since November 4 the English version runs on our own site. We're leaving this section as it was written, as a record of how we handled a build we couldn't re-upload on our own schedule.
This took the most care. The English build on CrazyGames keeps calling the production API with the old client until we upload a new build there. Uploading is a manual step in their dashboard, so it never lines up exactly with a server change, and some players keep an old tab open after that anyway. (Submission details are in our CrazyGames note.) So server changes followed these rules:
- New fields we'd like clients to send are never required (old clients don't send them)
- Fields old clients read are never removed or reshaped
- The normal success response shape doesn't change
For example, when a banned device posts a record, we couldn't be sure how an old client would handle an error. So we don't save it and return a normal "accepted" with no rank. The old client shows "posted" with a rank of "-". At the rate limit, the old client's existing "too many posts" message appears. When ranked play won't match someone, the old client falls back to "can't reach server, play the CPU", so nobody gets stuck.
To test this, we ran the previous version of the game client (from git) in a real browser against the new server code (with local SQLite standing in for the database) and checked it still worked. As of October 22, all passed.
The new tables (bans and counts) are created by the server on first use. No manual SQL step against production means no "shipped the code, forgot the table".
How we test
The server code runs locally without a Cloudflare login. Node.js 24's built-in SQLite (node:sqlite) stands in for D1, there's a stand-in Cache API, and the tests call the API functions directly with a frozen clock. The tests advance the clock, so "one hour later you can post again" and "new day, count starts at 0" take no time to check. Examples of what's tested:
- Refuse at the limit, refused requests add nothing, the next window accepts again
- Simultaneous requests can't exceed the limit
- IPv6 addresses in the same block share a count; different blocks don't
- Blocked names are refused; names that should pass, pass
- Banned devices appear on no board
- No response contains a device ID
- Response shapes stay what old clients expect
As of October 23, 2026, that's 223 checks, all passing. On the client side, browser automation tests (Playwright) check things like opponent names coming from the server and unknown prompts showing "?".
What we learned
- Deciding up front that you can't stop everything clarifies the work. Make abuse more work, clean up fast, don't bother normal players, hold no personal data: with those four, each layer's job became clear.
- You can stop floods without personal data. All we needed was "same place?" and "how many times?". Not the IP itself.
- "Works without the setting" hides failures. The secret was missing and a fixed value was in use. Check that it runs with the intended settings, not just that it runs.
- A fix can be a new hole. Without a time limit, the "couldn't connect" report was a tool for erasing losses.
- If clients are already out there, the server adapts to them. For a game hosted where you can't redeploy instantly, server changes need the most care.
When this was written, the boards were still small and we couldn't show the effect in numbers. When real abuse shows up and we learn which layer stopped it (or didn't), we'll add it here.
Doodle Stack runs in your browser with no sign-up. Post solo records to the leaderboard or play ranked matches with strangers. → Play Doodle Stack
Nandemo Factory is a one-person studio in Japan that makes small browser games, with AI doing most of the work. We only write about things we built and checked ourselves, with the numbers we actually saw. Play the games in English.