Preserve LuCI JavaScript through proxy

This commit is contained in:
benya
2026-06-04 19:46:03 +03:00
parent 44e8e47cbc
commit 14dbb00b2b
2 changed files with 10 additions and 1 deletions

View File

@@ -1148,7 +1148,7 @@ func (a *App) proxyLuCI(w http.ResponseWriter, r *http.Request, deviceID, sessio
}
rewriteLuCIHeaders(resp.Header, prefix)
contentType := resp.Header.Get("Content-Type")
if !strings.Contains(contentType, "text/html") && !strings.Contains(contentType, "javascript") && !strings.Contains(contentType, "text/css") {
if !strings.Contains(contentType, "text/html") {
return nil
}
body, err := io.ReadAll(resp.Body)

View File

@@ -425,6 +425,11 @@ func TestLuCIProxyRequiresActiveSessionAndRewritesPaths(t *testing.T) {
t.Fatal("LuCI route cookie leaked to LuCI upstream")
}
upstreamPath = r.URL.Path
if r.URL.Path == "/luci-static/resources/luci.js" {
w.Header().Set("Content-Type", "application/javascript")
_, _ = io.WriteString(w, `const untouched = '/cgi-bin/luci';`)
return
}
w.Header().Set("Content-Type", "text/html")
_, _ = io.WriteString(w, `<a href="/cgi-bin/luci/admin">LuCI</a><link href="/luci-static/test.css"><script>L = new LuCI({ "resource": "\/luci-static\/resources", "scriptname": "\/cgi-bin\/luci", "ubuspath": "\/ubus\/" });</script>`)
}))
@@ -510,6 +515,10 @@ func TestLuCIProxyRequiresActiveSessionAndRewritesPaths(t *testing.T) {
if upstreamPath != "/cgi-bin/luci/admin" {
t.Fatalf("LuCI fallback used upstream path %q", upstreamPath)
}
script := requestText(t, http.MethodGet, srv.URL+prefix+"/luci-static/resources/luci.js", "operator-test", nil, http.StatusOK)
if script != `const untouched = '/cgi-bin/luci';` {
t.Fatalf("LuCI JavaScript was unexpectedly rewritten: %s", script)
}
}
func TestServesStaticWebUI(t *testing.T) {