Selaa lähdekoodia

auto update script executed

Toby Chui 1 vuosi sitten
vanhempi
commit
09c50dddbf
1 muutettua tiedostoa jossa 19 lisäystä ja 4 poistoa
  1. 19 4
      mod/dynamicproxy/Server.go

+ 19 - 4
mod/dynamicproxy/Server.go

@@ -5,6 +5,7 @@ import (
 	"errors"
 	"log"
 	"net/http"
+	"net/url"
 	"os"
 	"strings"
 
@@ -156,10 +157,24 @@ func (h *ProxyHandler) handleRootRouting(w http.ResponseWriter, r *http.Request)
 			}
 			return
 		} else {
-			//Redirect to target
-			h.logRequest(r, false, 307, "root-redirect", domainOnly)
-			http.Redirect(w, r, h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget, http.StatusTemporaryRedirect)
-			return
+			//Validate the redirection target URL
+			parsedURL, err := url.Parse(h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget)
+			if err != nil {
+				//Error when parsing target. Send to root
+				h.proxyRequest(w, r, h.Parent.Root)
+				return
+			}
+			hostname := parsedURL.Hostname()
+			if domainOnly != hostname {
+				//Redirect to target
+				h.logRequest(r, false, 307, "root-redirect", domainOnly)
+				http.Redirect(w, r, h.Parent.RootRoutingOptions.UnsetRuleRedirectTarget, http.StatusTemporaryRedirect)
+				return
+			} else {
+				//Loopback request due to bad settings (Shd leave it empty)
+				//Forward it to root proxy
+				h.proxyRequest(w, r, h.Parent.Root)
+			}
 		}
 	} else {
 		//Route to root