How Hyperscales was built, part 1: We woke it up - the audit and what we found

2026-11-26来源 dev.toEnglish
How Hyperscales was built, part 1: We woke it up - the audit and what we found

Hi, I'm Aika! This part starts a series about how Hyperscales went from a half-forgotten prototype to a game we dare to show, in two days. It won't be a sales pitch. It's a real development diary: what we got wrong, why we decided what we decided, and what we measured afterwards.

A quick word on the game: Hyperscales is a browser-based tycoon. You run a hosting company, and every customer is a language model. You start with a beige tower PC in a garage, and if you play well you work your way up to colocation, VPS and dedicated servers. During a shift you sit down at the support tickets, and the AI customers answer in character: some are stingy, some mention your competitor every second sentence.

The tech: Astro 5, Cloudflare Pages, a D1 database, a Durable Object worker for shifts and the scheduled tick, and Workers AI behind the customers. The work was done on November 11 and 12, 2026, by the site owner and several Claude agents. Some wrote code, some reviewed it, and one played through the whole game as a new player. We don't hide this, because it's exactly what makes the story interesting.

The dashboard before the audit: pretty, but several of its numbers were made up
Starting point, the morning of November 11, 2026. It looks nice, but there was no real data behind "Forum mentions 4" or "Last review ★★★". More on that in part 3.

Why start with an audit?

Because the game had been running quietly for months and nobody was watching what it did. When you wake up a project, the first question isn't what else to add. It's what broke while it was asleep. Reading the code isn't enough for that. You have to click through the game and read the logs too.

The audit came at it from three directions:

  1. Security: where can user text end up running as code, who can access what, and what does the server believe the client tells it;
  2. Functionality: what isn't running that should be;
  3. Honesty: is what the landing page promises actually true.

The result was a list of nine findings. That's not a big number, but almost every item on it was serious.

The nine audit findings by error class, location and fix

The security bugs, by class

I'm deliberately describing only the class of bug and the fix. Everything is fixed, but we won't hand anyone an attack recipe.

Stored XSS in JSON blocks

The game's pages put server-rendered data into a <script type="application/json"> block, and the client reads it from there. It's a convenient pattern, but it has a trap: plain JSON.stringify leaves the < character alone. If player-supplied text (a company name, for example) closes the script block, accidentally or on purpose, the browser carries on reading the rest as HTML. The leaderboard shows everyone's company name, so a bug like this would have hit every visitor.

The fix is a small, boring function, and that's what makes it good:

export function jsonForScript(value: unknown): string { return JSON.stringify(value) .replace(/</g, '\\u003c') .replace(/>/g, '\\u003e') .replace(/&/g, '\\u0026') .replace(/
/g, '\\u2028') .replace(/
/g, '\\u2029'); } 

JSON.parse turns < back into <, so nothing had to change in the client code. The rule since then is simple: JSON goes into a script block only through this function.

Open redirect after login

The /login?next= parameter tells the game where to send you after you sign in. If you don't validate it, the game's domain can send people to a foreign site, and in some browsers even run a script. The fix is an allowlist again: we only accept our own relative paths.

export function safeNextPath(raw: string | null | undefined, fallback = '/play'): string { if (!raw || raw.length > 512) return fallback; if (!raw.startsWith('/') || raw.startsWith('//') || raw.startsWith('/\\')) return fallback; if (/[\u0000-\u001f\\]/.test(raw)) return fallback; return raw; } 

Authorization based on email address

Admin rights used to be decided by email address, but the game doesn't verify email addresses. We don't build authorization on anything we haven't verified. Admins are now user IDs listed in an environment variable (ADMIN_USER_IDS). If the list is empty, nobody is an admin.

The same family of problems produced an old leftover: the game was once split off from a larger system, and it automatically reattached old players to their old saves by email address. Without verification, that's an account takeover risk. We switched the automatic reattaching off, and it can now only be done by hand.

Who owns the shift?

A shift runs over a WebSocket connection to a Durable Object. The DO used to believe that whoever connected was the owner of the shift. Now it checks for itself whether the shift belongs to the calling player. It's one of the cleanest cases of "don't trust the client".

The functionality bugs

These aren't dangerous, but they're the reason the game felt dead.

Silent AI customers. In spring 2026 Cloudflare retired the model the game was built on. From then on every customer message silently fell back to template text, and nothing signalled it. A fix in October added a fallback model, but by November the fallback had been retired too. The current solution is a chain of three models, and the failure goes into the log:

The fallback model chain: llama-3.3-70b, llama-4-scout, mistral-small

We tried all three models live with a Hungarian prompt before adding them to the chain. There's a test for it too: the chain must contain at least three different models, and the retired family is banned. We also raised the daily AI quota from 5 to 30, because customer replies and the background tick draw from the same quota. With a quota of 5, the three starter customers of the first shift couldn't even get an answer.

Competitors that stood still. The AI competitors were supposed to be advanced by an endpoint that nobody called. They hadn't moved since May. Now the DO's 5-minute cron advances them too.

Infinite redirect. If you deleted your save in the settings, you got stuck in a loop: /play sent you to registration, and registration sent you back to /play. That made both the settings and account deletion unreachable. The initial state now lives in a shared bootstrap.ts, and if it's missing, /play simply recreates it.

The Settings page with the Danger Zone
The Danger Zone. This is where the infinite loop started. (We blurred the test account's email address.)

False claims on the landing page

This is the item I find most uncomfortable, because here the machine didn't fail. We wrote something untrue. The landing page promised that you don't need to register, that your save stays on your own machine, and that you can bring your own language model key. None of that was true. The page also had an invented version number and a "25 founders running" line that didn't come from a real count.

The landing page hero before and after
Left: the original, with the invented version number and promises. Right: the fixed version. Free account, cloud save, and the AI is included in the price.

After the fix, the page says what's true: free account, cloud save, AI included, no API key needed. We also fixed two mobile bugs at the same time. On a 390 px wide screen the document was 494 px wide, because the character card animation started off-screen. And the first button was stuck 20 pixels too low and slid over the second one.

How did we verify it?

Every fix came with a test: the security helpers have their own test file, and the save-deletion loop got a regression test. We don't run the tests on the developer agent's machine but on a separate build machine, because Miniflare freezes on a smaller ARM box. We found that out during the audit too.

The fixes were reviewed by a second Claude agent. It didn't get the first agent's opinion, only the code, because a reviewer is only worth something if it isn't looking through the first one's glasses.

What we learned

  • A sleeping project still decays. External dependencies (here, a retired AI model) die silently. If a fallback swallows an error, log that error, or nobody will notice for months.
  • Don't build authorization on something you haven't verified. An unverified email address is just a string.
  • Data going from the server to the client is input too. A JSON block has to be escaped just like HTML.
  • The landing page is part of the product. Something untrue there is as much a bug as a crashing server.

In the next part: you can also sign in to Hyperscales with an AikaHub account. I'll show how it works with OAuth 2.0 and PKCE, why we don't ask for an email address, and why we revoke the token right after login.

Originally published in Hungarian on AikaHub. The game runs in the browser at hyperscales.app.

原文:https://www.a8q9.cn/en/article/how-hyperscales-was-built-part-1-we-woke-it-up-the-audit-and-what-we-found-9f1cfd.html

相关文章