# CVE-2021-41106: File reference keys leads to incorrect hashes on HMAC algorithms

> Users relying on file path references for HMAC keys in this JWT library may inadvertently use the path string as the secret, allowing token forgery.

- **Severity:** Medium 4.4 (`CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U/C:L/I:L/A:N`)
- **Exploited in the wild:** Not known
- **Login needed:** Any signed-in user
- **Attackable:** Local or same network only
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 28 Sep 2021
- **Updated:** 4 Aug 2024
- **Also known as:** GHSA-7322-jrq4-x5hf

## What is CVE-2021-41106?

CVE-2021-41106 is a medium-severity vulnerability in lcobucci jwt, published on 28 Sep 2021. It can only be exploited from the same machine or local network, with no action from the victim.

### Official description

JWT is a library to work with JSON Web Token and JSON Web Signature. Prior to versions 3.4.6, 4.0.4, and 4.1.5, users of HMAC-based algorithms (HS256, HS384, and HS512) combined with `Lcobucci\JWT\Signer\Key\LocalFileReference` as key are having their tokens issued/validated using the file path as hashing key - instead of the contents. The HMAC hashing functions take any string as input and, since users can issue and validate tokens, users are lead to believe that everything works properly. Versions 3.4.6, 4.0.4, and 4.1.5 have been patched to always load the file contents, deprecated the `Lcobucci\JWT\Signer\Key\LocalFileReference`, and suggest `Lcobucci\JWT\Signer\Key\InMemory` as the alternative. As a workaround, use `Lcobucci\JWT\Signer\Key\InMemory` instead of `Lcobucci\JWT\Signer\Key\LocalFileReference` to create the instances of one's keys.

Weakness: CWE-345 (Insufficient Verification of Data Authenticity)

## Which versions are affected by CVE-2021-41106?

6 open source packages ship an affected version, including lcobucci/jwt. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `lcobucci/jwt` | Packagist | From 3.4.0 | 3.4.6 |
| `lcobucci/jwt` | Packagist | From 3.4.0 | 3.4.6 |
| `lcobucci/jwt` | Packagist | From 4.0.0 | 4.0.4 |
| `lcobucci/jwt` | Packagist | From 4.0.0 | 4.0.4 |
| `lcobucci/jwt` | Packagist | From 4.1.0 | 4.1.5 |
| `lcobucci/jwt` | Packagist | From 4.1.0 | 4.1.5 |

Products: Lcobucci Jwt.

## How do I fix CVE-2021-41106?

Upgrade lcobucci/jwt to a fixed version for your release line: 3.4.6, 4.0.4 or 4.1.5.

## Is CVE-2021-41106 being exploited?

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

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-41106 and fix it if it is affected.

What it is: CVE-2021-41106 is a medium-severity vulnerability in lcobucci jwt, published on 28 Sep 2021. It can only be exploited from the same machine or local network, with no action from the victim.
Exploitation: There is no known exploitation of CVE-2021-41106 in the wild and no public exploit code.

Affected packages and fixed versions:
- lcobucci/jwt (Packagist): affected from 3.4.0; fixed in 3.4.6
- lcobucci/jwt (Packagist): affected from 3.4.0; fixed in 3.4.6
- lcobucci/jwt (Packagist): affected from 4.0.0; fixed in 4.0.4
- lcobucci/jwt (Packagist): affected from 4.0.0; fixed in 4.0.4
- lcobucci/jwt (Packagist): affected from 4.1.0; fixed in 4.1.5
- lcobucci/jwt (Packagist): affected from 4.1.0; fixed in 4.1.5

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

## Sources

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

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