Skip to content

Treat Unix domain sockets as loopback - #72

Open
dyk1454683243-sudo wants to merge 1 commit into
jshttp:masterfrom
dyk1454683243-sudo:cursor/unix-socket-support-8ec2
Open

dyk1454683243-sudo wants to merge 1 commit into
jshttp:masterfrom
dyk1454683243-sudo:cursor/unix-socket-support-8ec2

Conversation

@dyk1454683243-sudo

Copy link
Copy Markdown

When an app listens on a Unix domain socket, Node.js leaves req.socket.remoteAddress unset. forwarded then puts undefined at the front of the address list, and compiled trust functions reject it (!isip(addr)), so no hop is trusted and X-Forwarded-For is ignored.

This treats a confirmed IPC connection as 127.0.0.1 so a loopback (or 127.0.0.1) trust configuration works, as suggested in #9.

Detection uses the documented Node.js IPC signal: server.address() returns a string (the socket or pipe path). Some Node versions also expose socket.address().path. A missing remoteAddress on a TCP socket is still untrusted — Doug noted that TCP can also yield undefined, so we do not assume every missing address is a Unix socket.

Skipping invalid entries was considered and rejected: that would honor X-Forwarded-For when a TCP socket has no remoteAddress, which the existing tests correctly treat as untrusted.

Tests cover mocked Unix sockets, a live HTTP server on a Unix socket, and the existing TCP-undefined cases.

Fixes #9

When an app listens on a Unix socket, remoteAddress is undefined, so
trust checks fail and X-Forwarded-For is ignored. Detect IPC via
server.address() (a string path) and substitute 127.0.0.1 so loopback
trust works. Generic missing remoteAddress on TCP stays untrusted.

Fixes jshttp#9

Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unix socket support

2 participants