Insecure Persistent Login Token

The 'remember me' cookie that keeps users signed in is built from guessable or recoverable values, lasts too long or is never revoked, so a stolen or forged token gives lasting access.

SeverityMedium
CVSS 3.16.8 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N Open in the calculator
CVSS 4.07.6 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-539: Use of Persistent Cookies Containing Sensitive Information
OWASP Top 10A06:2025 Insecure Design
MITRE ATT&CKT1539 Steal Web Session Cookie, T1550.004 Web Session Cookie
CategoryCryptographic Failures

Description

The application offers a 'remember me' or 'keep me signed in' option that sets a long-lived cookie, which signs the user back in without a password once the normal session has ended. While it is valid, the cookie is as powerful as the password, so it needs the same care: an attacker who obtains it, for example through cross-site scripting, malware, a shared or unattended computer or a copy of the server's database, can sign in as that user and keep doing so long after the original session has ended. It is insecure when one or more of the following applies:

  • it contains the username and password, or a hash of the password, in encoded or reversibly encrypted form, so it can be decoded or cracked offline to recover the password, which may be reused on other services;
  • it is built from values an attacker can know or guess, such as the username, user ID or a timestamp, or a hash of them, so a valid token can be forged for any user, including administrators, without stealing anything first, which would make the issue high or critical;
  • it remains valid for months or indefinitely, is not invalidated at logout or password change, and can be used again and again, so a stolen token keeps working even after the user logs out or changes their password;
  • it is stored on the server in plain text, so anyone who can read the database can sign in as any user who chose the option.

The weakness can be identified by decoding the cookie and comparing tokens issued to different accounts and at different times, by checking whether the same token can be used repeatedly, and by testing whether it still signs the user in after logout and after a password change.

Remediation

Rebuild the persistent login mechanism so that the token is random, stored safely and revocable:

  • Generate the token from at least 128 bits of a cryptographically secure random number generator. A common design issues two random values, a selector used to look up the record and a validator that is compared with a hash stored on the server, so a copy of the database does not yield usable tokens.
  • Never place the password, a password hash or other user data in the cookie.
  • Give each token a fixed expiry, replace it with a new token each time it is used, and delete all of a user's tokens when they log out of all devices, change or reset their password, or the account is disabled.
  • Set the cookie with the Secure and HttpOnly attributes and a suitable SameSite value.
  • Ask for the password again before sensitive actions, such as changing the email address, password or multi-factor settings, in a session restored from the token.
  • Let users see and revoke the devices on which they are remembered.

As an interim measure, shorten the token lifetime and invalidate all existing persistent tokens so that users sign in again. Confirm the fix by checking that tokens are random and unrelated across accounts, that a token is rejected once it has been used and replaced, and that tokens stop working after logout and password change.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Authentication and Sessions Findings

Every Authentication and Sessions finding