1000-ft view: Insecure design is about flawed flows and policies, not just code bugs. This page shows secure designs for five common flows: password reset, sensitive action re-auth, CSRF-resistant settings, one-time magic links, and coupon business rules.
Secure idea: generate a cryptographically random token, store server-side with a short TTL and invalidate on first use. Don’t encode predictable data (email|timestamp) as the token.
Secure idea: require the user’s current password (or WebAuthn) within a recent window (e.g., 5–15 minutes) before high-risk changes like changing email or enabling 2FA.
Secure idea: protect state-changing POSTs with a per-session
CSRF token and SameSite=Lax/Strict cookies. Validate token and origin/referrer.
Secure idea: magic links should be single-use and expire quickly (e.g., 5–10 minutes). Store server-side and invalidate on use.
Secure idea: enforce business rules server-side: coupon applies once per session, minimum subtotal, and a maximum discount cap.