Skip to content

Minimal rate-limiting on create-user / create-room - #28

Merged
valeboth merged 1 commit into
mainfrom
feat/rate-limit
Aug 26, 2026
Merged

Minimal rate-limiting on create-user / create-room#28
valeboth merged 1 commit into
mainfrom
feat/rate-limit

Conversation

@valeboth

Copy link
Copy Markdown
Owner

The app is public, so casual spam could pile up rows in D1. Adds a fixed-window KV rate limiter (per client IP) on the two write endpoints:

  • POST /api/users → 20/min/IP
  • POST /api/rooms → 30/min/IP
  • over the limit → 429

Best-effort: fails open on a KV hiccup (never blocks real users), and stops writing once over the limit so KV writes stay bounded. For serious abuse, Cloudflare WAF rate-limiting rules are the proper next step.

Tested local: the 21st create-user within a minute returns 429 (20×201 then 429). lint/typecheck/build ✅. health → v3.6.

- lib/ratelimit.ts: fixed-window KV limiter (per-IP, fails open on KV errors; no write
  once over the limit so writes stay bounded)
- POST /api/users -> 20/min/IP, POST /api/rooms -> 30/min/IP; over limit -> 429
- health -> v3.6

Tested local: 21st user-create in a minute returns 429.
@valeboth
valeboth merged commit d7db8ea into main Aug 26, 2026
1 check passed
@valeboth
valeboth deleted the feat/rate-limit branch August 28, 2026 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant