# CVE-2023-48309: next-auth vulnerable to possible user mocking that bypasses basic authentication

> Attackers can bypass authentication by injecting a JWT from an interrupted OAuth flow, allowing them to simulate a logged-in state and view protected UI elements.

- **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:** 20 Nov 2023
- **Updated:** 29 Aug 2024
- **Also known as:** GHSA-v64w-49xw-qq89

## What is CVE-2023-48309?

CVE-2023-48309 is a medium-severity authentication bypass vulnerability in nextauthjs next-auth, published on 20 Nov 2023. An attacker can exploit it over the internet without logging in, with no action from the victim.

### Official description

NextAuth.js provides authentication for Next.js. `next-auth` applications prior to version 4.24.5 that rely on the default Middleware authorization are affected by a vulnerability. A bad actor could create an empty/mock user, by getting hold of a NextAuth.js-issued JWT from an interrupted OAuth sign-in flow (state, PKCE or nonce). Manually overriding the `next-auth.session-token` cookie value with this non-related JWT would let the user simulate a logged in user, albeit having no user information associated with it. (The only property on this user is an opaque randomly generated string). This vulnerability does not give access to other users' data, neither to resources that require proper authorization via scopes or other means. The created mock user has no information associated with it (ie. no name, email, access_token, etc.) This vulnerability can be exploited by bad actors to peek at logged in user states (e.g. dashboard layout). `next-auth` `v4.24.5` contains a patch for the vulnerability. As a workaround, using a custom authorization callback for Middleware, developers can manually do a basic authentication.

Weakness: CWE-863 (Incorrect Authorization), CWE-285 (Improper Authorization)

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

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `next-auth` | npm | All versions | 4.24.5 |
| `next-auth` | npm | All versions | 4.24.5 |

Products: Nextauth.js Next-Auth.

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

Upgrade next-auth to 4.24.5 or later.

## Is CVE-2023-48309 being exploited?

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

## Other vulnerabilities in nextauthjs next-auth

- [CVE-2022-35924](https://insights.sbomify.com/CVE-2022-35924/): Verification requests (magic link) sent to unwanted emails (critical 9.1)
- [CVE-2023-27490](https://insights.sbomify.com/CVE-2023-27490/): Missing proper state, nonce and PKCE checks for OAuth authentication in next-auth (high 8.1)
- [CVE-2022-31093](https://insights.sbomify.com/CVE-2022-31093/): Improper Handling of `callbackUrl` parameter in next-auth (high 7.5)
- [CVE-2022-31127](https://insights.sbomify.com/CVE-2022-31127/): Improper handling of email input in next-auth (high 7.1)
- [CVE-2022-39263](https://insights.sbomify.com/CVE-2022-39263/): NextAuth.js Upstash Adapter missing token verification (medium 6.8)

## Fix prompt for AI coding agents

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

What it is: CVE-2023-48309 is a medium-severity authentication bypass vulnerability in nextauthjs next-auth, 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-48309 in the wild and no public exploit code.

Affected packages and fixed versions:
- next-auth (npm): affected all versions; fixed in 4.24.5
- next-auth (npm): affected all versions; fixed in 4.24.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-2023-48309/ (Markdown: https://insights.sbomify.com/CVE-2023-48309/index.md)
```

## Sources

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

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