Authentication interview question · Most asked

How do you secure session cookies?

Summary

Set HttpOnly (no JavaScript access), Secure (HTTPS only), SameSite=Lax or Strict (limits cross-site sending), a narrow Path/Domain, sensible expiry, and use the __Host- prefix where possible. Regenerate the session ID on login and privilege change.

Longer Answer

Also enforce idle and absolute timeouts server-side, invalidate sessions on logout and password change, and store minimal data in the session. SameSite=None requires Secure and is needed only for legitimate cross-site use.

Key Points

  • HttpOnly, Secure, SameSite
  • __Host- prefix
  • Regenerate ID on login
  • Server-side timeouts and invalidation

More most-asked Authentication questions

← All Authentication questions