Skip to content

Commit

Permalink
fix(node): respect x-forwarded for client id
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 25, 2024
1 parent 7722716 commit 3f8bd0c
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/adapters/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 3f8bd0c

Please sign in to comment.