Treat Unix domain sockets as loopback - #72
Open
dyk1454683243-sudo wants to merge 1 commit into
Open
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When an app listens on a Unix domain socket, Node.js leaves
req.socket.remoteAddressunset.forwardedthen putsundefinedat the front of the address list, and compiled trust functions reject it (!isip(addr)), so no hop is trusted andX-Forwarded-Foris ignored.This treats a confirmed IPC connection as
127.0.0.1so aloopback(or127.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 exposesocket.address().path. A missingremoteAddresson a TCP socket is still untrusted — Doug noted that TCP can also yieldundefined, so we do not assume every missing address is a Unix socket.Skipping invalid entries was considered and rejected: that would honor
X-Forwarded-Forwhen a TCP socket has noremoteAddress, 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-
undefinedcases.Fixes #9