CVE-2024-31999: @fastify/secure-session Reuse Of Destroyed Secure Session Vulnerability

HIGH
Advisory Identifier: GHSA-9wwp-q7wq-jx35
CVSS 7.4
CWE-613
Published
Advisory Summary

CVE-2024-31999 is a HIGH (CVSS 7.4) reuse of destroyed secure session vulnerability (CWE-613: Insufficient Session Expiration) affecting @fastify/secure-session libraries in the npm ecosystem. The issue involves reuse of destroyed secure session cookie. Remediation is available by upgrading affected packages to version 7.3.0.

CVE-2024-31999 at a Glance

CVE Identifier CVE-2024-31999
GHSA Identifier GHSA-9wwp-q7wq-jx35
Severity HIGH
CVSS v3.1 Base Score 7.4
CWE Classification CWE-613: Insufficient Session Expiration
Affected Product @fastify/secure-session
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 7.4

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N).

Attack Vector Network (AV:N)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity None (I:N)
Availability None (A:N)

How to Fix CVE-2024-31999

To remediate this vulnerability, upgrade all affected @fastify/secure-session dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@fastify/secure-session fixed: 7.3.0
npm install @fastify/secure-session@7.3.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @fastify/secure-session

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2024-31999, inspect your project dependencies using npm:

npm ls @fastify/secure-session

Analyze the terminal output to locate any version of @fastify/secure-session in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 7.3.0), your application is affected.

Note: The npm ls @fastify/secure-session command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-613: Insufficient Session Expiration, where according to wasc, "insufficient session expiration is when a web site permits an attacker to reuse old session credentials or session ids for authorization.". In @fastify/secure-session, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 * https://hackerone.com/reports/2374253

CVE-2024-31999 Affected @fastify/secure-session Versions

1 component(s)
Fixed Versions:
7.3.0
Product / Package Ecosystem Affected Versions Fixed Version
@fastify/secure-session
npm
< 7.3.0
7.3.0

References

Frequently Asked Questions

What is CVE-2024-31999?
CVE-2024-31999 is a security vulnerability in @fastify/secure-session involving Reuse of destroyed secure session cookie under CWE-613: Insufficient Session Expiration.
Which @fastify/secure-session versions are affected?
Affected versions include releases prior to 7.3.0 across affected packages: @fastify/secure-session.
What version fixes CVE-2024-31999?
Upgrading to 7.3.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @fastify/secure-session affected?
Yes, @fastify/secure-session is affected in releases prior to 7.3.0. Upgrade your dependency to 7.3.0 or later.
What is the CVSS score of CVE-2024-31999?
CVE-2024-31999 has a CVSS v3.1 base score of 7.4 (HIGH) with vector string CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N.
What CWE is associated with CVE-2024-31999?
CVE-2024-31999 is classified under CWE-613: Insufficient Session Expiration (According to WASC, "Insufficient Session Expiration is when a web site permits an attacker to reuse old session credentials or session IDs for authorization.").
How can I check npm dependencies for CVE-2024-31999?
Run the dependency tree command: 'npm ls @fastify/secure-session'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-9wwp-q7wq-jx35",
  "modified" : "2024-04-11T14:31:13Z",
  "published" : "2024-04-10T17:15:50Z",
  "aliases" : [ "CVE-2024-31999" ],
  "summary" : "@fastify/secure-session: Reuse of destroyed secure session cookie",
  "details" : "### Impact\n\nAt 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).\n\nThe 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.\n\n### Patches\n\nFixed in 56d66642ecc633cff0606927601e81cdac361370.\nUpdate to v7.3.0.\n\n### Workarounds\n\nInclude a \"last update\" field in the session, and treat \"old sessions\" as expired. \nMake sure to configure your cookie as \"http only\".\n\n### References\n\n* https://hackerone.com/reports/2374253\n",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "@fastify/secure-session"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "7.3.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-secure-session/security/advisories/GHSA-9wwp-q7wq-jx35"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2024-31999"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/fastify/fastify-secure-session/commit/56d66642ecc633cff0606927601e81cdac361370"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/fastify/fastify-secure-session"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-613" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2024-04-10T17:15:50Z",
    "nvd_published_at" : "2024-04-10T22:15:07Z"
  }
}