# CVE-2023-48223: fast-jwt JWT Algorithm Confusion

> Attackers can bypass JWT signature verification by exploiting algorithm confusion in fast-jwt when specific public key formats are used.

- **Severity:** Medium 5.9 (`CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/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:** 20 Nov 2023
- **Updated:** 2 Aug 2024
- **Also known as:** GHSA-c2ff-88x2-x9pg

## What is CVE-2023-48223?

CVE-2023-48223 is a medium-severity vulnerability in nearform fast-jwt, published on 20 Nov 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

fast-jwt provides fast JSON Web Token (JWT) implementation. Prior to version 3.3.2, the fast-jwt library does not properly prevent JWT algorithm confusion for all public key types. The 'publicKeyPemMatcher' in 'fast-jwt/src/crypto.js' does not properly match all common PEM formats for public keys. To exploit this vulnerability, an attacker needs to craft a malicious JWT token containing the HS256 algorithm, signed with the public RSA key of the victim application. This attack will only work if the victim application utilizes a public key containing the `BEGIN RSA PUBLIC KEY` header. Applications using the RS256 algorithm, a public key with a `BEGIN RSA PUBLIC KEY` header, and calling the verify function without explicitly providing an algorithm, are vulnerable to this algorithm confusion attack which allows attackers to sign arbitrary payloads which will be accepted by the verifier. Version 3.3.2 contains a patch for this issue. As a workaround, change line 29 of `blob/master/src/crypto.js` to include a regular expression.

Weakness: CWE-20 (Improper Input Validation)

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

2 open source packages ship an affected version, including fast-jwt. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `fast-jwt` | npm | All versions | 3.3.2 |
| `fast-jwt` | npm | All versions | 3.3.2 |

Products: Nearform Fast-Jwt.

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

Upgrade fast-jwt to 3.3.2 or later.

## Is CVE-2023-48223 being exploited?

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

Public exploit code:

- https://github.com/lucastran05/CVE-2023-48223 (github_poc): https://github.com/lucastran05/CVE-2023-48223

## Other vulnerabilities in nearform fast-jwt

- [CVE-2026-34950](https://insights.sbomify.com/CVE-2026-34950/): fast-jwt has an incomplete fix for CVE-2023-48223: JWT Algorithm Confusion via Whitespace-Prefixed RSA Public Key (critical 9.1)
- [CVE-2026-35039](https://insights.sbomify.com/CVE-2026-35039/): fast-jwt: Cache Confusion via cacheKeyBuilder Collisions Can Return Claims From a Different Token (Identity/Authorization Mixup) (critical 9.1)
- [CVE-2026-35042](https://insights.sbomify.com/CVE-2026-35042/): fast-jwt accepts unknown `crit` header extensions (RFC 7515 §4.1.11 MUST violation) (high 7.5)
- [CVE-2026-35040](https://insights.sbomify.com/CVE-2026-35040/): fast-jwt: Stateful RegExp (/g or /y) causes non-deterministic allowed-claim validation (logical DoS) (medium 5.3)
- [CVE-2026-35041](https://insights.sbomify.com/CVE-2026-35041/): ReDoS in fast-jwt when using RegExp in allowed* leading to CPU exhaustion during token verification (medium 4.2)

## Fix prompt for AI coding agents

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

What it is: CVE-2023-48223 is a medium-severity vulnerability in nearform fast-jwt, published on 20 Nov 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-48223 in the wild and no public exploit code.

Affected packages and fixed versions:
- fast-jwt (npm): affected all versions; fixed in 3.3.2
- fast-jwt (npm): affected all versions; fixed in 3.3.2

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

## Sources

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

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