Skip to content

channel.c: Listen on loopback-only addresses#19799

Open
zdohnal wants to merge 1 commit intovim:masterfrom
zdohnal:no-addrany-1
Open

channel.c: Listen on loopback-only addresses#19799
zdohnal wants to merge 1 commit intovim:masterfrom
zdohnal:no-addrany-1

Conversation

@zdohnal
Copy link
Copy Markdown
Contributor

@zdohnal zdohnal commented Mar 23, 2026

This protects Vim process for accidental opening to public network to
prevent security and performance issues, test included.

OLD:
This will prevent unintentional binding the process to public network interfaces, and opening Vim to communication from outside network if firewall allows it.

@chrisbra
Copy link
Copy Markdown
Member

thanks. What is the issue with the indentation change? Also can you please fix the codeql warning? I think the hostname cannot be null anyhow, since you add a test for it right at the beginning.

@zdohnal zdohnal force-pushed the no-addrany-1 branch 2 times, most recently from dc648c4 to f38ee9d Compare March 24, 2026 13:18
@zdohnal
Copy link
Copy Markdown
Contributor Author

zdohnal commented Mar 24, 2026

hi @chrisbra !

ad indentation - I followed the style in the function - there is 4 space per indent, and every 8 spaces is a tab - I have followed this style in the file and it is why Github shows it that way (so far I have not been able to set Github to show tabs properly - that's why personally prefer using spaces everywhere - everywhere it is shown the same way).

ad codecov error - I have fixed it now.

Thank you for the review!

OT question - is it expected to pass non-localhost address to that function in plugins, or only loopback? I could send PR for enforcing loopback, which could narrow the attack vector further.

@chrisbra
Copy link
Copy Markdown
Member

That is tricky. I think we should try to restrict to localhost if possible. @mattn does that work for you?

@zdohnal
Copy link
Copy Markdown
Contributor Author

zdohnal commented Mar 25, 2026

@chrisbra can we merge this PR for now? I can pass another PR separately.

@mattn
Copy link
Copy Markdown
Member

mattn commented Mar 25, 2026

I'd prefer changing the default from INADDR_ANY to INADDR_LOOPBACK instead of requiring the hostname. This achieves the same security improvement without breaking backward compatibility. The change would be just one line:

-	server.sin_addr.s_addr = htonl(INADDR_ANY);
+	server.sin_addr.s_addr = htonl(INADDR_LOOPBACK);

@mattn
Copy link
Copy Markdown
Member

mattn commented Mar 25, 2026

Also, the default binding behavior when the hostname is omitted is not documented. It would be good to document that it defaults to localhost (loopback), and that "0.0.0.0" can be specified to listen on all interfaces.

@zdohnal
Copy link
Copy Markdown
Contributor Author

zdohnal commented Mar 26, 2026

@mattn @chrisbra preferably I would like to make Vim able to connect to loopback only in all cases and only leave to user to define which hostname/IP address version they can use for loopback. Providing a way how to listen on network addresses might open the process to the internet, which I'm not sure whether Vim is ready to serve as such security and performance-wise.

@chrisbra
Copy link
Copy Markdown
Member

I agree, I don't want to expose Vim over the network. localhost only

@zdohnal zdohnal changed the title channel.c: Require hostname/address for ch_listen() channel.c: Listen on loopback-only addresses Mar 27, 2026
This protects Vim process for accidental opening to public network to
prevent security and performance issues, test included.
@zdohnal
Copy link
Copy Markdown
Contributor Author

zdohnal commented Mar 27, 2026

@chrisbra I have updated the MR and desc accordingly, and rebased the MR. Feel free to review and merge.

@mattn
Copy link
Copy Markdown
Member

mattn commented Mar 27, 2026

If we only want to allow loopback connections, the function should not accept a hostname at all. Accepting a hostname string and then rejecting non-loopback addresses after resolution is the wrong approach — it implies the caller can choose the bind address when they can't.

The proper fix would be to only accept a port number and always bind to INADDR_LOOPBACK internally. This eliminates the need for hostname resolution code in channel_listen() entirely.

@mattn
Copy link
Copy Markdown
Member

mattn commented Mar 27, 2026

Also, the indentation in the patch is incorrect. Vim source uses a mix of tabs and spaces for indentation — please match the existing style in the file.

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.

3 participants