# CVE-2023-25581: Deserialization of untrusted data in InternalAttributeHandler in pac4j

> Remote code execution via unsafe Java deserialization in pac4j-core when processing specially crafted attributes in UserProfile objects.

- **Severity:** Critical 9.2 (`CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 10 Oct 2024
- **Updated:** 10 Oct 2024
- **Also known as:** GHSA-76mw-6p95-x9x5

## What is CVE-2023-25581?

CVE-2023-25581 is a critical unsafe deserialization vulnerability in pac4j, published on 10 Oct 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

pac4j is a security framework for Java. `pac4j-core` prior to version 4.0.0 is affected by a Java deserialization vulnerability. The vulnerability affects systems that store externally controlled values in attributes of the `UserProfile` class from pac4j-core. It can be exploited by providing an attribute that contains a serialized Java object with a special prefix `{#sb64}` and Base64 encoding. This issue may lead to Remote Code Execution (RCE) in the worst case. Although a `RestrictedObjectInputStream` is in place, that puts some restriction on what classes can be deserialized, it still allows a broad range of java packages and potentially exploitable with different gadget chains. pac4j versions 4.0.0 and greater are not affected by this issue. Users are advised to upgrade. There are no known workarounds for this vulnerability.

Weakness: CWE-502 (Deserialization of Untrusted Data)

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

2 open source packages ship an affected version, including org.pac4j:pac4j-core.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `org.pac4j:pac4j-core` | Maven | All versions | 4.0.0 |
| `org.pac4j:pac4j-core` | Maven | All versions | 4.0.0 |

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

Upgrade org.pac4j:pac4j-core to 4.0.0 or later.

## Is CVE-2023-25581 being exploited?

It is not confirmed as exploited in the wild, but public exploit code for CVE-2023-25581 exists.

Public exploit code:

- https://github.com/p33d/CVE-2023-25581 (github_poc): https://github.com/p33d/CVE-2023-25581

## Fix prompt for AI coding agents

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

What it is: CVE-2023-25581 is a critical unsafe deserialization vulnerability in pac4j, published on 10 Oct 2024. An attacker can exploit it over the internet without logging in, with no action from the victim.
Exploitation: It is not confirmed as exploited in the wild, but public exploit code for CVE-2023-25581 exists.

Affected packages and fixed versions:
- org.pac4j:pac4j-core (Maven): affected all versions; fixed in 4.0.0
- org.pac4j:pac4j-core (Maven): affected all versions; fixed in 4.0.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-2023-25581/ (Markdown: https://insights.sbomify.com/CVE-2023-25581/index.md)
```

## Sources

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

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