CVE-2026-41213 describes a validation gap in @node-oauth/oauth2-server, a widely used OAuth 2.0 server library for Node.js. According to the advisory records, the token exchange accepted code_verifier values that RFC 7636 forbids, including single-character strings, when the S256 method was used. Reports also say a failed verifier attempt did not invalidate the authorization code.
Source notes: the core description is consistent across NVD, Wiz, and other trackers. Severity scores differ between them (one lists CVSS 5.9, medium; at least one vendor page calls it critical), and NVD analysis was pending when we looked. Wiz reports the fix in 5.3.0, and the GitHub advisory is GHSA-jhm7-29pj-4xvf. Read the advisory itself for the authoritative affected range before you decide how urgent this is.
What PKCE is supposed to guarantee
PKCE protects the authorization code flow when a code can be intercepted, for example through a leaked redirect, a malicious app registered for the same custom scheme, or logs. The client generates a random code_verifier, sends only its hash (code_challenge) with the authorization request, and proves possession by sending the original verifier at the token endpoint.
RFC 7636 constrains the verifier: 43 to 128 characters from the unreserved set A-Z a-z 0-9 - . _ ~. With S256, the challenge is BASE64URL(SHA256(verifier)).
The length requirement is not cosmetic. A verifier with 43 or more characters drawn from a 66-character alphabet has enough entropy that an attacker holding only the challenge cannot guess it. If a server accepts a one-character verifier, the entropy argument collapses: the legitimate client may send a weak value, and, more importantly, the check the server performs is no longer the check the protocol relies on.
Why failed attempts must consume the code
The second half matters as much as the first. If a wrong verifier leaves the authorization code valid, an attacker who intercepted the code can try guesses against the token endpoint until one works. Per RFC 6749, authorization codes must be single-use, and the safest reading is that any failed redemption attempt should invalidate the code. Combine a weak verifier space with unlimited retries and the attack becomes practical.
Audit your own server
Whether or not you use this library, check three things at your token endpoint.
- Format validation before hashing. Reject verifiers that do not match the RFC grammar.
- Code burn on failure. A failed verifier check should delete or mark the code as used.
- Short code lifetime. RFC 6749 recommends a maximum of 10 minutes; one to two minutes is common.
A minimal validation function:
import { createHash, timingSafeEqual } from "node:crypto";
const VERIFIER_PATTERN = /^[A-Za-z0-9\-._~]{43,128}$/;
export function verifyPkceS256(
codeVerifier: string,
storedChallenge: string,
): boolean {
if (!VERIFIER_PATTERN.test(codeVerifier)) return false;
const computed = createHash("sha256")
.update(codeVerifier, "ascii")
.digest("base64url");
const a = Buffer.from(computed);
const b = Buffer.from(storedChallenge);
return a.length === b.length && timingSafeEqual(a, b);
}And the redemption path, which must invalidate the code before returning an error:
export async function redeemCode(
code: string,
codeVerifier: string,
store: CodeStore,
) {
const record = await store.take(code); // atomically fetch AND delete
if (!record || record.expiresAt < Date.now()) {
throw new OAuthError("invalid_grant");
}
if (!verifyPkceS256(codeVerifier, record.codeChallenge)) {
throw new OAuthError("invalid_grant"); // code is already gone
}
return issueTokens(record);
}The important design choice is take, not get. Fetch and delete atomically, so that a failure after that point cannot leave a usable code behind. With Redis this is GETDEL; with SQL it is a DELETE ... RETURNING in a single statement.
Tests worth keeping
These cases would have caught the issue in any server implementation:
import { describe, it, expect } from "vitest";
describe("PKCE token exchange", () => {
it("rejects a one-character verifier", async () => {
const { code } = await startFlow({ challengeFor: "a".repeat(43) });
await expect(redeem(code, "a")).rejects.toThrow("invalid_grant");
});
it("burns the code after a failed verifier", async () => {
const { code, verifier } = await startFlow();
await expect(redeem(code, "x".repeat(43))).rejects.toThrow();
// The correct verifier must now fail too.
await expect(redeem(code, verifier)).rejects.toThrow("invalid_grant");
});
it("rejects verifiers with characters outside the unreserved set", async () => {
const { code } = await startFlow();
await expect(redeem(code, "!".repeat(43))).rejects.toThrow();
});
});The second test encodes the behavior people forget: after one bad attempt, even the correct verifier must fail.
Practical steps
- If you use
@node-oauth/oauth2-server: check your installed version withnpm ls @node-oauth/oauth2-server, read GHSA-jhm7-29pj-4xvf, and upgrade to the fixed release (reported as 5.3.0). - If you run another OAuth server: run the three tests above against a staging instance. This class of bug, a check that exists but is looser than the spec, is common.
- For authorization servers you do not control: make sure your clients generate verifiers from at least 32 random bytes encoded as base64url, which yields 43 characters, and require S256 rather than
plain. - Add a rate limit and an alert on repeated
invalid_grantresponses per client. Even with correct code-burning, a spike is worth knowing about.
Summary
PKCE is only as strong as the server's enforcement of its details. The verifier grammar and single-use codes are the two properties that turn a hash comparison into an actual defense. If you operate an OAuth server, a thirty-minute audit with the tests above is a reasonable response to this advisory, whichever library you use.