fast-jwt: Stateful RegExp (/g or /y) causes non-deterministic allowed-claim validation (logical DoS)
Using 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.
Such modifiers are:
This 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:
Example: allowedAud: /abc/g ← IMPACTED
Example: allowedAud: "/abc/" ← SAFE
To determine if you're affected:
Check if allowedAud, allowedIss, allowedSub, allowedJti, or allowedNonce options use RegExp objects (/pattern/ or new RegExp())
If yes, review the pattern for stateful modifiers like /g, /y
If no RegExp usage or no stateful modifiers, you are NOT affected
While 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.
Summary
fast-jwt accepts RegExp for allowedAud, allowedIss, allowedSub, allowedJti, and allowedNonce.
If 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.
This 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.
Affected component
src/verifier.js
ensureStringClaimMatcher() returns the RegExp object directly.
validateClaimValues() performs repeated a.test(v) calls without resetting lastIndex.
Impact
Logical denial-of-service / authentication flapping.
A valid signed JWT can be intermittently rejected.
Causes unpredictable authentication outcomes across repeated verification calls.
Can trigger retry storms and cascading failures in API gateways and authentication middleware.
Affects any deployment that configures allowed* using RegExp and includes g or y flags.
Root cause
validateClaimValues() uses: allowed.some(a => a.test(v))
When a is a RegExp with g or y, a.test() mutates a.lastIndex.
Subsequent calls against the same input can return different results.
Proof of concept
Environment
PoC
const { createSigner, createVerifier } = require('fast-jwt')
const sign = createSigner({ key: 'secret' })
const token = sign({ aud: 'admin', iss: 'issuer' })
function run(name, opts) {
const verify = createVerifier({ key: 'secret', ...opts })
console.log('\n==', name)
for (let i = 0; i < 8; i++) {
try { verify(token); console.log(i, 'PASS') }
catch (e) { console.log(i, 'FAIL', e.code || e.message) }
}
}
run('allowedAud global regex', { allowedAud: /^admin$/g })
run('allowedIss global regex', { allowedIss: /^issuer$/g })
run('control (non-global regex)', { allowedAud: /^admin$/ })
Observed behavior
/g alternates PASS/FAIL across calls/g alternates PASS/FAIL across callsExpected behavior
Validation must be deterministic.
The same token under the same verifier configuration must always yield the same decision.
Suggested fix (minimal and safe)
Wrap RegExp matchers inside ensureStringClaimMatcher() to reset lastIndex before calling test():
if (r instanceof RegExp) {
return { test: v => { r.lastIndex = 0; return r.test(v) } }
}
This preserves semantics for non-global regexes, makes g/y deterministic, and avoids changes in the rest of the verifier logic.
Security classification
Logical DoS / authentication reliability failure.
This can be weaponized to produce production outages via retry storms and auth instability.
Why this is not “misuse”
This issue can be reached over the network, attack complexity is low, an attacker needs no privileges on the target. No user interaction is required. The scope is unchanged, so the impact stays within the vulnerable component. Rated impact: confidentiality none, integrity none, availability low.
The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
CVE-2026-35040 is classified as CWE-440: Expected Behavior Violation. A feature, API, or function does not perform according to its specification.
CVE-2026-35040 is recorded against 1 package.
Published on 9 April 2026 and last revised on 17 June 2026. A public exploit is known to exist, which raises the urgency of patching considerably. A vendor advisory or fix has been published. Record sourced from OSV.
github.com (Web)
nvd.nist.gov (Advisory)
github.com (Web)
github.com (Web)
github.com (Package)
github.com (Web)
fast-jwt has other advisories on record. If you are patching this one, these are worth checking on the same host:
These advisories are the same class of weakness (CWE-440: Expected Behavior Violation) in other software:
Details
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:N/A:L
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| fast-jwt | — | — |
References
Similar Threats
Exploit Protection
CVE-2026-35040 carries CVSS 5.3 Medium rating and a public exploit already exists. BotEraser checks your installation against this and other known CVE records, and blocks IPs associated with exploit activity.
Check My Site For CVE-2026-35040 →No credit card required · Results in minutes
ⓘ Data Notice: The information presented above has been compiled from publicly available internet sources. Boteraser aggregates this data solely for informational purposes and does not independently classify, evaluate, or endorse any findings about the vulnerabilities listed. The accuracy and completeness of this information is the sole responsibility of the original publishers. Boteraser and its operators accept no liability for any decisions made based on this data.
Stay up to date with the latest from Boteraser.
We use cookies to improve your experience on our site. By using our site, you consent to cookies.
Manage your cookie preferences below:
Essential cookies enable basic functions and are necessary for the proper function of the website.
CloudFlare provides web performance and security solutions, enhancing site speed and protecting against threats.
Service URL: developers.cloudflare.com (opens in a new window)
These cookies are needed for adding comments on this website.
These cookies are used for managing login functionality on this website.
Statistics cookies collect information anonymously. This information helps us understand how visitors use our website.
Google Analytics is a powerful tool that tracks and analyzes website traffic for informed marketing decisions.
Service URL: policies.google.com (opens in a new window)
You can find more information in our Cookie Policy and Privacy Policy.