Skip to content

Notes

2 min read

By Le Quoc Khanh

Login and logout: check what happens to the session

A focused review of authentication behavior: session creation, real logout, password recovery, and checks that catch failures beyond the login form.

A login form accepts the right password. Logout returns the user to the home page. Both screens look correct, but neither proves that the old session has stopped working.

Review authentication by following the credential through its lifecycle: creation, use, expiry, and revocation. The most useful checks happen after the happy path.

Create a new authenticated session

For a browser app using server-side sessions, issue a new session identifier after authentication. Reusing the pre-login identifier can expose the application to session fixation. Set an appropriate lifetime and protect the cookie with Secure, HttpOnly, and a deliberate SameSite policy. Cookie authentication also needs CSRF protection; HttpOnly does not provide it. OWASP's session guidance explains these controls.

A changed IP address is a reason to assess context, not proof of a different person. A user can switch from Wi-Fi to mobile data during an ordinary session. Decide when to require fresh authentication based on the action and the risk, rather than silently logging out everyone whose network changes.

Make logout a server decision

With server-side sessions, logout must invalidate the session on the server and expire its browser cookie. Clearing frontend state only changes what the browser displays.

JWTs need an explicit revocation policy. A short-lived access token may remain usable until it expires, even after its refresh token is revoked. Immediate rejection requires a server-side check, such as a denylist or session state checked by the API. OWASP's REST guidance describes this gap between token expiry and session termination.

In a test environment, keep the old credential, log out, then send it to an authenticated endpoint. For immediate logout, that request must be rejected. If the design permits a delay until expiry, document and test that delay instead of calling the token revoked.

Treat recovery as another way into the account

A password reset token needs secure random generation, a limited lifetime, and single-use enforcement. Do not change the account until the token has been validated. Decide how existing sessions are invalidated after recovery. OWASP's recovery guide covers the flow.

Test the same reset link twice, including two requests arriving together. Only one should succeed. An expiry check by itself does not prevent reuse.

Check failure paths deliberately

Use consistent login failure responses to avoid revealing whether an account exists, and rate-limit attempts. CAPTCHA can supplement abuse controls; it is not a requirement to put in front of every user. See OWASP's authentication guidance.

At minimum, exercise a wrong password, an expired session, a reused reset token, and a revoked credential. Check what the API accepts as well as what the UI displays. An authentication library can supply much of the machinery, but the application still has to enforce its own session and access rules.

Share

Comments (0)