# CVE-2023-45814: Tokens cached in the AuthenticationService are susceptible to reuse in Bunkum

> Cached authentication tokens persist beyond request lifetime, allowing potential reuse of expired or detached tokens in Bunkum game server libraries.

- **Severity:** Medium 5.3 (`CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:L/I:N/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 18 Oct 2023
- **Updated:** 13 Sep 2024
- **Also known as:** GHSA-jrf2-h5j6-3rrq

## What is CVE-2023-45814?

CVE-2023-45814 is a medium-severity use after free vulnerability in LittleBigRefresh Bunkum, published on 18 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

Bunkum is an open-source protocol-agnostic request server for custom game servers. First, a little bit of background. So, in the beginning, Bunkum's `AuthenticationService` only supported injecting `IUser`s. However, as Refresh and SoundShapesServer implemented permissions systems support for injecting `IToken`s into endpoints was added. All was well until 4.0. Bunkum 4.0 then changed to enforce relations between `IToken`s and `IUser`s. This wasn't implemented in a very good way in the `AuthenticationService`, and ended up breaking caching in such a way that cached tokens would persist after the lifetime of the request - since we tried to cache both tokens and users. From that point until now, from what I understand, Bunkum was attempting to use that cached token at the start of the next request once cached. Naturally, when that token expired, downstream projects like Refresh would remove the object from Realm - and cause the object in the cache to be in a detached state, causing an exception from invalid use of `IToken.User`. So in other words, a use-after-free since Realm can't manage the lifetime of the cached token. Security-wise, the scope is fairly limited, can only be pulled off on a couple endpoints given a few conditions, and you can't guarantee which token you're going to get. Also, the token *would* get invalidated properly if the endpoint had either a `IToken` usage or a `IUser` usage. The fix is to just wipe the token cache after the request was handled, which is now in `4.2.1`. Users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-772 (Missing Release of Resource after Effective Lifetime)

## Which versions are affected by CVE-2023-45814?

2 open source packages ship an affected version, including Bunkum. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `Bunkum` | NuGet | From 4.0.0 | 4.2.1 |
| `Bunkum` | NuGet | From 4.0.0 | 4.2.1 |

Products: Littlebigfresh Bunkum.

## How do I fix CVE-2023-45814?

Upgrade Bunkum to 4.2.1 or later.

## Is CVE-2023-45814 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2023-45814 and fix it if it is affected.

What it is: CVE-2023-45814 is a medium-severity use after free vulnerability in LittleBigRefresh Bunkum, published on 18 Oct 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2023-45814 in the wild and no public exploit code.

Affected packages and fixed versions:
- Bunkum (NuGet): affected from 4.0.0; fixed in 4.2.1
- Bunkum (NuGet): affected from 4.0.0; fixed in 4.2.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-2023-45814/ (Markdown: https://insights.sbomify.com/CVE-2023-45814/index.md)
```

## Sources

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

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