Skip to content
Snippets Groups Projects
Commit 064a7387 authored by ale's avatar ale
Browse files

fix withLocalhost: RemoteAddr is a host:port

parent e01cbaab
Branches
No related tags found
No related merge requests found
...@@ -371,7 +371,12 @@ func (h *HttpRedirector) serveStatusPage(w http.ResponseWriter, r *http.Request) ...@@ -371,7 +371,12 @@ func (h *HttpRedirector) serveStatusPage(w http.ResponseWriter, r *http.Request)
func withLocalhost(h http.Handler) http.Handler { func withLocalhost(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { 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) http.Error(w, "Unauthorized", http.StatusUnauthorized)
return return
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment