Quellcode durchsuchen

Fix unexpected permission error on an IPv6 configured machine (#176)

when visiting the webui.

When net.SplitHostPort is called, it will return the string "::1",
but the code was only checking for "[::1]".
Sanjay Ghemawat vor 8 Jahren
Ursprung
Commit
47fb2f570c
2 geänderte Dateien mit 15 neuen und 1 gelöschten Zeilen
  1. 1
    1
      internal/driver/webui.go
  2. 14
    0
      internal/driver/webui_test.go

+ 1
- 1
internal/driver/webui.go Datei anzeigen

@@ -105,7 +105,7 @@ func newListenerAndURL(hostport string) (ln net.Listener, url string, isLocal bo
105 105
 }
106 106
 
107 107
 func isLocalhost(host string) bool {
108
-	for _, v := range []string{"localhost", "127.0.0.1", "[::1]"} {
108
+	for _, v := range []string{"localhost", "127.0.0.1", "[::1]", "::1"} {
109 109
 		if host == v {
110 110
 			return true
111 111
 		}

+ 14
- 0
internal/driver/webui_test.go Datei anzeigen

@@ -17,6 +17,7 @@ package driver
17 17
 import (
18 18
 	"fmt"
19 19
 	"io/ioutil"
20
+	"net"
20 21
 	"net/http"
21 22
 	"net/http/httptest"
22 23
 	"net/url"
@@ -235,3 +236,16 @@ func TestNewListenerAndURL(t *testing.T) {
235 236
 		})
236 237
 	}
237 238
 }
239
+
240
+func TestIsLocalHost(t *testing.T) {
241
+	for _, s := range []string{"localhost:10000", "[::1]:10000", "127.0.0.1:10000"} {
242
+		host, _, err := net.SplitHostPort(s)
243
+		if err != nil {
244
+			t.Error("unexpected error when splitting", s)
245
+			continue
246
+		}
247
+		if !isLocalhost(host) {
248
+			t.Errorf("host %s from %s not considered local", host, s)
249
+		}
250
+	}
251
+}