Skip to content

fix: correct func startup binding - #5484

Merged
Jacob Viau (jviau) merged 4 commits into
mainfrom
u/jviau/bind-localhost-only
Jul 29, 2026
Merged

Jacob Viau (jviau) merged 4 commits into
mainfrom
u/jviau/bind-localhost-only

Conversation

@jviau

@jviau Jacob Viau (jviau) commented Jul 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Updates func start local host binding and makes the bind address configurable.

Changes in src/Cli/func/Actions/HostActions/StartHostAction.cs (and src/Cli/func/Common/HostStartSettings.cs):

  • Default binding: both the HTTP path (Setup()) and the HTTPS path (Kestrel Listen) bind to the IPv4 loopback address (127.0.0.1 / IPAddress.Loopback).
  • New opt-in --address flag: lets you specify the local IP address to bind to. When unset it defaults to 127.0.0.1.
  • New local.settings.json setting: Host.LocalHttpAddress provides the same override via config.
  • Precedence: --address flag β†’ Host.LocalHttpAddress β†’ 127.0.0.1.

The address is resolved once via a shared ResolveBindAddress() helper that validates the value and throws a clear CliException on invalid input. It feeds both binding paths (the listen URI is built through an IPEndPoint so IPv6 values are bracketed correctly). BaseUri and displayed function URLs remain localhost, so normal local development output is unchanged.

Notes

  • Default behavior is localhost-only; broadening the bind address is strictly opt-in.
  • No change to IPv6 defaults.
  • Existing localhost-based workflows and tests (which connect via http://localhost:{port}) are unaffected.
  • NetworkHelpers and unrelated build assets are untouched.

Validation

  • dotnet build of src/Cli/func succeeds with 0 warnings / 0 errors.
  • 4 new unit tests in StartHostActionTests.cs cover the default, the --address override, the config-supplied value, and invalid-input handling β€” all pass.

Change the local host binding for 'func start' from the IPv4 wildcard (0.0.0.0) to IPv4 loopback (127.0.0.1) for both the HTTP (UseUrls) and HTTPS (Kestrel Listen) paths, so the host is reachable only from localhost.
@jviau
Jacob Viau (jviau) requested a review from a team as a code owner July 17, 2026 18:53
@jviau Jacob Viau (jviau) changed the title Bind func host to 127.0.0.1 loopback instead of 0.0.0.0 fix: bind func host to 127.0.0.1 loopback instead of 0.0.0.0 Jul 17, 2026
@jviau Jacob Viau (jviau) changed the title fix: bind func host to 127.0.0.1 loopback instead of 0.0.0.0 fix: correct func startup binding Jul 17, 2026
Adds an opt-in --address CLI flag and matching local.settings.json Host.LocalHttpAddress setting to control the local IP the func host binds to. Defaults to 127.0.0.1 when unset. Precedence: CLI flag > config > 127.0.0.1.

Both the HTTP listen URI and the HTTPS Kestrel listener now resolve the address through a shared ResolveBindAddress() helper, which validates the value and throws on invalid input. BaseUri remains localhost.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Release notes entry missing?

  2. My agent review flagged this. Is this something we should mention in the "breaking change" docs?:

The 0.0.0.0 β†’ 127.0.0.1 default change breaks a common workflow: running func start in a container and reaching it from the host via a mapped port (docker run -p 7071:7071, Compose, etc.). Docker forwards host traffic to the container's eth0, not loopback, so a loopback-only bind refuses those connections β€” a confusing "connection refused" on a port that's clearly mapped. Same for container-to-container and WSL2 β†’ Windows host. This worked before with no flags; now it requires --address 0.0.0.0.

Documents the default bind change from 0.0.0.0 to 127.0.0.1, the new opt-in --address flag / Host.LocalHttpAddress setting, and the workaround for setups that relied on 0.0.0.0 (e.g. reaching the host from outside a Docker container).
@jviau
Jacob Viau (jviau) merged commit b9387d9 into main Jul 29, 2026
42 checks passed
@jviau
Jacob Viau (jviau) deleted the u/jviau/bind-localhost-only branch July 29, 2026 22:29
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