# CVE-2024-51987: HTTP Client uses incorrect token after refresh in Duende.AccessTokenManagement.OpenIdConnect

> HTTP clients may use another user's access token after refresh, allowing unauthorized data access or account takeover.

- **Severity:** Medium 5.4 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:L/I:L/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:** 7 Nov 2024
- **Updated:** 8 Nov 2024
- **Also known as:** GHSA-7mr7-4f54-vcx5

## What is CVE-2024-51987?

CVE-2024-51987 is a medium-severity vulnerability in DuendeSoftware Duende.AccessTokenManagement, published on 7 Nov 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

Duende.AccessTokenManagement.OpenIdConnect is a set of .NET libraries that manage OAuth and OpenId Connect access tokens. HTTP Clients created by `AddUserAccessTokenHttpClient` may use a different user's access token after a token refresh occurs. This occurs because a refreshed token will be captured in pooled `HttpClient` instances, which may be used by a different user. Instead of using `AddUserAccessTokenHttpClient` to create an `HttpClient` that automatically adds a managed token to outgoing requests, you can use the `HttpConext.GetUserAccessTokenAsync` extension method or the `IUserTokenManagementService.GetAccessTokenAsync` method. This issue is fixed in Duende.AccessTokenManagement.OpenIdConnect 3.0.1. All users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-270 (Privilege Context Switching Error)

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

2 open source packages ship an affected version, including Duende.AccessTokenManagement.OpenIdConnect.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `Duende.AccessTokenManagement.OpenIdConnect` | NuGet | From 3.0.0 | 3.0.1 |
| `Duende.AccessTokenManagement.OpenIdConnect` | NuGet | From 3.0.0 | 3.0.1 |

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

Upgrade Duende.AccessTokenManagement.OpenIdConnect to 3.0.1 or later.

## Is CVE-2024-51987 being exploited?

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

## Fix prompt for AI coding agents

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

What it is: CVE-2024-51987 is a medium-severity vulnerability in DuendeSoftware Duende.AccessTokenManagement, published on 7 Nov 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-51987 in the wild and no public exploit code.

Affected packages and fixed versions:
- Duende.AccessTokenManagement.OpenIdConnect (NuGet): affected from 3.0.0; fixed in 3.0.1
- Duende.AccessTokenManagement.OpenIdConnect (NuGet): affected from 3.0.0; fixed in 3.0.1

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-51987/ (Markdown: https://insights.sbomify.com/CVE-2024-51987/index.md)
```

## Sources

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

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