Skip to content

[Vulnerability] nodejs/node: Prototype Pollution #414

Open

Description

@github-actions

Potential Security Vulnerability Detected

Repository: nodejs/node
Commit: 800f582
Author: Jonathan Lopes
Date: 2026-04-23T17:20:28Z

Commit Message

crypto: reject inherited key type names

Use an own-property check when dispatching generateKeyPair's NID-only
algorithm table

Fixes: https://github.com/nodejs/node/issues/62874
Signed-off-by: Jonathan Lopes <jonathan15989@protonmail.com>
PR-URL: https://github.com/nodejs/node/pull/62875
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>

Pull Request

PR: #62875 - crypto: reject inherited key type names
Labels: crypto, author ready, needs-ci, commit-queue-squash

Description:
Use an own-property check when dispatching generateKeyPair's NID-only algorithm table

Fixes: nodejs/node#62874

<!--
Before submitting a pull request, please read:

For code changes:

  1. Include tests for any bug fixes or new f...

Analysis

Vulnerability Type: Prototype Pollution
Severity: High

Description

The patch fixes a prototype pollution vulnerability where inherited properties (from Object.prototype) such as 'constructor' and 'toString' could be used as key type names in the crypto module's generateKeyPair function. By not using an 'own-property' check, the original code could mistakenly treat these special inherited properties as valid key types, potentially allowing attackers to bypass input validation or cause unexpected behavior in cryptographic key generation. The patch prevents this by initializing the lookup object with a null prototype and explicitly rejecting inherited properties as key types.

Affected Code

const nidOnlyKeyPairs = {
  'ed25519': EVP_PKEY_ED25519,
  'ed448': EVP_PKEY_ED448,
  'x25519': EVP_PKEY_X25519,
};

Proof of Concept

const crypto = require('crypto');

// The following invalid input uses 'constructor', an inherited property
crypto.generateKeyPair('constructor', {}, (err, publicKey, privateKey) => {
  if (err) {
    console.error('Unexpected acceptance of invalid key type:', err);
  } else {
    console.log('Security issue: generated keys with invalid type \"constructor\"');
  }
});

// Expected behavior before patch: no error; toxic key type accepted
// Expected behavior after patch: throws TypeError with message about invalid key type

This issue was automatically created by Vulnerability Spoiler Alert.
Detected at: 2026-04-23T18:00:36.162Z

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions