From 6610c182a56e69a612b0efa06713150021969ca1 Mon Sep 17 00:00:00 2001 From: immanuwell Date: Thu, 23 Jul 2026 21:07:53 +0400 Subject: [PATCH] fix: bind web server to loopback by default Signed-off-by: immanuwell --- cmd/stackwhere/web.go | 2 +- cmd/stackwhere/web_test.go | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/stackwhere/web.go b/cmd/stackwhere/web.go index e2cb2d5..90b23ca 100644 --- a/cmd/stackwhere/web.go +++ b/cmd/stackwhere/web.go @@ -43,7 +43,7 @@ func webCommand() *cobra.Command { flags := c.Flags() wc := &webCmd{ - flagAddr: flags.String("addr", ":8080", "Address to bind the local web server to"), + flagAddr: flags.String("addr", "127.0.0.1:8080", "Address to bind the local web server to"), flagSourceDirs: flags.StringSlice( "source-dir", nil, diff --git a/cmd/stackwhere/web_test.go b/cmd/stackwhere/web_test.go index f1c2aec..32087f0 100644 --- a/cmd/stackwhere/web_test.go +++ b/cmd/stackwhere/web_test.go @@ -46,6 +46,18 @@ func TestStartupURL(t *testing.T) { } } +func TestWebCommandBindsLoopbackByDefault(t *testing.T) { + cmd := webCommand() + addr, err := cmd.Flags().GetString("addr") + if err != nil { + t.Fatalf("failed to get addr flag: %v", err) + } + + if want := "127.0.0.1:8080"; addr != want { + t.Fatalf("default addr = %q, want %q", addr, want) + } +} + func TestWebCommandRequiresCollectionArg(t *testing.T) { cmd := root() cmd.SetArgs([]string{"web"})