What are some good practices for ensuring logins, session IDs and session content are secure for a website?
- Use a database for sessions.
- Regenerate the session on when the permissions change (e.g., when a user logs in).
- Regenerate the session on every page load (optional).
- Don't expose the session ID in the URL.
- Don't expose any sensitive data to the session.
In addition to VirtuosiMedia's list:
- Use TLS (SSL) across the entire site. Use the HSTS header.
- Use a session cookie, rather than adding a session token to every link-href and form-action.
- Use the
httpOnlyflags on the cookie.
- Use the
- Keep the content of the session minimal. E.g., store only the user-id. If caching is needed, cache in a general caching layer, not the session.
- Cryptographically sign the session cookie with a secret key known only to the server. Include an expiration datetime in the signed data. Check the signature and the expiration at the server on every request.
Expire your session after a reasonable amount of time... Delete the session out of whatever your using as a repository so it can't be re-used...
don't save password or other user information except user id to the session.
Use the Secure attribute for all others cookies
Similar to the above, don't serve advertisements on your site