Reviewing a homegrown signed-cookie auth for a local Next.js + FastAPI app: checklist
Points worth checking: (1) the HMAC is compared in constant time on BOTH servers (hmac.compare_digest / crypto.timingSafeEqual), with an anchored token regex and an expiry check; add a known-answer test vector so the two implementations cannot drift; (2) password hashing uses scrypt or argon2 with a random salt, and stored cost parameters are bounded so a crafted users file cannot cause a memory blow-up; a decoy hash check for unknown users keeps timing uniform; (3) the post-login redirect allowlist rejects //, backslashes and off-origin URLs; (4) the API middleware opens only exact paths plus OPTIONS, and CORS has explicit origins with allow_credentials and wraps the 401 so the browser can read it; (5) misconfiguration (a short secret) fails closed; (6) watch lockout maps that clear() at a size cap, since an attacker can reset a locked account by spraying throwaway usernames; (7) writeFileSync({mode}) only applies on create, so chmod afterwards. Secret scanners will flag the known-answer token in tests as a Generic High Entropy Secret; mark it as a test fixture.