7.4high
@fastify/secure-session: Reuse of destroyed secure session cookie
- Severity
- 7.4high CVSS:3.1 by GitHub_M
- Exploit likelihood
- 0.62% (higher than 50% of CVEs; EPSS, by FIRST)
- Published
- Last changed
- Assigned by
- GitHub_M
- Also known as
- GHSA-9wwp-q7wq-jx35
Description
@festify/secure-session creates a secure stateless cookie session for Fastify. At the end of the request handling, it will encrypt all data in the session with a secret key and attach the ciphertext as a cookie value with the defined cookie name. After that, the session on the server side is destroyed. When an encrypted cookie with matching session name is provided with subsequent requests, it will decrypt the ciphertext to get the data. The plugin then creates a new session with the data in the ciphertext. Thus theoretically the web instance is still accessing the data from a server-side session, but technically that session is generated solely from a user provided cookie (which is assumed to be non-craftable because it is encrypted with a secret key not known to the user). The issue exists in the session removal process. In the delete function of the code, when the session is deleted, it is marked for deletion. However, if an attacker could gain access to the cookie, they could keep using it forever. Version 7.3.0 contains a patch for the issue. As a workaround, one may include a "last update" field in the session, and treat "old sessions" as expired.
Affected
| Product or package | Versions | Reported by |
|---|---|---|
| fastify fastify-secure-session | < 7.3.0 | CVE List |
| @fastify/secure-session (npm) | before 7.3.0 | GitHub Advisory Database |
All scores
| GitHub_M | 7.4high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N |
| GitHub | 7.4high CVSS:3.1 | CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N |
Classification
SSVC (CISA-ADP): exploitation none, automatable no, technical impact partial.
What each source says
CVE List
@festify/secure-session creates a secure stateless cookie session for Fastify. At the end of the request handling, it will encrypt all data in the session with a secret key and attach the ciphertext as a cookie value with the defined cookie name. After that, the session on the server side is destroyed. When an encrypted cookie with matching session name is provided with subsequent requests, it will decrypt the ciphertext to get the data. The plugin then creates a new session with the data in the ciphertext. Thus theoretically the web instance is still accessing the data from a server-side session, but technically that session is generated solely from a user provided cookie (which is assumed to be non-craftable because it is encrypted with a secret key not known to the user). The issue exists in the session removal process. In the delete function of the code, when the session is deleted, it is marked for deletion. However, if an attacker could gain access to the cookie, they could keep using it forever. Version 7.3.0 contains a patch for the issue. As a workaround, one may include a "last update" field in the session, and treat "old sessions" as expired.
GitHub Advisory Database
Impact
At the end of the request handling, it will encrypt all data in the session with a secret key and attach the ciphertext as a cookie value with the defined cookie name. After that, the session on the server side is destroyed. When an encrypted cookie with matching session name is provided with subsequent requests, it will decrypt the ciphertext to get the data. The plugin then creates a new session with the data in the ciphertext. Thus theoretically the web instance is still accessing the data from a server-side session, but technically that session is generated solely from a user provided cookie (which is assumed to be non-craftable because it is encrypted with a secret key not known to the user).
The issue exists in the session removal process. In the delete function of the code, when the session is deleted, it is marked for deletion. However, if an attacker could gain access to the cookie, they could keep using it forever.
Patches
Fixed in 56d66642ecc633cff0606927601e81cdac361370. Update to v7.3.0.
Workarounds
Include a "last update" field in the session, and treat "old sessions" as expired. Make sure to configure your cookie as "http only".
References
NVD (es)
@festify/secure-session crea una sesión segura de cookies sin estado para Fastify. Al final del manejo de la solicitud, cifrará todos los datos de la sesión con una clave secreta y adjuntará el texto cifrado como un valor de cookie con el nombre de cookie definido. Después de eso, la sesión en el lado del servidor se destruye. Cuando se proporciona una cookie cifrada con un nombre de sesión coincidente en solicitudes posteriores, descifrará el texto cifrado para obtener los datos. Luego, el complemento crea una nueva sesión con los datos en el texto cifrado. Por lo tanto, en teoría, la instancia web todavía accede a los datos desde una sesión del lado del servidor, pero técnicamente esa sesión se genera únicamente a partir de una cookie proporcionada por el usuario (que se supone que no se puede crear porque está cifrado con una clave secreta que el usuario desconoce). El problema existe en el proceso de eliminación de la sesión. En la función de eliminación del código, cuando se elimina la sesión, se marca para su eliminación. Sin embargo, si un atacante pudiera obtener acceso a la cookie, podría seguir usándola para siempre. La versión 7.3.0 contiene un parche para el problema. Como workaround, se puede incluir un campo de "última actualización" en la sesión y tratar las "sesiones antiguas" como vencidas.
References
Sources
| Source | Record | Licence |
|---|---|---|
| CVE List | CVE-2024-31999 changed 2024-08-02 | CVE Terms of Use |
| GitHub Advisory Database | GHSA-9wwp-q7wq-jx35 changed 2026-09-10 | CC-BY-4.0 |
| NVD | CVE-2024-31999 changed 2026-06-17 | Public domain |