# CVE-2024-31999: @fastify/secure-session: Reuse of destroyed secure session cookie

> Attackers can reuse destroyed secure session cookies indefinitely, bypassing session expiration and potentially maintaining unauthorized access.

- **Severity:** High 7.4 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:N/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 10 Apr 2024
- **Updated:** 2 Aug 2024
- **Also known as:** GHSA-9wwp-q7wq-jx35

## What is CVE-2024-31999?

CVE-2024-31999 is a high-severity vulnerability in fastify-secure-session, published on 10 Apr 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.

### Official 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.

Weakness: CWE-613 (DEPRECATED: Insufficient Session Expiration)

## Which versions are affected by CVE-2024-31999?

2 open source packages ship an affected version, including @fastify/secure-session.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `@fastify/secure-session` | npm | All versions | 7.3.0 |
| `@fastify/secure-session` | npm | All versions | 7.3.0 |

## How do I fix CVE-2024-31999?

Upgrade @fastify/secure-session to 7.3.0 or later.

## Is CVE-2024-31999 being exploited?

There is no known exploitation of CVE-2024-31999 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2024-31999 and fix it if it is affected.

What it is: CVE-2024-31999 is a high-severity vulnerability in fastify-secure-session, published on 10 Apr 2024. An attacker can exploit it over the internet without logging in, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2024-31999 in the wild and no public exploit code.

Affected packages and fixed versions:
- @fastify/secure-session (npm): affected all versions; fixed in 7.3.0
- @fastify/secure-session (npm): affected all versions; fixed in 7.3.0

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2024-31999/ (Markdown: https://insights.sbomify.com/CVE-2024-31999/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2024-31999
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2024-31999
- OSV: https://osv.dev/vulnerability/CVE-2024-31999

---
From sbomify Insights: https://insights.sbomify.com/CVE-2024-31999/
Summaries are generated and may contain mistakes; the official description above is the record.
