Skip to content

Commit 7c8de85

Browse files
committed
fix: remove implicit loopback injection, warn if UI enabled without lo
Instead of silently prepending 127.0.0.1 to Listens, the config is now explicit: bind must include "lo" (or "all") when the UI is enabled. A logger.Error is emitted at startup if this invariant is violated. https://claude.ai/code/session_01GKdjLHJH3n1CDut5j95H1u
1 parent bd5fcff commit 7c8de85

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

config/config.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ func resolveIfaceToIP(bind string) (string, error) {
117117
}
118118

119119
// resolveBindsToListens converts a list of bind names to host:port listen addresses.
120-
// "all" expands to 0.0.0.0 (which covers loopback too).
121-
// Otherwise 127.0.0.1 is always prepended if not already present.
120+
// "all" expands to 0.0.0.0. No implicit addresses are added.
122121
func resolveBindsToListens(binds []string, port string) ([]string, error) {
123122
for _, b := range binds {
124123
if b == "all" {
@@ -141,12 +140,19 @@ func resolveBindsToListens(binds []string, port string) ([]string, error) {
141140
}
142141
}
143142

143+
return addrs, nil
144+
}
145+
146+
// hasLoopback returns true if listens contains 127.0.0.1:port or 0.0.0.0:port.
147+
func hasLoopback(listens []string, port string) bool {
144148
loopback := net.JoinHostPort("127.0.0.1", port)
145-
if !seen[loopback] {
146-
addrs = append([]string{loopback}, addrs...)
149+
wildcard := net.JoinHostPort("0.0.0.0", port)
150+
for _, l := range listens {
151+
if l == loopback || l == wildcard {
152+
return true
153+
}
147154
}
148-
149-
return addrs, nil
155+
return false
150156
}
151157

152158
// getZeroconfInterfaces returns the network interfaces on which mDNS should be announced.
@@ -285,6 +291,10 @@ func New(cfgFile *string) (*Config, error) {
285291
Enabled: viper.GetBool("api.ui.enabled"),
286292
}
287293

294+
if uiCfg.Enabled && !hasLoopback(listens, portStr) {
295+
logger.Error("[config] UI is enabled but 'lo' is not in bind list — UI will fail to reach the API (add 'lo' to bind)")
296+
}
297+
288298
apiCfg := ApiConfig{
289299
Enabled: viper.GetBool("api.enabled"),
290300
Listens: listens,

0 commit comments

Comments
 (0)