CVE-2026-35040: fast-jwt Denial of Service Vulnerability
MODERATECVE-2026-35040 is a MODERATE (CVSS 5.3) denial of service vulnerability (CWE-440: Expected Behavior Violation) affecting fast-jwt libraries in the npm ecosystem. The issue involves stateful regexp (/g or /y) causes non-deterministic allowed-claim validation (logical dos). Remediation is available by upgrading affected packages to version 6.2.1.
CVE-2026-35040 at a Glance
Security Impact
CVSS: 5.3
The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L).
How to Fix CVE-2026-35040
To remediate this vulnerability, upgrade all affected fast-jwt dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install fast-jwt@6.2.1
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls fast-jwt
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2026-35040, inspect your project dependencies using npm:
npm ls fast-jwt
Analyze the terminal output to locate any version of fast-jwt in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 6.2.1), your application is affected.
Note: The npm ls fast-jwt 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-440: Expected Behavior Violation, where a feature, api, or function does not perform according to its specification. In fast-jwt, 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
CVE-2026-35040 Affected fast-jwt Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
fast-jwt
|
npm |
< 6.2.1
|
6.2.1
|
References
Frequently Asked Questions
What is CVE-2026-35040?
Which fast-jwt versions are affected?
What version fixes CVE-2026-35040?
Is fast-jwt affected?
What is the CVSS score of CVE-2026-35040?
What CWE is associated with CVE-2026-35040?
How can I check npm dependencies for CVE-2026-35040?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-3j8v-cgw4-2g6q",
"modified" : "2026-04-09T19:05:11Z",
"published" : "2026-04-09T16:41:20Z",
"aliases" : [ "CVE-2026-35040" ],
"summary" : "fast-jwt: Stateful RegExp (/g or /y) causes non-deterministic allowed-claim validation (logical DoS)",
"details" : "## Impact\n\nUsing certain modifiers on RegExp objects in the allowedAud, allowedIss, allowedSub, allowedJti, or allowedNonce options in verify functions can cause certain unintended behaviours. This is because some modifiers are stateful and will cause failures in every second verification attempt regardless of the validity of the token provided.\n\nSuch modifiers are:\n- /g : Global matching\n- /y : Sticky matching\n\nThis does NOT allow invalid tokens to be accepted, only for valid tokens to be improperly rejected in some configurations. Instead it causes **50% of valid authentication requests to fail** in an alternating pattern, leading to:\n - Intermittent user authentication failures\n - Potential retry storms in applications\n - Operational monitoring alerts\n\n## Affected Configurations\n\n### This vulnerability ONLY affects applications that:\n\n- Use RegExp objects (not strings) in the allowedAud, allowedIss, allowedSub, allowedJti, or allowedNonce options\n- Use stateful RegExp modifiers such a /g or /y\n\nExample: allowedAud: /abc/g ← IMPACTED\nExample: allowedAud: \"/abc/\" ← SAFE\n\n### Not Affected\n\n- Applications using string patterns for audience validation (most common)\n- Applications using RegExp patterns without stateful modifiers\n\n### Assessment Guide\nTo determine if you're affected:\n\nCheck if allowedAud, allowedIss, allowedSub, allowedJti, or allowedNonce options use RegExp objects (/pattern/ or new RegExp())\nIf yes, review the pattern for stateful modifiers like /g, /y\nIf no RegExp usage or no stateful modifiers, you are NOT affected\n\n## Mitigation Options\nWhile a fix will be coming in the next version of the package you can take steps to mitigate the issue immediately by removing any such modifiers (/g, /y) from the regex.\n\n---\n\nSummary\n\nfast-jwt accepts RegExp for allowedAud, allowedIss, allowedSub, allowedJti, and allowedNonce.\n\nIf the provided regular expression uses the g (global) or y (sticky) flag, verification becomes non-deterministic: the same valid token alternates between acceptance and rejection across successive calls.\n\nThis occurs because RegExp.prototype.test() is stateful when g/y is set (it mutates lastIndex), and fast-jwt reuses the same RegExp object without resetting lastIndex.\n\n\nAffected component\n\nsrc/verifier.js\n\nensureStringClaimMatcher() returns the RegExp object directly.\n\nvalidateClaimValues() performs repeated a.test(v) calls without resetting lastIndex.\n\n\nImpact\n\nLogical denial-of-service / authentication flapping.\n\nA valid signed JWT can be intermittently rejected.\n\nCauses unpredictable authentication outcomes across repeated verification calls.\n\nCan trigger retry storms and cascading failures in API gateways and authentication middleware.\n\nAffects any deployment that configures allowed* using RegExp and includes g or y flags.\n\n\nRoot cause\n\nvalidateClaimValues() uses: allowed.some(a => a.test(v))\n\n\nWhen `a` is a RegExp with g or y, `a.test()` mutates `a.lastIndex`.\n\nSubsequent calls against the same input can return different results.\n\n\nProof of concept\n\nEnvironment\n\n- fast-jwt: 6.1.0 (repo HEAD)\n- Node.js: v24.13.1\n\nPoC\nconst { createSigner, createVerifier } = require('fast-jwt')\n\nconst sign = createSigner({ key: 'secret' })\nconst token = sign({ aud: 'admin', iss: 'issuer' })\n\nfunction run(name, opts) {\nconst verify = createVerifier({ key: 'secret', ...opts })\nconsole.log('\\n==', name)\nfor (let i = 0; i < 8; i++) {\ntry { verify(token); console.log(i, 'PASS') }\ncatch (e) { console.log(i, 'FAIL', e.code || e.message) }\n}\n}\n\nrun('allowedAud global regex', { allowedAud: /^admin$/g })\nrun('allowedIss global regex', { allowedIss: /^issuer$/g })\nrun('control (non-global regex)', { allowedAud: /^admin$/ })\n\n\n\nObserved behavior\n\n- allowedAud with `/g` alternates PASS/FAIL across calls\n- allowedIss with `/g` alternates PASS/FAIL across calls\n- control regex (no g/y) is deterministic and always PASS\n\n\nExpected behavior\n\nValidation must be deterministic.\n\nThe same token under the same verifier configuration must always yield the same decision.\n\n\nSuggested fix (minimal and safe)\n\nWrap RegExp matchers inside ensureStringClaimMatcher() to reset lastIndex before calling test():\nif (r instanceof RegExp) {\nreturn { test: v => { r.lastIndex = 0; return r.test(v) } }\n}\n\n\nThis preserves semantics for non-global regexes, makes g/y deterministic, and avoids changes in the rest of the verifier logic.\n\n\nSecurity classification\n\nLogical DoS / authentication reliability failure.\n\nThis can be weaponized to produce production outages via retry storms and auth instability.\n\n\nWhy this is not “misuse”\n\n- The library explicitly accepts RegExp for allowed* claim validation.\n- The behavior difference is caused by internal state mutation of RegExp.test().\n- The same token, same verifier config, same runtime yields different outcomes.\n- Security decisions must be deterministic; non-determinism at the verification layer is a correctness flaw.\n- Consumers cannot reliably defend against this unless the library normalizes matcher state.\n\n\nNotes\n\n- Affects allowedAud, allowedIss, allowedSub, allowedJti, allowedNonce equally (shared matcher logic).\n- Independent from the previously reported ReDoS; this is a determinism and correctness failure that can still produce production DoS effects.\n\n\nPoC Code:\n'use strict'\n\n/**\n * PoC: Stateful RegExp flags (g/y) cause non-deterministic allowed-claim validation\n * fast-jwt reuses the same RegExp object; RegExp.test() mutates lastIndex when g/y is set.\n *\n * This script prints a human-readable log AND writes evidence to JSON.\n *\n * Usage:\n * node poc_regex_state_evidence.js\n */\n\nconst fs = require('node:fs')\nconst path = require('node:path')\nconst { createSigner, createVerifier } = require('fast-jwt')\n\nconst OUT_JSON = path.join(process.cwd(), 'evidence-regex-stateful-fastjwt.json')\nconst OUT_LOG = path.join(process.cwd(), 'evidence-regex-stateful-fastjwt.log')\n\n// Make a stable, valid token\nconst sign = createSigner({ key: 'secret' })\nconst token = sign({\n aud: 'admin',\n iss: 'issuer',\n sub: 'subject',\n jti: 'id-123',\n nonce: 'nonce-xyz'\n})\n\nfunction runCase(name, verifierOpts, iterations = 12) {\n const verify = createVerifier({ key: 'secret', ...verifierOpts })\n\n const results = []\n for (let i = 0; i < iterations; i++) {\n try {\n verify(token)\n results.push({ i, ok: true })\n } catch (e) {\n results.push({ i, ok: false, code: e.code || null, message: e.message || String(e) })\n }\n }\n\n return results\n}\n\nfunction summarize(results) {\n const seq = results.map(r => (r.ok ? 'PASS' : 'FAIL')).join(' ')\n const pass = results.filter(r => r.ok).length\n const fail = results.length - pass\n return { pass, fail, seq }\n}\n\nfunction printCase(name, opts, results) {\n const s = summarize(results)\n const lines = []\n lines.push(`== ${name}`)\n lines.push(`opts: ${JSON.stringify(opts)}`)\n lines.push(`PASS=${s.pass} FAIL=${s.fail}`)\n lines.push(`sequence: ${s.seq}`)\n lines.push('')\n return lines.join('\\n')\n}\n\nfunction main() {\n const meta = {\n poc: 'stateful-regexp-allowed-claims',\n package: 'fast-jwt',\n node: process.version,\n timestamp: new Date().toISOString(),\n note: 'RegExp.test is stateful when g/y flags are set; lastIndex mutation causes alternating PASS/FAIL.'\n }\n\n // Cases: g/y should flap, control should be stable\n const cases = [\n {\n name: 'allowedAud with global RegExp /g (expected: flapping)',\n opts: { allowedAud: /^admin$/g }\n },\n {\n name: 'allowedAud with sticky RegExp /y (expected: flapping)',\n opts: { allowedAud: /^admin$/y }\n },\n {\n name: 'allowedIss with global RegExp /g (expected: flapping)',\n opts: { allowedIss: /^issuer$/g }\n },\n {\n name: 'allowedSub with global RegExp /g (expected: flapping)',\n opts: { allowedSub: /^subject$/g }\n },\n {\n name: 'allowedJti with global RegExp /g (expected: flapping)',\n opts: { allowedJti: /^id-123$/g }\n },\n {\n name: 'allowedNonce with global RegExp /g (expected: flapping)',\n opts: { allowedNonce: /^nonce-xyz$/g }\n },\n {\n name: 'CONTROL: allowedAud with non-global RegExp (expected: stable PASS)',\n opts: { allowedAud: /^admin$/ }\n }\n ]\n\n const evidence = {\n meta,\n token: {\n alg: 'HS256 (autodetected by fast-jwt)',\n signed: true,\n jwt: token\n },\n cases: []\n }\n\n let log = ''\n for (const c of cases) {\n const results = runCase(c.name, c.opts, 12)\n const s = summarize(results)\n\n evidence.cases.push({\n name: c.name,\n opts: c.opts,\n iterations: results.length,\n pass: s.pass,\n fail: s.fail,\n sequence: s.seq,\n results\n })\n\n log += printCase(c.name, c.opts, results)\n }\n\n fs.writeFileSync(OUT_JSON, JSON.stringify(evidence, null, 2))\n fs.writeFileSync(OUT_LOG, log)\n\n console.log(log)\n console.log(`[+] Wrote JSON evidence: ${OUT_JSON}`)\n console.log(`[+] Wrote LOG evidence : ${OUT_LOG}`)\n}\n\nmain()\n\n\nOutput:\nPS C:\\Users\\Franciny Rojas\\Desktop\\crypto-research\\fast-jwt> node .\\poc_regex_state_evidence.js\n== allowedAud with global RegExp /g (expected: flapping)\nopts: {\"allowedAud\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== allowedAud with sticky RegExp /y (expected: flapping)\nopts: {\"allowedAud\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== allowedIss with global RegExp /g (expected: flapping)\nopts: {\"allowedIss\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== allowedSub with global RegExp /g (expected: flapping)\nopts: {\"allowedSub\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== allowedJti with global RegExp /g (expected: flapping)\nopts: {\"allowedJti\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== allowedNonce with global RegExp /g (expected: flapping)\nopts: {\"allowedNonce\":{}}\nPASS=6 FAIL=6\nsequence: PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL PASS FAIL\n== CONTROL: allowedAud with non-global RegExp (expected: stable PASS)\nopts: {\"allowedAud\":{}}\nPASS=12 FAIL=0\nsequence: PASS PASS PASS PASS PASS PASS PASS PASS PASS PASS PASS PASS\n\n[+] Wrote JSON evidence: C:\\Users\\Franciny Rojas\\Desktop\\crypto-research\\fast-jwt\\evidence-regex-stateful-fastjwt.json\n[+] Wrote LOG evidence : C:\\Users\\Franciny Rojas\\Desktop\\crypto-research\\fast-jwt\\evidence-regex-stateful-fastjwt.log\nPS C:\\Users\\Franciny Rojas\\Desktop\\crypto-research\\fast-jwt>",
"severity" : [ {
"type" : "CVSS_V3",
"score" : "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "fast-jwt"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "6.2.1"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/nearform/fast-jwt/security/advisories/GHSA-3j8v-cgw4-2g6q"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-35040"
}, {
"type" : "WEB",
"url" : "https://github.com/nearform/fast-jwt/pull/593"
}, {
"type" : "WEB",
"url" : "https://github.com/nearform/fast-jwt/commit/18d25904e4617e8753526d1b3ab5a2cccdea726a"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/nearform/fast-jwt"
}, {
"type" : "WEB",
"url" : "https://github.com/nearform/fast-jwt/releases/tag/v6.2.1"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-440", "CWE-697" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-04-09T16:41:20Z",
"nvd_published_at" : "2026-04-09T16:16:27Z"
}
}