From 3f8bd0c8ee29fbf754cd5eebf5b5f2c81faaafcc Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 25 Feb 2024 21:38:44 +0100 Subject: [PATCH] fix(node): respect `x-forwarded` for client id --- src/adapters/node.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/adapters/node.ts b/src/adapters/node.ts index a1f6857..ef6f994 100644 --- a/src/adapters/node.ts +++ b/src/adapters/node.ts @@ -119,11 +119,13 @@ class NodePeer extends Peer<{ if (!socket) { return undefined; } - const addr = - socket.remoteFamily === "IPv6" - ? `[${socket.remoteAddress}]` - : socket.remoteAddress; - return `${addr}:${socket.remotePort}`; + const headers = this.ctx.node.req.headers; + let addr = headers["x-forwarded-for"] || socket.remoteAddress || "??"; + if (addr.includes(":")) { + addr = `[${addr}]`; + } + const port = headers["x-forwarded-port"] || socket.remotePort || "??"; + return `${addr}:${port}`; } get url() {