Developer security mini-course

Lesson 2: Secure Authentication and Session Management

Review authentication and session management across login, MFA, recovery and logout. Learn what to verify and practise with a focused developer exercise.

Secure authentication and session management protects the ways a user proves identity and continues using the service. Login, MFA, recovery, token refresh and logout need to work together as one account lifecycle.

Account recovery security deserves the same attention as the primary login. A strong sign-in process can be undermined if a reset link, support workflow or change of email address gives an attacker an easier route.

Learning outcome

You should be able to map the account lifecycle and explain how the service establishes identity, maintains authenticated state and revokes access when required.

Use maintained framework or identity-provider features where appropriate, and review how they are configured and integrated. A reputable component still needs the right trust settings, redirects and application permissions.

Protect credentials and sensitive changes

Use a maintained password-hashing implementation designed for password storage. Support long passwords and suitable breached-password controls, with rate limiting that considers account abuse and denial-of-service consequences.

Choose MFA methods appropriate to the service risk. Plan enrolment, replacement and recovery so an attacker cannot simply register a new factor after obtaining a limited session.

Require suitable reauthentication for sensitive actions, such as changing recovery information or security factors. Notify the user through an appropriate existing channel when important account changes occur.

Define the session lifecycle

EventBehaviour to establish
LoginThe application creates the intended authenticated state and replaces relevant pre-login identifiers.
Privilege changeExisting sessions reflect the new permissions according to the design.
Inactivity or expiryAccess ends at the intended boundary.
LogoutThe relevant server-side session or token arrangement is invalidated as designed.
Account disablementAccess is revoked within the defined lifecycle.
Factor or password changeThe service applies the agreed session review and revocation rules.

For cookie-based sessions, use suitable Secure, HttpOnly and SameSite settings. SameSite needs to fit the login architecture and does not replace all necessary CSRF protection.

For tokens, verify signature or equivalent integrity protection and relevant issuer, audience, expiry and intended use. Explain how revocation and refresh work rather than assuming that deleting a token from the browser ends its validity.

Design recovery deliberately

Use unpredictable, purpose-limited recovery tokens with appropriate expiry and single-use behaviour. Prevent token leakage through logs, analytics, URLs shared with other services or insecure delivery.

Avoid responses that unnecessarily reveal whether an account exists. Apply appropriate abuse controls to recovery requests and test the final state after a token is used.

Review exercise

Using controlled accounts in a test environment:

  1. Log in and record the session transition.
  2. Change a relevant security setting and check the expected reauthentication.
  3. Use a recovery token, then try to reuse it.
  4. Log out and check whether the previous authenticated request still works.
  5. Disable the account and examine existing session or token behaviour.

Record the intended rule before deciding whether the observed behaviour is a defect. Some services use short-lived tokens with a defined revocation delay; the risk and requirements should determine whether that design is acceptable.

Add regression checks for material lifecycle rules and include identity integration changes in future security review.

Read our Testing methodology to discuss coverage, or Book a demo with the systems and objectives you have in mind.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo