From 495f26caeda8fb3400cdb8a207f619b27623000e Mon Sep 17 00:00:00 2001 From: Stefan Etringer Date: Wed, 9 Jul 2025 14:45:35 +0000 Subject: [PATCH] added support for upload and download functions of the gommand interactive agent through the proxy --- src/server/webapp/handlers.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/server/webapp/handlers.go b/src/server/webapp/handlers.go index 8a97db6..3278d2a 100644 --- a/src/server/webapp/handlers.go +++ b/src/server/webapp/handlers.go @@ -396,7 +396,9 @@ func (app *App) proxyAgentHandler(w http.ResponseWriter, r *http.Request) { ForceAttemptHTTP2: false, }, FlushInterval: -1, + ModifyResponse: func(resp *http.Response) error { + // Patch the base tag for seemless translation of the proxy if strings.HasPrefix(resp.Header.Get("Content-Type"), "text/html") { body, _ := io.ReadAll(resp.Body) patched := bytes.Replace( @@ -408,6 +410,20 @@ func (app *App) proxyAgentHandler(w http.ResponseWriter, r *http.Request) { resp.ContentLength = int64(len(patched)) resp.Header.Set("Content-Length", strconv.Itoa(len(patched))) } + + // patch relative redirects coming from the agent + // e.g. download function of the interactive agent + if loc := resp.Header.Get("Location"); loc != "" { + if !strings.HasPrefix(loc, "http://") && + !strings.HasPrefix(loc, "https://") && + !strings.HasPrefix(loc, "/proxyAgent/") { + // Remove leading "/" if present, prefix with the tunnel + loc = strings.TrimPrefix(loc, "/") + fixed := fmt.Sprintf("/proxyAgent/%s/%s", agentKey, loc) + resp.Header.Set("Location", fixed) + } + } + return nil }, }