{ "schema_version": "1.4.0", "id": "GHSA-4rxr-27mm-mxq9", "modified": "2022-09-30T05:31:32Z", "published": "2022-09-30T05:31:32Z", "aliases": [ "CVE-2022-39263" ], "summary": "Upstash Adapter missing token verification", "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's email could easily sign in as the victim, given the attacker also knows about the verification token's 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's 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\" && 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) => 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", "severity": [ { "type": "CVSS_V3", "score": "CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N" } ], "affected": [ { "package": { "ecosystem": "npm", "name": "@next-auth/upstash-redis-adapter" }, "ranges": [ { "type": "ECOSYSTEM", "events": [ { "introduced": "0" }, { "fixed": "3.0.2" } ] } ] } ], "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" } ], "database_specific": { "cwe_ids": [ "CWE-287" ], "severity": "MODERATE", "github_reviewed": true, "github_reviewed_at": "2022-09-30T05:31:32Z", "nvd_published_at": "2022-09-28T21:15:00Z" } }