Our paywall was bypassable in 30 seconds. Here is how we fixed it
Our paywall was bypassable in 30 seconds. Here's how we fixed it. Postmortems are more useful than success stories, so here's ours. Interactive Stories is a mobile app where an LLM writes the plot in real time. Every ge
Our paywall was bypassable in 30 seconds. Here's how we fixed it.
Postmortems are more useful than success stories, so here's ours. Interactive Stories is a mobile app where an LLM writes the plot in real time. Every generation costs us real money — inference isn't free — so after 12 free generations per story, the player unlocks the rest with a one-time purchase.
The original design (embarrassing)
The client counted generations. Let me repeat that: the client counted generations. The app sent choiceCount in the request body, and the server compared it against the free allowance. The payload that cost us money looked like this:
POST /generate-story
{ "storyId": "...", "choiceCount": 1, "prompt": "...", "len": ... }
If you've been doing this for a while you're already wincing. choiceCount: 1 — forever. Any motivated user with a proxy could play the entire game free, indefinitely. Worse: prompt and len also came from the client, so the endpoint was effectively a free LLM proxy for anyone who found it.
In our defense: this is a common indie trap. You build the happy path first, and the happy path doesn't include adversaries.
The fix
The server now computes everything that matters:
-
Usage is counted server-side. A
generation_usagetable tracks per-user per-story counts. The client's count is ignored entirely — it's not even read. -
Content parameters come from the database.
promptand generation length are looked up bystoryIdserver-side. The client can't inject them. - Unknown or malformed story IDs are rejected. No more open proxy.
- Existing players were migrated — their historical counts were backfilled so nobody lost progress they'd honestly earned.
Verification
We tested the actual exploit path after deploying: replaying the exact request shape that used to bypass the paywall now returns 402 story_purchase_required on the 13th generation, regardless of what choiceCount says. Purchases still resolve correctly and meter against the real count.
Lessons
- The client is adversarial input. Anything the client sends about money, metering or entitlement is a hint at most, never a fact.
- Meter cost-bearing operations server-side from day one. Retrofitting is migrating live user data under pressure.
- "Nobody will bother" is not a threat model. If an endpoint proxies paid inference, somebody will bother.
The app is on RuStore if you're curious: https://www.rustore.ru/catalog/app/com.SpeedOfLightGames.AIbook
Happy to answer questions about the migration path in the comments.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.