From cf2cf18136b3859ac06979c958e179e18e91101d Mon Sep 17 00:00:00 2001 From: Toby Chui Date: Fri, 10 Oct 2025 15:51:00 +0800 Subject: [PATCH] Added check for loopback proxy enable state - Added check and show 521 if the loopback proxy endpoint is disabled --- src/mod/dynamicproxy/endpoints.go | 5 +++++ src/mod/dynamicproxy/proxyRequestHandler.go | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/mod/dynamicproxy/endpoints.go b/src/mod/dynamicproxy/endpoints.go index 9a18fc1..58031c3 100644 --- a/src/mod/dynamicproxy/endpoints.go +++ b/src/mod/dynamicproxy/endpoints.go @@ -272,6 +272,11 @@ func (ep *ProxyEndpoint) Remove() error { return nil } +// Check if the proxy endpoint is enabled +func (ep *ProxyEndpoint) IsEnabled() bool { + return !ep.Disabled +} + // Write changes to runtime without respawning the proxy handler // use prepare -> remove -> add if you change anything in the endpoint // that effects the proxy routing src / dest diff --git a/src/mod/dynamicproxy/proxyRequestHandler.go b/src/mod/dynamicproxy/proxyRequestHandler.go index 757bc55..7d3f669 100644 --- a/src/mod/dynamicproxy/proxyRequestHandler.go +++ b/src/mod/dynamicproxy/proxyRequestHandler.go @@ -111,15 +111,21 @@ func (router *Router) rewriteURL(rooturl string, requestURL string) string { // this prevents unnecessary external DNS lookup and connection, return true if swapped and request is already handled // by the loopback handler. Only continue if return is false func (h *ProxyHandler) upstreamHostSwap(w http.ResponseWriter, r *http.Request, selectedUpstream *loadbalance.Upstream) bool { - upstreamHostanme := selectedUpstream.OriginIpOrDomain - if strings.Contains(upstreamHostanme, ":") { - upstreamHostanme = strings.Split(upstreamHostanme, ":")[0] + upstreamHostname := selectedUpstream.OriginIpOrDomain + if strings.Contains(upstreamHostname, ":") { + upstreamHostname = strings.Split(upstreamHostname, ":")[0] } - loopbackProxyEndpoint := h.Parent.GetProxyEndpointFromHostname(upstreamHostanme) + loopbackProxyEndpoint := h.Parent.GetProxyEndpointFromHostname(upstreamHostname) if loopbackProxyEndpoint != nil { //This is a loopback request. Swap the target to the loopback target //h.Parent.Option.Logger.PrintAndLog("proxy", "Detected a loopback request to self. Swap the target to "+loopbackProxyEndpoint.RootOrMatchingDomain, nil) - h.hostRequest(w, r, loopbackProxyEndpoint) + if loopbackProxyEndpoint.IsEnabled() { + h.hostRequest(w, r, loopbackProxyEndpoint) + } else { + //Endpoint disabled, return 503 + http.ServeFile(w, r, "./web/rperror.html") + h.Parent.logRequest(r, false, 521, "host-http", r.Host, upstreamHostname) + } return true } return false