Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS00cnhyLTI3bW0tbXhxOc4AAvIm
Upstash Adapter missing token verification
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)
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
Permalink: https://github.com/advisories/GHSA-4rxr-27mm-mxq9JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS00cnhyLTI3bW0tbXhxOc4AAvIm
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: about 2 years ago
Updated: almost 2 years ago
CVSS Score: 6.8
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N
Identifiers: GHSA-4rxr-27mm-mxq9, CVE-2022-39263
References:
- https://github.com/nextauthjs/next-auth/security/advisories/GHSA-4rxr-27mm-mxq9
- https://nvd.nist.gov/vuln/detail/CVE-2022-39263
- https://github.com/nextauthjs/next-auth/commit/d16e04848ee703cf797724194d4ad2907fe125a9
- https://github.com/advisories/GHSA-4rxr-27mm-mxq9
Blast Radius: 11.7
Affected Packages
npm:@next-auth/upstash-redis-adapter
Dependent packages: 1Dependent repositories: 53
Downloads: 2,822 last month
Affected Version Ranges: < 3.0.2
Fixed in: 3.0.2
All affected versions: 1.1.0, 1.1.1, 2.0.0, 3.0.0, 3.0.1
All unaffected versions: 3.0.2, 3.0.3, 3.0.4