From ad94073ae7dbe400d243dbafde420948b3b7e703 Mon Sep 17 00:00:00 2001 From: Tim Perry <1526883+pimterry@users.noreply.github.com> Date: Mon, 19 Oct 2026 14:35:59 +0200 Subject: [PATCH] tls: add tlsSocket.socket, to access the raw stream beneath TLS Signed-off-by: Tim Perry PR-URL: https://github.com/nodejs/node/pull/66598 Reviewed-By: Luigi Pinca --- doc/api/tls.md | 23 ++++++++ lib/internal/tls/wrap.js | 2 + .../test-tls-socket-underlying-socket.js | 57 +++++++++++++++++++ 3 files changed, 82 insertions(+) create mode 100644 test/parallel/test-tls-socket-underlying-socket.js diff --git a/doc/api/tls.md b/doc/api/tls.md index 36895df23d8..9fdc392c80b 100644 --- a/doc/api/tls.md +++ b/doc/api/tls.md @@ -1668,6 +1668,27 @@ and their processing can be delayed due to packet loss or reordering. However, smaller fragments add extra TLS framing bytes and CPU overhead, which may decrease overall server throughput. +### `tlsSocket.socket` + + + +* Type: {net.Socket|stream.Duplex|null} + +The underlying socket or stream that this socket reads and writes TLS data +through. This is the `socket` passed to [`new tls.TLSSocket()`][] or +[`tls.connect()`][], or the connection given to a [`tls.Server`][] by its +`'connection'` event. + +This is only `null` for client sockets that manage their own connection, +created by [`tls.connect()`][] with a `port` or `path` rather than a `socket`. +Connection details such as `remoteAddress` are then available directly on this +socket. Server sockets always have an underlying socket. + +This remains available after the socket has been destroyed, for example to +identify the underlying connection from a [`'tlsClientError'`][] listener. + ## `tls.checkServerIdentity(hostname, cert)`