Skip to content

feat: bind to 127.0.0.1 by default instead of 0.0.0.0#2812

Open
bfirsh wants to merge 2 commits intomainfrom
fix/bind-localhost-by-default
Open

feat: bind to 127.0.0.1 by default instead of 0.0.0.0#2812
bfirsh wants to merge 2 commits intomainfrom
fix/bind-localhost-by-default

Conversation

@bfirsh
Copy link
Member

@bfirsh bfirsh commented Mar 5, 2026

Summary

  • Default port binding changed from 0.0.0.0 to 127.0.0.1 across all commands, preventing prediction endpoints from being accidentally exposed to the entire network during development.
  • Added --host flag to cog serve and host:port syntax to cog run -p so users can opt into binding to all interfaces when needed.

Changes

File Change
pkg/docker/command/command.go Added HostIP field to Port struct
pkg/docker/docker.go Uses port.HostIP (default 127.0.0.1) instead of hardcoded ""
pkg/docker/run.go GetHostPortForContainer now accepts a hostIP parameter
pkg/docker/run_test.go Updated tests + added new test cases for default and all-interfaces binding
pkg/cli/serve.go Added --host flag (default 127.0.0.1)
pkg/cli/run.go -p flag supports host:port syntax (e.g. -p 0.0.0.0:8888), defaults to 127.0.0.1
pkg/predict/predictor.go cog predict/cog train bind to 127.0.0.1

User-facing behavior

Command Before After
cog serve Binds to 0.0.0.0 Binds to 127.0.0.1. Use --host 0.0.0.0 to expose.
cog run -p 8888 Binds to 0.0.0.0:8888 Binds to 127.0.0.1:8888. Use -p 0.0.0.0:8888 to expose.
cog predict / cog train Binds to 0.0.0.0 Binds to 127.0.0.1

Test plan

  • All 853 Go unit tests pass
  • 0 lint issues

Port bindings now default to localhost-only, preventing prediction
endpoints from being exposed to the entire network during development.

- Add HostIP field to command.Port struct (defaults to 127.0.0.1)
- Add --host flag to cog serve (default 127.0.0.1, use 0.0.0.0 to expose)
- Support host:port syntax in cog run -p (e.g. -p 0.0.0.0:8888)
- Bind cog predict/train to 127.0.0.1
- Update GetHostPortForContainer to match configured host IP
@bfirsh bfirsh requested a review from a team as a code owner March 5, 2026 02:15
@michaeldwan michaeldwan added this to the 0.18.0 milestone Mar 5, 2026
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