0
Challenge · 44Testing, Security & Ship
Security: rate limiting, headers, env
Securityused in ~78% of apps
The fastest way to get your job board taken down isn't a clever exploit — it's a script hitting your login Server Action 10,000 times a minute, or a leaked `DATABASE_URL` that shipped to the browser because someone named it `NEXT_PUBLIC_` by accident. Rate limiting, security headers, and validated env are the unglamorous trio every reviewer checks, and the one most tutorials skip entirely.
Core idea. Server Actions and route handlers are public POST endpoints, so you rate-limit the expensive/abusable ones (auth, mutations) with `@upstash/ratelimit`. You set security headers once in `next.config.ts`. And you validate `process.env` at boot with t3-env + Zod so a missing or mis-prefixed variable fails the build instead of leaking at runtime — anything not prefixed `NEXT_PUBLIC_` never reaches the client bundle.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
.envgit-ignored
Tap a line to toggle its VITE_ prefix. P = public, S = server-only.
app.4f2.jsSHIPPED TO BROWSER · PUBLIC
import.meta.env.VITE_API_BASE_URL // → "https://api.pulse.app"
server (process.env)NEVER SENT TO BROWSER
ANALYTICS_ID // stays here, value hidden from users
DATABASE_URL // stays here, value hidden from users
STRIPE_SECRET_KEY // stays here, value hidden from users
Safe build. Only the public URL/id were prefixed and inlined; the real secrets stayed on the server. The rule: a prefix makes a value public forever, so only ever prefix things you would print on a billboard.
↑ play a little first, then dig in