From 98e0f3dac41d2d722d2e6e7448ba6ca3ce0f4fbe Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Tue, 10 Nov 2026 21:13:27 -0700 Subject: [PATCH 1/4] net: expose peer name of pipe connections getpeername(2) on a Unix domain socket returns the path the peer is bound to, but the pipe handle had no getpeername method, so socket.remoteAddress was always undefined for pipe connections. Add getpeername to the pipe handle, backed by uv_pipe_getpeername(), so that socket.remoteAddress reports the listening path on the connecting side and the path of a bound client on the accepting side. It remains undefined for an unbound peer, and on Windows, where a named pipe has a single name rather than one per end. The server 'drop' data and BlockList check keyed off the presence of getpeername on the accepted handle, so restrict both to non-pipe handles to keep their behavior for pipe servers unchanged. Signed-off-by: Guy Bedford Assisted-by: Claude Fable 5.2 --- doc/api/net.md | 14 +++ lib/net.js | 6 +- src/pipe_wrap.cc | 47 ++++++++- src/pipe_wrap.h | 4 +- test/parallel/test-net-pipe-remote-address.js | 99 +++++++++++++++++++ 5 files changed, 165 insertions(+), 5 deletions(-) create mode 100644 test/parallel/test-net-pipe-remote-address.js diff --git a/doc/api/net.md b/doc/api/net.md index 0a3800f3b905..ce4ab711ec97 100644 --- a/doc/api/net.md +++ b/doc/api/net.md @@ -1602,6 +1602,10 @@ If the socket is `ref`ed calling `ref` again will have no effect. * Type: {string} @@ -1610,6 +1614,14 @@ The string representation of the remote IP address. For example, `'74.125.127.100'` or `'2001:4860:a005::68'`. Value may be `undefined` if the socket is destroyed (for example, if the client disconnected). +For a [Unix domain socket][IPC], this is the path the peer is bound to: the +listening path on the connecting side, and on the accepting side the path of a +client that was bound before connecting (see [`BoundSocket`][]). It is +`undefined` if the peer is not bound to a path, which is the case for most +clients. [`socket.remoteFamily`][] and [`socket.remotePort`][] are always +`undefined` for these connections, as is `socket.remoteAddress` for a Windows +named pipe. + ### `socket.remoteFamily` From d8378a6ef3e8cda2f1a90270d2dbc94fed543d40 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 18 Nov 2026 16:00:09 -0700 Subject: [PATCH 3/4] fixup! net: expose peer name of pipe connections Keep the http2 origin set from using a pipe's peer path as a host name, and apply clang-format. Signed-off-by: Guy Bedford Assisted-by: Claude Fable 5.2 --- lib/internal/http2/core.js | 6 ++- src/pipe_wrap.cc | 3 +- test/parallel/test-http2-pipe-origin-set.js | 47 +++++++++++++++++++++ 3 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 test/parallel/test-http2-pipe-origin-set.js diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 04acb5d30f63..32c51e907d40 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -765,10 +765,12 @@ function initOriginSet(session) { session[kState].originSet = originSet = new SafeSet(); let hostName = socket.servername; if (hostName === null || hostName === false) { - if (socket.remoteFamily === 'IPv6') { + // A pipe has no remote family, and its remote address is a path. + const { remoteFamily } = socket; + if (remoteFamily === 'IPv6') { hostName = `[${socket.remoteAddress}]`; } else { - hostName = socket.remoteAddress; + hostName = remoteFamily === undefined ? undefined : socket.remoteAddress; } } let originString = `https://${hostName}`; diff --git a/src/pipe_wrap.cc b/src/pipe_wrap.cc index ce60288de648..95b662614004 100644 --- a/src/pipe_wrap.cc +++ b/src/pipe_wrap.cc @@ -299,8 +299,7 @@ void PipeWrap::GetPeerName(const FunctionCallbackInfo& args) { // An unbound peer has an empty name, which leaves the address unset. if (err == 0 && size > 0) { Local name; - if (!String::NewFromUtf8( - env->isolate(), *buf, NewStringType::kNormal, size) + if (!String::NewFromUtf8(env->isolate(), *buf, NewStringType::kNormal, size) .ToLocal(&name) || args[0] .As() diff --git a/test/parallel/test-http2-pipe-origin-set.js b/test/parallel/test-http2-pipe-origin-set.js new file mode 100644 index 000000000000..56407f12bf3c --- /dev/null +++ b/test/parallel/test-http2-pipe-origin-set.js @@ -0,0 +1,47 @@ +'use strict'; + +const common = require('../common'); +if (!common.hasCrypto) + common.skip('missing crypto'); +const fixtures = require('../common/fixtures'); +const assert = require('assert'); +const http2 = require('http2'); +const tmpdir = require('../common/tmpdir'); + +tmpdir.refresh(); + +// Without a servername the origin set falls back to the peer address, which +// for a pipe is a path rather than a host and must not be used as one. + +function test(path) { + const server = http2.createSecureServer({ + key: fixtures.readKey('agent1-key.pem'), + cert: fixtures.readKey('agent1-cert.pem'), + }); + server.on('stream', common.mustCall((stream) => { + stream.respond(); + stream.end(); + })); + server.listen(path, common.mustCall(() => { + const client = http2.connect('https://127.0.0.1', { + path, + rejectUnauthorized: false, + }); + client.on('connect', common.mustCall(() => { + assert.strictEqual(client.socket.servername, false); + assert.deepStrictEqual(client.originSet, ['https://undefined']); + const req = client.request(); + req.resume(); + req.on('close', common.mustCall(() => { + client.close(); + server.close(); + })); + })); + })); +} + +test(`${common.PIPE}-origin-set`); + +if (common.isLinux) { + test(`\0node-test-origin-set-${process.pid}`); +} From dff163421e299b8b4c5be50482e571da2a2be019 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Wed, 18 Nov 2026 16:15:34 -0700 Subject: [PATCH 4/4] fixup! net: expose peer name of pipe connections Use localhost as the http2 origin host for a pipe without a servername. Signed-off-by: Guy Bedford Assisted-by: Claude Fable 5.2 --- lib/internal/http2/core.js | 2 +- test/parallel/test-http2-pipe-origin-set.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 32c51e907d40..12ec4b74dc00 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -770,7 +770,7 @@ function initOriginSet(session) { if (remoteFamily === 'IPv6') { hostName = `[${socket.remoteAddress}]`; } else { - hostName = remoteFamily === undefined ? undefined : socket.remoteAddress; + hostName = remoteFamily === undefined ? 'localhost' : socket.remoteAddress; } } let originString = `https://${hostName}`; diff --git a/test/parallel/test-http2-pipe-origin-set.js b/test/parallel/test-http2-pipe-origin-set.js index 56407f12bf3c..1fd9275e77ad 100644 --- a/test/parallel/test-http2-pipe-origin-set.js +++ b/test/parallel/test-http2-pipe-origin-set.js @@ -29,7 +29,7 @@ function test(path) { }); client.on('connect', common.mustCall(() => { assert.strictEqual(client.socket.servername, false); - assert.deepStrictEqual(client.originSet, ['https://undefined']); + assert.deepStrictEqual(client.originSet, ['https://localhost']); const req = client.request(); req.resume(); req.on('close', common.mustCall(() => {