Authentication and session review
Goal
Find the flaws in how users prove who they are and stay logged in.
A good review follows each credential from creation to expiry and checks every state change.
When to use
- The app has custom login, sessions, API tokens or reset flows.
- The user uses JWTs and is unsure about validation or storage.
- Before adding single sign-on or multi-factor.
- For how passwords are stored, use
use_skillwithpassword-storage-review.
Steps
- Map the auth code with
exploreorrgforlogin,session,jwt,cookie,token,reset,verifyand middleware names. Read each file withread_file. - Check login: generic error messages for bad user or bad password, rate limiting or lockout per account and per address, and constant-time comparison where secrets are compared.
- Check session identifiers: generated by a cryptographic random source, long enough, and replaced at login to prevent fixation.
- Check cookies:
HttpOnly,Secure, a suitableSameSite, a narrowPathand domain, and no sensitive data stored inside. - Check expiry: idle timeout and absolute lifetime, and that logout destroys the session on the server and does more than clear the browser cookie.
- For JWTs check that the algorithm is fixed on the server (never taken from the token),
exp,audandissare validated, keys are strong, and tokens are short lived with a rotation scheme for refresh. - Check where tokens live in the browser and the risk of that choice against XSS and CSRF. State state-changing requests need CSRF protection when cookies carry the session.
- Check password reset: single use random tokens, short expiry, stored hashed, invalidated after use, and no account existence leak in the response.
- Check multi-factor and recovery paths: the recovery route must not bypass the second factor.
- Check privilege changes: sessions are invalidated after password change, role change or account disable.
- Check API keys and service tokens: scoped, revocable and not logged.
- Rank findings with the file, line, attack scenario and the fix.
Gotchas
- JWTs cannot be revoked by default. A stolen one works until it expires, so lifetime and a deny list matter.
- Accepting
alg: noneor letting the token pick the algorithm are classic validation holes. Pin it. - Login that says which of user or password was wrong, or reset that says the email is unknown, enables account enumeration.
- Rate limiting by address alone fails behind shared proxies, and by account alone allows lockout of victims. Combine and check the real client address source.
SameSite=Laxdoes not make every state change safe. Verify routes that change data accept only POST and check an anti-forgery token.- Timing differences between known and unknown users also leak existence.
Output
- Findings ranked by severity with location, how it could be abused, and a fix.
- A list of controls that are correct, so the owner knows what to keep.
- Parts not reviewed, such as an external identity provider.
