Skip to content

Percent-decode the IPC path of ws+unix: URLs - #2346

Closed
nk-batman21 wants to merge 1 commit into
websockets:masterfrom
nk-batman21:decode-ipc-path
Closed

nk-batman21 wants to merge 1 commit into
websockets:masterfrom
nk-batman21:decode-ipc-path

Conversation

@nk-batman21

Copy link
Copy Markdown
Contributor

The IPC path of a ws+unix: URL is cut out of URL#pathname, which is percent-encoded, and passed to net.connect() without decoding. So a UNIX domain socket whose path contains a space or a non-ASCII character, or a named pipe whose name contains a non-ASCII character, cannot be reached. For example, with a server listening on \\.\pipe\ws-café:

const ws = new WebSocket(String.raw`ws+unix:\\.\pipe\ws-café:/chat`);
// 'error': connect ENOENT \\.\pipe\ws-caf%C3%A9

The same happens with a space in a socket path, which is common on macOS (~/Library/Application Support/<app>/app.sock is passed as Application%20Support). There is no workaround short of a custom createConnection, because socketPath is always overridden.

This decodes the IPC path after it is split from the URL path, so an encoded %3A cannot move the separator. If the IPC path is not valid percent-encoding it is used as is: ws+unix:/tmp/100%.sock works today and keeps working, and decoding cannot throw from the redirect handler.

Ran: npm test (441 passing, 1 pending) and npm run lint on Node.js 24, Windows. The decode test fails without the change.
Checked: a client connecting to a named pipe with é in its name gets ENOENT before the change and opens after it.

The IPC path is taken from the URL pathname, which is percent-encoded,
so a UNIX domain socket whose path contains a space or a non-ASCII
character, or a named pipe whose name contains a non-ASCII character,
could not be reached. For example, `ws+unix:\\.\pipe\ws-café:/chat`
failed with `connect ENOENT \\.\pipe\ws-caf%C3%A9`.

Decode the IPC path after splitting it from the URL path, and use it as
is if it is not valid percent-encoding.
@lpinca

lpinca commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

I don't think this is needed, what is the reason for using non-ASCII characters? I can't remember open issues for this.

@nk-batman21

Copy link
Copy Markdown
Contributor Author

@lpinca the more common case is a space rather than non-ASCII. URL percent-encodes it, so a socket under ~/Library/Application Support/<app>/ on macOS reaches net.connect() as Application%20Support and fails with ENOENT, and writing %20 in the URL yourself doesn't help because nothing decodes it. Non-ASCII mostly comes from the user's home directory name, e.g. /home/José/.... I'm not aware of an open issue for it, so feel free to close this if you'd rather not support it.

@lpinca

lpinca commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

At the moment, it seems like a solution in search of a problem. We can revisit the matter if someone actually ends up needing it. Thank you anyway.

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.

2 participants