From 064a7387a6715a3cb54dcaa21f1a848fea8ac3b6 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Fri, 24 Jul 2015 08:47:52 +0100
Subject: [PATCH] fix withLocalhost: RemoteAddr is a host:port

---
 fe/http.go | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fe/http.go b/fe/http.go
index d204401c..2d0854af 100644
--- a/fe/http.go
+++ b/fe/http.go
@@ -371,7 +371,12 @@ func (h *HttpRedirector) serveStatusPage(w http.ResponseWriter, r *http.Request)
 
 func withLocalhost(h http.Handler) http.Handler {
 	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
-		if ip := net.ParseIP(r.RemoteAddr); !ip.IsLoopback() {
+		host, _, err := net.SplitHostPort(r.RemoteAddr)
+		if err != nil {
+			http.Error(w, "Unauthorized", http.StatusUnauthorized)
+			return
+		}
+		if ip := net.ParseIP(host); !ip.IsLoopback() {
 			http.Error(w, "Unauthorized", http.StatusUnauthorized)
 			return
 		}
-- 
GitLab