Commit d5943f5ae9e for nodejs

commit d5943f5ae9e21a08fb83a211115d2a5f414c6390
Author: James M Snell <jasnell@gmail.com>
Date:   Sat Dec 5 08:27:44 2026 -0800

    tls: add --tls-groups command-line option

    Set tls.DEFAULT_ECDH_CURVE from the command line or NODE_OPTIONS.

    Assisted-by: Claude Opus 5.5
    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67993
    Reviewed-By: Tim Perry <pimterry@gmail.com>
    Reviewed-By: Filip Skokan <panva.ip@gmail.com>

diff --git a/doc/api/cli.md b/doc/api/cli.md
index 293c5286aa6..606e86f4e3e 100644
--- a/doc/api/cli.md
+++ b/doc/api/cli.md
@@ -3620,6 +3620,15 @@ added: v4.0.0
 Specify an alternative default TLS cipher list. Requires Node.js to be built
 with crypto support (default).

+### `--tls-groups=list`
+
+<!-- YAML
+added: REPLACEME
+-->
+
+Set [`tls.DEFAULT_ECDH_CURVE`][], the default colon-separated list of TLS
+groups used for key agreement. **Default:** `'auto'`.
+
 ### `--tls-keylog=file`

 <!-- YAML
@@ -4513,6 +4522,7 @@ one is included in the list below.
 * `--throw-deprecation`
 * `--title`
 * `--tls-cipher-list`
+* `--tls-groups`
 * `--tls-keylog`
 * `--tls-max-v1.2`
 * `--tls-max-v1.3`
@@ -5107,6 +5117,7 @@ node --stack-trace-limit=12 -p -e "Error.stackTraceLimit" # prints 12
 [`permission.drop()`]: permissions.md#permissiondropscope-reference
 [`process.setUncaughtExceptionCaptureCallback()`]: process.md#processsetuncaughtexceptioncapturecallbackfn
 [`session.connectToMainThread()`]: inspector.md#sessionconnecttomainthread
+[`tls.DEFAULT_ECDH_CURVE`]: tls.md#tlsdefault_ecdh_curve
 [`tls.DEFAULT_MAX_VERSION`]: tls.md#tlsdefault_max_version
 [`tls.DEFAULT_MIN_VERSION`]: tls.md#tlsdefault_min_version
 [`unhandledRejection`]: process.md#event-unhandledrejection
diff --git a/doc/api/tls.md b/doc/api/tls.md
index 484b0bdb6d1..52f183f7894 100644
--- a/doc/api/tls.md
+++ b/doc/api/tls.md
@@ -2596,8 +2596,9 @@ changes:
 -->

 The default named curve or TLS group list to use for key agreement in a TLS
-server. The default value is `'auto'`. See [`tls.createSecureContext()`][] for
-further information.
+server. The default value is `'auto'`, or the value of the [`--tls-groups`][]
+command-line option. See [`tls.createSecureContext()`][] for further
+information.

 ## `tls.DEFAULT_MAX_VERSION`

@@ -2673,6 +2674,7 @@ added: v0.11.3
 [`'session'`]: #event-session
 [`'tlsClientError'`]: #event-tlsclienterror
 [`--tls-cipher-list`]: cli.md#--tls-cipher-listlist
+[`--tls-groups`]: cli.md#--tls-groupslist
 [`--use-bundled-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
 [`--use-openssl-ca`]: cli.md#--use-bundled-ca---use-openssl-ca
 [`--use-system-ca`]: cli.md#--use-system-ca
diff --git a/doc/node-config-schema.json b/doc/node-config-schema.json
index 098bae8efd3..160ad48e59d 100644
--- a/doc/node-config-schema.json
+++ b/doc/node-config-schema.json
@@ -791,6 +791,10 @@
               "type": "string",
               "description": "use an alternative default TLS cipher list"
             },
+            "tls-groups": {
+              "type": "string",
+              "description": "set the default TLS key exchange group list (default: auto)"
+            },
             "tls-keylog": {
               "type": "string",
               "description": "log TLS decryption keys to named file for traffic analysis"
diff --git a/doc/node.1 b/doc/node.1
index c7b49c61603..bd9095df799 100644
--- a/doc/node.1
+++ b/doc/node.1
@@ -1810,6 +1810,10 @@ Set \fBprocess.title\fR on startup.
 Specify an alternative default TLS cipher list. Requires Node.js to be built
 with crypto support (default).
 .
+.It Fl -tls-groups Ns = Ns Ar list
+Set \fBtls.DEFAULT_ECDH_CURVE\fR, the default colon-separated list of TLS
+groups used for key agreement. \fBDefault:\fR \fB'auto'\fR.
+.
 .It Fl -tls-keylog Ns = Ns Ar file
 Log TLS key material to a file. The key material is in NSS \fBSSLKEYLOGFILE\fR
 format and can be used by software (such as Wireshark) to decrypt the TLS
@@ -2546,6 +2550,8 @@ one is included in the list below.
 .It
 \fB--tls-cipher-list\fR
 .It
+\fB--tls-groups\fR
+.It
 \fB--tls-keylog\fR
 .It
 \fB--tls-max-v1.2\fR
diff --git a/lib/tls.js b/lib/tls.js
index 13171847c7e..ee6c34daea7 100644
--- a/lib/tls.js
+++ b/lib/tls.js
@@ -112,7 +112,7 @@ defineRenegotiationLimit('CLIENT_RENEG_WINDOW', 'window');

 exports.DEFAULT_CIPHERS = getOptionValue('--tls-cipher-list');

-exports.DEFAULT_ECDH_CURVE = 'auto';
+exports.DEFAULT_ECDH_CURVE = getOptionValue('--tls-groups');

 if (getOptionValue('--tls-min-v1.0'))
   exports.DEFAULT_MIN_VERSION = 'TLSv1';
diff --git a/src/node_options.cc b/src/node_options.cc
index cece3acc4a9..79d60c2b854 100644
--- a/src/node_options.cc
+++ b/src/node_options.cc
@@ -1509,6 +1509,11 @@ EnvironmentOptionsParser::EnvironmentOptionsParser() {

   AddOption("--napi-modules", "", NoOp{}, kAllowedInEnvvar);

+  AddOption("--tls-groups",
+            "set the default TLS key exchange group list (default: auto)",
+            &EnvironmentOptions::tls_groups,
+            kAllowedInEnvvar);
+
   AddOption("--tls-keylog",
             "log TLS decryption keys to named file for traffic analysis",
             &EnvironmentOptions::tls_keylog,
diff --git a/src/node_options.h b/src/node_options.h
index 6392c39cd3d..00c6eeb50de 100644
--- a/src/node_options.h
+++ b/src/node_options.h
@@ -153,6 +153,7 @@ class EnvironmentOptions : public Options {
   std::string unhandled_rejections;
   std::string watch_mode_kill_signal = "SIGTERM";
   std::string eval_string;
+  std::string tls_groups = "auto";
   std::string tls_keylog;
   std::string config_file_path;
   std::string experimental_package_map_path;
diff --git a/test/parallel/test-tls-groups-cli.js b/test/parallel/test-tls-groups-cli.js
new file mode 100644
index 00000000000..6a1a40fb7f0
--- /dev/null
+++ b/test/parallel/test-tls-groups-cli.js
@@ -0,0 +1,47 @@
+'use strict';
+const common = require('../common');
+if (!common.hasCrypto)
+  common.skip('missing crypto');
+
+// Test that --tls-groups sets tls.DEFAULT_ECDH_CURVE.
+
+const { spawnSyncAndAssert } = require('../common/child_process');
+const fixtures = require('../common/fixtures');
+
+spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], {
+  stdout: 'auto',
+  trim: true,
+});
+
+spawnSyncAndAssert(process.execPath,
+                   ['--tls-groups=P-384:P-256', '-p', 'tls.DEFAULT_ECDH_CURVE'],
+                   { stdout: 'P-384:P-256', trim: true });
+
+if (!process.config.variables.node_without_node_options) {
+  spawnSyncAndAssert(process.execPath, ['-p', 'tls.DEFAULT_ECDH_CURVE'], {
+    env: { ...process.env, NODE_OPTIONS: '--tls-groups=P-384' },
+  }, { stdout: 'P-384', trim: true });
+}
+
+// The option applies to servers and clients that do not set ecdhCurve.
+const script = `
+  const tls = require('tls');
+  const server = tls.createServer({
+    key: ${JSON.stringify(fixtures.readKey('agent2-key.pem', 'utf8'))},
+    cert: ${JSON.stringify(fixtures.readKey('agent2-cert.pem', 'utf8'))},
+  }, (conn) => conn.end());
+  server.listen(0, () => {
+    const client = tls.connect({
+      port: server.address().port,
+      rejectUnauthorized: false,
+    }, () => {
+      console.log(client.getEphemeralKeyInfo().name);
+      client.end();
+      server.close();
+    });
+  });
+`;
+spawnSyncAndAssert(process.execPath, ['--tls-groups=P-384', '-e', script], {
+  stdout: 'secp384r1',
+  trim: true,
+});