GHSA-4RXR-27MM-MXQ9
Vulnerability from github – Published: 2022-09-30 05:31 – Updated: 2022-09-30 05:31Impact
Applications that use next-auth Email Provider and @next-auth/upstash-redis-adapter before v3.0.2 are affected.
Description
The Upstash Redis adapter implementation did not check for both the identifier (email) and the token, but only checking for the identifier when verifying the token in the email callback flow. An attacker who knows about the victim's email could easily sign in as the victim, given the attacker also knows about the verification token's expired duration.
Patches
The vulnerability is patched in v3.0.2. To upgrade, run one of the following:
npm i @next-auth/upstash-redis-adapter@latest
yarn add @next-auth/upstash-redis-adapter@latest
pnpm add @next-auth/upstash-redis-adapter@latest
Workarounds
Using Advanced Initialization, developers can check the requests and compare the query's token and identifier before proceeding. Below is an example of how to do this: (Upgrading is still strongly recommended)
import { createHash } from "crypto"
export default async function auth(req, res) {
if (req.method === "POST" && req.action === "callback") {
const token = req.query?.token
const identifier = req.query?.email
function hashToken(token: string) {
const provider = authOptions.providers.find((p) => p.id === "email")
const secret = authOptions.secret
return (
createHash("sha256")
// Prefer provider specific secret, but use default secret if none specified
.update(`${token}${provider.secret ?? secret}`)
.digest("hex")
)
}
const hashedToken = hashToken(token)
const invite = await authOptions.adapter.useVerificationToken?.({
identifier,
token: hashedToken,
})
if (invite.token !== hashedToken) {
res.status(400).json({ error: "Invalid token" })
}
}
return await NextAuth(req, res, authOptions)
}
References
EmailProvider: https://next-auth.js.org/providers/email Advanced Initialization: https://next-auth.js.org/configuration/initialization#advanced-initialization Upstash Redis Adapter: https://next-auth.js.org/adapters/upstash-redis
For more information
If you have any concerns, we request responsible disclosure, outlined here: https://next-auth.js.org/security#reporting-a-vulnerability
{
"affected": [
{
"package": {
"ecosystem": "npm",
"name": "@next-auth/upstash-redis-adapter"
},
"ranges": [
{
"events": [
{
"introduced": "0"
},
{
"fixed": "3.0.2"
}
],
"type": "ECOSYSTEM"
}
]
}
],
"aliases": [
"CVE-2022-39263"
],
"database_specific": {
"cwe_ids": [
"CWE-287"
],
"github_reviewed": true,
"github_reviewed_at": "2022-09-30T05:31:32Z",
"nvd_published_at": "2022-09-28T21:15:00Z",
"severity": "MODERATE"
},
"details": "### Impact\nApplications that use `next-auth` Email Provider and `@next-auth/upstash-redis-adapter` before v3.0.2 are affected.\n\n### Description\nThe Upstash Redis adapter implementation did not check for both the identifier (email) and the token, but only checking for the identifier when verifying the token in the email callback flow. An attacker who knows about the victim\u0027s email could easily sign in as the victim, given the attacker also knows about the verification token\u0027s expired duration. \n\n### Patches\nThe vulnerability is patched in v3.0.2.\nTo upgrade, run one of the following:\n```\nnpm i @next-auth/upstash-redis-adapter@latest\n```\n```\nyarn add @next-auth/upstash-redis-adapter@latest\n```\n```\npnpm add @next-auth/upstash-redis-adapter@latest\n```\n\n### Workarounds\nUsing Advanced Initialization, developers can check the requests and compare the query\u0027s token and identifier before proceeding. Below is an example of how to do this: (Upgrading is still strongly recommended)\n\n```js\nimport { createHash } from \"crypto\"\nexport default async function auth(req, res) {\n if (req.method === \"POST\" \u0026\u0026 req.action === \"callback\") {\n const token = req.query?.token\n const identifier = req.query?.email\n function hashToken(token: string) {\n const provider = authOptions.providers.find((p) =\u003e p.id === \"email\")\n const secret = authOptions.secret\n return (\n createHash(\"sha256\")\n // Prefer provider specific secret, but use default secret if none specified\n .update(`${token}${provider.secret ?? secret}`)\n .digest(\"hex\")\n )\n }\n const hashedToken = hashToken(token)\n\n const invite = await authOptions.adapter.useVerificationToken?.({\n identifier,\n token: hashedToken,\n })\n if (invite.token !== hashedToken) {\n res.status(400).json({ error: \"Invalid token\" })\n }\n }\n return await NextAuth(req, res, authOptions)\n}\n\n```\n### References\nEmailProvider: https://next-auth.js.org/providers/email\nAdvanced Initialization: https://next-auth.js.org/configuration/initialization#advanced-initialization\nUpstash Redis Adapter: https://next-auth.js.org/adapters/upstash-redis\n\n### For more information\nIf you have any concerns, we request responsible disclosure, outlined here: https://next-auth.js.org/security#reporting-a-vulnerability\n\n",
"id": "GHSA-4rxr-27mm-mxq9",
"modified": "2022-09-30T05:31:32Z",
"published": "2022-09-30T05:31:32Z",
"references": [
{
"type": "WEB",
"url": "https://github.com/nextauthjs/next-auth/security/advisories/GHSA-4rxr-27mm-mxq9"
},
{
"type": "ADVISORY",
"url": "https://nvd.nist.gov/vuln/detail/CVE-2022-39263"
},
{
"type": "WEB",
"url": "https://github.com/nextauthjs/next-auth/commit/d16e04848ee703cf797724194d4ad2907fe125a9"
},
{
"type": "PACKAGE",
"url": "https://github.com/nextauthjs/next-auth"
}
],
"schema_version": "1.4.0",
"severity": [
{
"score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N",
"type": "CVSS_V3"
}
],
"summary": "Upstash Adapter missing token verification"
}
Sightings
| Author | Source | Type | Date |
|---|
Nomenclature
- Seen: The vulnerability was mentioned, discussed, or observed by the user.
- Confirmed: The vulnerability has been validated from an analyst's perspective.
- Published Proof of Concept: A public proof of concept is available for this vulnerability.
- Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
- Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
- Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
- Not confirmed: The user expressed doubt about the validity of the vulnerability.
- Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.