CVE-2022-39263: @next auth/upstash redis adapter Upstash Adapter Missing Token Verification Vulnerability

MODERATE
Advisory Identifier: GHSA-4rxr-27mm-mxq9
CVSS 6.8
CWE-287
Published
Advisory Summary

CVE-2022-39263 is a MODERATE (CVSS 6.8) upstash adapter missing token verification vulnerability (CWE-287: Improper Authentication) affecting @next auth/upstash redis adapter libraries in the npm ecosystem. The issue involves upstash adapter missing token verification. Remediation is available by upgrading affected packages to version 3.0.2.

CVE-2022-39263 at a Glance

CVE Identifier CVE-2022-39263
GHSA Identifier GHSA-4rxr-27mm-mxq9
Severity MODERATE
CVSS v3.1 Base Score 6.8
CWE Classification CWE-287: Improper Authentication
Affected Product @next auth/upstash redis adapter
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 6.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability None (A:N)

How to Fix CVE-2022-39263

To remediate this vulnerability, upgrade all affected @next auth/upstash redis adapter dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

@next-auth/upstash-redis-adapter fixed: 3.0.2
npm install @next-auth/upstash-redis-adapter@3.0.2
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls @next-auth/upstash-redis-adapter

How to Check if You Are Affected

To determine whether your Node.js application is affected by CVE-2022-39263, inspect your project dependencies using npm:

npm ls @next-auth/upstash-redis-adapter

Analyze the terminal output to locate any version of @next auth/upstash redis adapter in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.0.2), your application is affected.

Note: The npm ls @next-auth/upstash-redis-adapter command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-287: Improper Authentication, where when an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct. In @next auth/upstash redis adapter, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Impact 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) ```js 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

CVE-2022-39263 Affected @next auth/upstash redis adapter Versions

1 component(s)
Fixed Versions:
3.0.2
Product / Package Ecosystem Affected Versions Fixed Version
@next-auth/upstash-redis-adapter
npm
< 3.0.2
3.0.2

References

Frequently Asked Questions

What is CVE-2022-39263?
CVE-2022-39263 is a security vulnerability in @next auth/upstash redis adapter involving Upstash Adapter missing token verification under CWE-287: Improper Authentication.
Which @next auth/upstash redis adapter versions are affected?
Affected versions include releases prior to 3.0.2 across affected packages: @next-auth/upstash-redis-adapter.
What version fixes CVE-2022-39263?
Upgrading to 3.0.2 (or the latest patched release for your respective branch) resolves the vulnerability.
Is @next-auth/upstash-redis-adapter affected?
Yes, @next-auth/upstash-redis-adapter is affected in releases prior to 3.0.2. Upgrade your dependency to 3.0.2 or later.
What is the CVSS score of CVE-2022-39263?
CVE-2022-39263 has a CVSS v3.1 base score of 6.8 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N.
What CWE is associated with CVE-2022-39263?
CVE-2022-39263 is classified under CWE-287: Improper Authentication (When an actor claims to have a given identity, the product does not prove or insufficiently proves that the claim is correct.).
How can I check npm dependencies for CVE-2022-39263?
Run the dependency tree command: 'npm ls @next-auth/upstash-redis-adapter'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "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"
  }
}