From 1f048ae956ee38056eb5e62fb2cce23004752e49 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Tue, 24 Nov 2026 11:40:10 -0800 Subject: [PATCH] mini: bind WebDAV to loopback unless Basic Auth is set weed mini starts WebDAV by default on -ip.bind, which is 0.0.0.0, so anyone on the network could read, write and delete all bucket data even with S3 IAM on. Without [webdav.basic_auth], bind it to 127.0.0.1, as is done for the unauthenticated Admin UI. -webdav.allowInsecureBind keeps the network bind. Co-Authored-By: Claude Opus 5.5 --- weed/command/mini.go | 25 ++++++++++++++++++--- weed/command/mini_webdav_bind_test.go | 31 +++++++++++++++++++++++++++ weed/command/scaffold/security.toml | 3 ++- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 weed/command/mini_webdav_bind_test.go diff --git a/weed/command/mini.go b/weed/command/mini.go index f7a28e3f82..75a79d5c43 100644 --- a/weed/command/mini.go +++ b/weed/command/mini.go @@ -74,6 +74,7 @@ var ( // captured before the saved options file is applied explicitFlags map[string]bool miniEnableWebDAV *bool + miniWebDavAllowInsecureBind *bool miniEnableS3 *bool miniEnableAdminUI *bool miniAdminWorkerBindIP *string @@ -594,6 +595,7 @@ func initMiniWebDAVFlags() { miniWebDavOptions.maxMB = cmdMini.Flag.Int("webdav.maxMB", 4, "split files larger than the limit") miniWebDavOptions.filerRootPath = cmdMini.Flag.String("webdav.filer.path", "/", "use this remote path from filer server") miniWebDavOptions.idleTimeout = cmdMini.Flag.Int("webdav.idleTimeout", 10, "connection idle seconds") + miniWebDavAllowInsecureBind = cmdMini.Flag.Bool("webdav.allowInsecureBind", false, "INSECURE: allow WebDAV without [webdav.basic_auth] to bind to -ip.bind instead of loopback") } // initMiniAdminFlags initializes Admin server flag options @@ -1032,6 +1034,9 @@ func ensureAllPortsAvailableOnIP(bindIp string, listenOnLocalhost bool) error { if config.name == "Admin" { checkIP = adminBindIP } + if config.name == "WebDAV" { + checkIP = miniWebDavBindIP(bindIp) + } original := *config.port unavailablePorts := maps.Clone(reservedPorts) for port, flag := range chosenPorts { @@ -1540,7 +1545,11 @@ func runMini(cmd *Command, args []string) bool { miniS3Options.ip = miniIp miniS3Options.bindIp = miniBindIp miniS3Options.listenOnLocalhost = &listenOnLocalhost - miniWebDavOptions.ipBind = miniBindIp + webDavBindIP := miniWebDavBindIP(*miniBindIp) + if *miniEnableWebDAV && webDavBindIP != *miniBindIp { + glog.Warningf("WebDAV has no authentication; binding it to %s instead of %s. Set [webdav.basic_auth] in security.toml, or use -webdav.allowInsecureBind to keep the network bind.", webDavBindIP, *miniBindIp) + } + miniWebDavOptions.ipBind = &webDavBindIP miniOptions.v.ip = miniIp miniOptions.v.bindIp = miniBindIp miniOptions.v.listenOnLocalhost = &listenOnLocalhost @@ -1859,7 +1868,7 @@ func startMiniServices(miniWhiteList []string, allServicesReady chan struct{}) { } } if *miniEnableWebDAV { - waitForServiceReady("WebDAV", *miniWebDavOptions.port, bindIp) + waitForServiceReady("WebDAV", *miniWebDavOptions.port, *miniWebDavOptions.ipBind) } // Start Admin with worker (depends on master, filer, S3, WebDAV) @@ -1934,6 +1943,12 @@ func miniAdminBindIP(requestedIP string, passwordConfigured, mtlsConfigured, all return "127.0.0.1" } +// miniWebDavBindIP keeps WebDAV on loopback unless [webdav.basic_auth] or +// -webdav.allowInsecureBind permits the requested address. +func miniWebDavBindIP(requestedIP string) string { + return miniAdminBindIP(requestedIP, webDavBasicAuth() != nil, false, *miniWebDavAllowInsecureBind) +} + func miniAdminEffectiveBindIP(requestedIP string) string { hasMTLS := util.GetViper().GetString("https.admin.key") != "" && util.GetViper().GetString("https.admin.ca") != "" @@ -2357,7 +2372,11 @@ func printWelcomeMessage() { fmt.Fprintf(&sb, " Volume Server: http://%s:%d\n", *miniIp, *miniOptions.v.port) fmt.Fprintf(&sb, " Filer UI: http://%s:%d\n", *miniIp, *miniFilerOptions.port) if *miniEnableWebDAV { - fmt.Fprintf(&sb, " WebDAV: http://%s:%d\n", *miniIp, *miniWebDavOptions.port) + webDavIP := *miniIp + if isLoopbackIp(*miniWebDavOptions.ipBind) { + webDavIP = *miniWebDavOptions.ipBind + } + fmt.Fprintf(&sb, " WebDAV: http://%s:%d\n", webDavIP, *miniWebDavOptions.port) } if *miniEnableS3 { fmt.Fprintf(&sb, " S3 Endpoint: http://%s:%d\n", *miniIp, *miniS3Options.port) diff --git a/weed/command/mini_webdav_bind_test.go b/weed/command/mini_webdav_bind_test.go new file mode 100644 index 0000000000..04eb050ff3 --- /dev/null +++ b/weed/command/mini_webdav_bind_test.go @@ -0,0 +1,31 @@ +package command + +import "testing" + +func TestMiniWebDavBindIP(t *testing.T) { + allow := *miniWebDavAllowInsecureBind + t.Cleanup(func() { *miniWebDavAllowInsecureBind = allow }) + + tests := []struct { + name string + requestedIP string + password string + allowInsecure bool + want string + }{ + {name: "unauthenticated wildcard binds to loopback", requestedIP: "0.0.0.0", want: "127.0.0.1"}, + {name: "unauthenticated host address binds to loopback", requestedIP: "10.0.0.5", want: "127.0.0.1"}, + {name: "existing loopback bind is preserved", requestedIP: "127.0.0.1", want: "127.0.0.1"}, + {name: "basic auth permits requested bind", requestedIP: "0.0.0.0", password: "secret", want: "0.0.0.0"}, + {name: "explicit insecure opt-out permits requested bind", requestedIP: "0.0.0.0", allowInsecure: true, want: "0.0.0.0"}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Setenv("WEED_WEBDAV_BASIC_AUTH_PASSWORD", tt.password) + *miniWebDavAllowInsecureBind = tt.allowInsecure + if got := miniWebDavBindIP(tt.requestedIP); got != tt.want { + t.Fatalf("miniWebDavBindIP(%q) = %q, want %q", tt.requestedIP, got, tt.want) + } + }) + } +} diff --git a/weed/command/scaffold/security.toml b/weed/command/scaffold/security.toml index e9e7b09fb9..ba99a760e3 100644 --- a/weed/command/scaffold/security.toml +++ b/weed/command/scaffold/security.toml @@ -76,7 +76,8 @@ password = "" # HTTP Basic Auth on the WebDAV gateway (weed webdav, weed server -webdav, # weed mini). Without a password, anyone who can reach the WebDAV port reads, -# writes and deletes everything under its -filer.path. +# writes and deletes everything under its -filer.path, and weed mini binds +# WebDAV to 127.0.0.1 unless -webdav.allowInsecureBind is set. # Env: WEED_WEBDAV_BASIC_AUTH_USER, WEED_WEBDAV_BASIC_AUTH_PASSWORD [webdav.basic_auth] user = ""