Repository navigation
Bind --host localhost to 127.0.0.1 and refuse unparsed addresses - #1335
Merged
Merged
Conversation
… parse parseIp4 defaulted missing or unparsed octets to 0, so --host localhost, --host ::1, an empty host and any hostname bound 0.0.0.0. With no --api-key and no --lan-share, every device on the network then reached the router, including /v1/load-model and the provider proxies. The open-bind warning did not print, because the host was explicit. localhost now binds 127.0.0.1. Any other value must be an IPv4 address that std.Io.net.Ip4Address.parse accepts. main logs the rejected host at the flag and exits 1. serve() returns error.InvalidHost, which covers the iOS entry. parseIp4 refuses ::1 instead of mapping it to 127.0.0.1, because the server binds IPv4 only. This commit also moves serve()'s doc comment back to serve() from listen.zig.
Owner
|
🤖 MLXServe-PRBot approved — reviewed at head The bug is real, and it is a security bug:
Checked:
Note, not blocking: a host the app saved before this change (a No conflicts with main. CI has not run on this fork PR yet (workflows await approval); merge only on green. Generated by Claude Code |
4 of 5 tasks
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.
--host localhostbinds 0.0.0.0 today, and so do--host ::1, an empty host and any hostname.parseIp4defaults missing or unparsed octets to 0, and 0.0.0.0 is the wildcard.So a user who asks for a local-only server gets one that every device on the network can reach. With no
--api-keyand no--lan-share, a LAN peer reaches the router, including/v1/load-modeland the provider proxies. The open-bind warning does not print, because the caller passed--host. The app passes a non-empty Settings host field straight to--host, solocalhosttyped there does the same.What changes
localhost, in any case, binds 127.0.0.1.std.Io.net.Ip4Address.parseaccepts.mainexits 1 at the flag and prints, for example,--host takes an IPv4 address or localhost, got '::1'.serve()returnserror.InvalidHost, which coversios_lib.parseIp4refuses::1instead of mapping it to 127.0.0.1. The server binds IPv4 only. The app formats::1ashttp://[::1]:<port>, which cannot reach an IPv4-only listener.--help,docs/cli.mdanddocs/zh-CN/cli.mdname the accepted forms.Every
--hostin the repo's tests and scripts is an IPv4 literal, and the app turns an empty field into 0.0.0.0. Existing callers keep working. Only an empty--hoston the command line, a malformed IPv4, a hostname or an IPv6 address now fails.Testing
On a Mac Studio M5 Ultra, 96 GB, macOS 27.2.1:
parseIp4test failed before the fix, with localhost read as 0.0.0.0. It passes after.zig build test: 5655 of 6074 passed, 419 skipped, 0 failed. An earlier full run had one failure indeepseek_v41 served: DSpark rounds (greedy, then seeded sampling). That test passes when run alone, both on main and on this branch.python3 scripts/lint.py --strictexits 0./healthfrom loopback and from the machine's LAN address:--hostlocalhost*:port, the LAN gets 200127.0.0.1:port, the LAN cannot connect::1,'',my-mac.local*:port, the LAN gets 200On this branch,
--host 127.0.0.1still listens on 127.0.0.1, and the default still listens on every interface.