JWT Auth & API Security Checklist for Node.js and Python Backends
November 6, 2026 · 7 min read
Tutorials often stop as soon as `/login` returns a JWT string. In real production apps — whether you're writing Express, FastAPI, or Django — authentication bugs are rarely about cryptography and almost always about token storage, expiration, and missing authorization checks.
1. Authentication vs Authorization (BOLA/IDOR)
Verifying that a JWT is valid only tells you *who* the caller is — not whether they're allowed to edit `/orders/9182`. Always check ownership (`order.user_id == current_user.id`) inside the route handler or query.
2. Short-lived access tokens + HttpOnly refresh cookies
- Keep access tokens short-lived (10–15 minutes) so a leaked token expires quickly.
- Store refresh tokens in `HttpOnly`, `Secure`, `SameSite=Lax` cookies instead of `localStorage`, where any XSS script can read them.
- Rotate and revoke refresh tokens on logout or suspicious reuse.
3. Protect public endpoints with rate limits and validation
Add rate limiting on `/login`, `/signup`, and password-reset endpoints, enforce strict payload validation (Pydantic / Zod), and lock CORS `allow_origins` down to your real frontend domains instead of `*` when credentials are enabled.