middleware
Technical notes on web development, DevOps, and AI integration.
4 articles
- 22:12backend
Throttling a Public Feedback Endpoint: Two Buckets and One Cap
A public feedback endpoint needs defenses on two axes: a body size cap before JSON decoding and two per-account rate limit buckets mounted after authentication.
TL;DR: A security review flagged a feedback endpoint accepting unlimited payload sizes and submission frequency. Fixes: cap the body at 32 KiB before JSON decoding, mount two per-user rate limit buckets (one per 10 minutes, five per day) after auth middleware, and return 429 with Retry-After. Also normalize nil query results to empty arrays so clients get the promised JSON contract.
#go#security#rate-limit - 12:58backend
A Deleted User Is an Authentication Failure: 401, Not 500
A cryptographically valid JWT can still name a user who no longer exists. Mapping sql.ErrNoRows to 401 lets the frontend purge the stale session.
TL;DR: A deleted user's JWT kept hitting the API, and since the middleware treated missing rows as a generic DB error, users got stuck in a 500 banner loop instead of being logged out. The fix uses errors.Is(err, sql.ErrNoRows) to return 401, letting the frontend purge the stale session. Tests now pin both paths.
#go#golang#jwt - 18:06frontend
Next.js Mockup Pages Without Login for Client Review
Replace static mockup screenshots with real Next.js routes clients can open without a session, using an explicit public path list in the proxy file.
TL;DR: The blank preview problem came from mockup routes sitting behind auth, but loosening authentication for the whole app was never an option. Next.js's new root-level proxy file exempts mockup routes from authorization via an explicit public paths list and config matcher, leaving authentication untouched. Mockup routes should use fixture data only, and every route gets tested both ways.
#nextjs#middleware#prototyping - 10:44testing
The Guard That Says No and the Migration Road Home
A test-only commit: proving the global guard via httptest, and the migration down path on MySQL 5.7 really goes backward, then comes home.
TL;DR: We finally tested two long-ignored paths: the RequireGlobalBidang guard that should block bidang access and the down migrations that had never run. A table-driven unit test now locks in the guard's behavior, including its intentional fail-open for empty contexts. An integration test migrates down to version 56 and back up, verifying columns disappear and reappear correctly.
#go#testing#mysql