Commit 70317f71a0b for nodejs

commit 70317f71a0bf7ead66bed951cba881f87cb0a43e
Author: James M Snell <jasnell@gmail.com>
Date:   Fri Nov 27 23:02:46 2026 +0000

    net: enable DTLS 1.3 by default

    Assisted-by: Claude Opus 5.5
    Signed-off-by: James M Snell <jasnell@gmail.com>
    PR-URL: https://github.com/nodejs/node/pull/67837
    Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
    Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>

diff --git a/doc/api/dtls.md b/doc/api/dtls.md
index 571c5722fa5..d625ae3bb23 100644
--- a/doc/api/dtls.md
+++ b/doc/api/dtls.md
@@ -71,7 +71,8 @@ added: v26.9.0
 changes:
   - version: REPLACEME
     pr-url: https://github.com/nodejs/node/pull/00000
-    description: Added the `minVersion` and `maxVersion` options.
+    description: Added DTLS 1.3, enabled by default, and the `minVersion`
+                 and `maxVersion` options.
 -->

 * `callback` {Function} Called for each new DTLS session accepted by the
@@ -100,8 +101,7 @@ changes:
   * `minVersion` {string} The oldest protocol version to accept, `'DTLSv1.2'`
     or `'DTLSv1.3'`. **Default:** `'DTLSv1.2'`. See [Protocol versions][].
   * `maxVersion` {string} The newest protocol version to offer, `'DTLSv1.2'`
-    or `'DTLSv1.3'`. **Default:** `'DTLSv1.2'`, or `minVersion` if that is
-    newer.
+    or `'DTLSv1.3'`. **Default:** `'DTLSv1.3'`.
   * `alpn` {string\[]|Buffer} ALPN protocol names. Each name must be between
     1 and 255 bytes. A `Buffer` must already be in ALPN wire format: one
     length byte followed by that many bytes, repeated.
@@ -184,7 +184,8 @@ added: v26.9.0
 changes:
   - version: REPLACEME
     pr-url: https://github.com/nodejs/node/pull/00000
-    description: Added the `minVersion` and `maxVersion` options.
+    description: Added DTLS 1.3, enabled by default, and the `minVersion`
+                 and `maxVersion` options.
 -->

 * `host` {string} Remote host to connect to, as an IPv4 or IPv6 literal.
@@ -229,8 +230,7 @@ changes:
   * `minVersion` {string} The oldest protocol version to accept, `'DTLSv1.2'`
     or `'DTLSv1.3'`. **Default:** `'DTLSv1.2'`. See [Protocol versions][].
   * `maxVersion` {string} The newest protocol version to offer, `'DTLSv1.2'`
-    or `'DTLSv1.3'`. **Default:** `'DTLSv1.2'`, or `minVersion` if that is
-    newer.
+    or `'DTLSv1.3'`. **Default:** `'DTLSv1.3'`.
   * `mtu` {number} Maximum size in bytes of a DTLS datagram. **Default:**
     `1200`.
   * `handshakeTimeout` {number} Milliseconds a handshake may take before it is
@@ -264,7 +264,8 @@ added: v26.10.0
 changes:
   - version: REPLACEME
     pr-url: https://github.com/nodejs/node/pull/00000
-    description: Added the `minVersion` and `maxVersion` options.
+    description: Added DTLS 1.3, enabled by default, and the `minVersion`
+                 and `maxVersion` options.
 -->

 * `options` {Object}
@@ -354,17 +355,18 @@ DTLS 1.2 ([RFC 6347][]) and DTLS 1.3 ([RFC 9147][]) are supported. DTLS 1.0 is
 not: it is deprecated by [RFC 8996][] and has no AEAD cipher suites. Each side
 offers the range from `minVersion` to `maxVersion`, and the newest version both
 allow is negotiated; with none in common the handshake fails with a
-`protocol_version` alert. Only DTLS 1.2 is enabled by default.
+`protocol_version` alert. Both versions are enabled by default.

 ```mjs
 import { connect, listen } from 'node:dtls';

-const endpoint = listen(onsession, {
-  cert, key, port: 5684, maxVersion: 'DTLSv1.3',
-});
+const endpoint = listen(onsession, { cert, key, port: 5684 });

-const session = connect('192.0.2.1', 5684, { ca, maxVersion: 'DTLSv1.3' });
+const session = connect('192.0.2.1', 5684, { ca });
 const { protocol } = await session.opened;   // 'DTLSv1.3'
+
+// A peer that only speaks DTLS 1.2 is still served; to offer only that:
+const legacy = connect('192.0.2.2', 5684, { ca, maxVersion: 'DTLSv1.2' });
 ```

 What changes under DTLS 1.3:
diff --git a/lib/internal/dtls/dtls.js b/lib/internal/dtls/dtls.js
index efd7dd50d67..7ffb3567930 100644
--- a/lib/internal/dtls/dtls.js
+++ b/lib/internal/dtls/dtls.js
@@ -1057,7 +1057,7 @@ function createContext(options = kEmptyObject) {
 const kProtocolVersions = ['DTLSv1.2', 'DTLSv1.3'];
 const kProtocolVersionValues = [DTLS1_2_VERSION_VALUE, DTLS1_3_VERSION_VALUE];
 const kDefaultMinVersion = 'DTLSv1.2';
-const kDefaultMaxVersion = 'DTLSv1.2';
+const kDefaultMaxVersion = 'DTLSv1.3';

 // Validate minVersion and maxVersion and return them as indices into
 // kProtocolVersions.
diff --git a/test/parallel/test-dtls-version.mjs b/test/parallel/test-dtls-version.mjs
index 73ff9a6998c..eb10c0e0f3b 100644
--- a/test/parallel/test-dtls-version.mjs
+++ b/test/parallel/test-dtls-version.mjs
@@ -71,9 +71,16 @@ for (const [server, client, expected] of [
 await assert.rejects(negotiate(V12, V13), /unsupported protocol/);
 await assert.rejects(negotiate(V13, V12), /protocol version/);

-// The default is DTLS 1.2 on both sides.
-assert.strictEqual(await negotiate({}, BOTH), 'DTLSv1.2');
-assert.strictEqual(await negotiate(BOTH, {}), 'DTLSv1.2');
+// The default is DTLS 1.2 through 1.3 on both sides.
+assert.strictEqual(await negotiate({}, {}), 'DTLSv1.3');
+assert.strictEqual(await negotiate({}, V12), 'DTLSv1.2');
+assert.strictEqual(await negotiate(V12, {}), 'DTLSv1.2');
+assert.strictEqual(await negotiate({}, V13), 'DTLSv1.3');
+assert.strictEqual(await negotiate(V13, {}), 'DTLSv1.3');
+
+// Lowering only the ceiling is enough to stay on DTLS 1.2.
+assert.strictEqual(await negotiate({ maxVersion: 'DTLSv1.2' }, {}),
+                   'DTLSv1.2');

 // A secure context carries the range.
 {
@@ -108,7 +115,7 @@ assert.throws(
   () => createSecureContext({ minVersion: 'DTLSv1.3', maxVersion: 'DTLSv1.2' }),
   { code: 'ERR_INVALID_ARG_VALUE', message: /must not be newer/ });

-// Raising only the floor raises the default ceiling with it.
+// Raising only the floor is enough to require DTLS 1.3.
 assert.strictEqual(await negotiate({ minVersion: 'DTLSv1.3' }, BOTH),
                    'DTLSv1.3');
 await assert.rejects(negotiate({ minVersion: 'DTLSv1.3' }, V12),