Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Keep agent HTTP redirects within the configured origin
pulse-triage[bot]621966980926
diff --git a/cmd/pulse-mcp/main.go b/cmd/pulse-mcp/main.goindex 36bf0a1ac5..f084b3f634 100644--- a/cmd/pulse-mcp/main.go+++ b/cmd/pulse-mcp/main.go@@ -163,11 +163,7 @@ func (d pulseMCPAgentSurfaceHTTPDoer) Do(req *http.Request) (*http.Response, errreq.Header = req.Header.Clone()req.Header.Set(agentcapabilities.AgentSurfaceHeader, agentcapabilities.AgentSurfacePulseMCP)}- next := d.next- if next == nil {- next = http.DefaultClient- }- return next.Do(req)+ return agentcapabilities.DoAgentHTTPRequest(d.next, req)}// serve is the stdio loop: read line-delimited JSON-RPC requestsdiff --git a/cmd/pulse-mcp/main_test.go b/cmd/pulse-mcp/main_test.goindex 8627d968e6..68e1d0d362 100644--- a/cmd/pulse-mcp/main_test.go+++ b/cmd/pulse-mcp/main_test.go@@ -120,6 +120,32 @@ func TestMCPSameOriginRedirectPreservesWriteAndEventConsumer(t *testing.T) {}}+func TestMCPHTTPRedirectBoundaryCoversDefaultClientWithoutMutatingRequest(t *testing.T) {+ var destinationRequests atomic.Int32+ destination := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ destinationRequests.Add(1)+ }))+ defer destination.Close()+ origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ http.Redirect(w, r, destination.URL+"/target", http.StatusTemporaryRedirect)+ }))+ defer origin.Close()+ req, err := agentcapabilities.NewAgentHTTPRequest(context.Background(), http.MethodGet, origin.URL, "/api/example", "synthetic-token", nil)+ if err != nil {+ t.Fatal(err)+ }+ resp, err := (pulseMCPAgentSurfaceHTTPDoer{}).Do(req)+ if err == nil || resp != nil || !strings.Contains(err.Error(), "configured origin") {+ t.Fatalf("default-client redirect response = %v, error = %v", resp, err)+ }+ if destinationRequests.Load() != 0 {+ t.Fatal("default client contacted the other origin")+ }+ if req.Header.Get(agentcapabilities.AgentSurfaceHeader) != "" || req.Header.Get(agentcapabilities.AgentAPITokenHeader) != "synthetic-token" {+ t.Fatal("adapter mutated the caller's original request headers")+ }+}+type httpDoerFunc func(*http.Request) (*http.Response, error)func (f httpDoerFunc) Do(req *http.Request) (*http.Response, error) {diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.mdindex 74a395c204..fcfd0b1b43 100644--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md@@ -25,6 +25,22 @@ that same result. Successful reads retain their content and execution provenance## Purpose+### Pulse MCP does not forward credentials to a redirected origin++The adapter's standard-client requests share the agent HTTP origin boundary for+manifest discovery, tool/resource calls, workflow-prompt activity and the live+notification bridge, including its default client with no finite SSE timeout.+An off-origin redirect cannot send the token or write body, and cannot supply a+successful tool/resource result or live notification. The error tells the+operator to configure the final Pulse base URL without echoing destination data.++Same-origin redirects retain method/body semantics, token and surface attribution;+normal stdio errors, caller cancellation and client redirect limits still apply.+This is maintenance of existing transports, not a new tool, event type, history+source or grant. It changes no Pulse web consumer. The registered MCP suite+exercises tool reads/writes and resources through stdio, prompt-activity POSTs,+live notification consumption and the default-client request clone boundary.+### Typed MCP fleet filters survive HTTP projectionGET/DELETE capability projection preserves public string and boolean querydiff --git a/docs/release-control/v6/internal/subsystems/api-contracts.md b/docs/release-control/v6/internal/subsystems/api-contracts.mdindex 287828b909..a6b5a5ef25 100644--- a/docs/release-control/v6/internal/subsystems/api-contracts.md+++ b/docs/release-control/v6/internal/subsystems/api-contracts.md@@ -21,6 +21,24 @@## Purpose+### Agent HTTP redirects retain their configured origin++Manifest discovery, capability HTTP calls and agent SSE reads using standard Go+clients refuse redirects that change scheme, hostname or effective port, or+introduce different URL userinfo. In particular, the custom `X-API-Token` header+and replayable write bodies must not follow an off-origin redirect. Same-origin+relative redirects and equivalent default ports remain supported. Explicit HTTP+base URLs remain supported; an upgrade or downgrade is not silently followed.++The shared request executor copies the client, preserving its transport, timeout,+cookie jar and stricter redirect callback, with the normal ten-redirect default+when no callback exists. Callback edits cannot widen the origin. Boundary refusal+returns a fixed final-base-URL diagnostic without the redirect destination's+userinfo, path or query. Custom `HTTPDoer` implementations still own their transport+policy. No server route, scope, payload, token grant or browser producer changes.+Registered HTTP and MCP tests cover real loopback redirects, TLS, cancellation,+caller policy, request preservation and consuming stdio/event errors.+### Slow Assistant JSON results use current token authorityThe existing POST `execute` and `kubernetes/analyze` routes revalidate thediff --git a/internal/agentcapabilities/http.go b/internal/agentcapabilities/http.goindex cd6c5f94c5..24eda46c00 100644--- a/internal/agentcapabilities/http.go+++ b/internal/agentcapabilities/http.go@@ -4,6 +4,7 @@ import ("bytes""context""encoding/json"+ "errors""fmt""io""net/http"@@ -127,7 +128,7 @@ func FetchManifest(ctx context.Context, client HTTPDoer, baseURL string) (*Manifif err != nil {return nil, err}- resp, err := httpClient(client).Do(req)+ resp, err := DoAgentHTTPRequest(client, req)if err != nil {return nil, fmt.Errorf("GET %s: %w", AgentCapabilitiesPath, err)}@@ -178,7 +179,7 @@ func CallCapabilityHTTP(ctx context.Context, client HTTPDoer, baseURL, token strif err != nil {return HTTPCallResponse{}, err}- resp, err := httpClient(client).Do(req)+ resp, err := DoAgentHTTPRequest(client, req)if err != nil {return HTTPCallResponse{}, fmt.Errorf("%s %s: %w", cap.Method, projected.Path, err)}@@ -240,9 +241,65 @@ func CallRequestResponseCapabilityHTTPBodyByName(ctx context.Context, client HTTreturn append([]byte(nil), resp.Body...), nil}-func httpClient(client HTTPDoer) HTTPDoer {- if client != nil {- return client+var errAgentRedirectOrigin = errors.New("agent HTTP redirect left the configured origin; set the final Pulse base URL")++// DoAgentHTTPRequest keeps standard HTTP clients within the original request's+// origin. Go's default redirect rules do not protect our custom API-token+// header or replayable request bodies. Copy the client so callers retain their+// transport, timeout, cookie jar and stricter redirect policy without mutation.+// Custom HTTPDoers own their transport policy (including any redirect handling).+func DoAgentHTTPRequest(client HTTPDoer, req *http.Request) (*http.Response, error) {+ if client == nil {+ client = http.DefaultClient+ }+ standard, ok := client.(*http.Client)+ if !ok {+ return client.Do(req)+ }+ guarded := *standard+ previousRedirectPolicy := guarded.CheckRedirect+ guarded.CheckRedirect = func(next *http.Request, via []*http.Request) error {+ if len(via) == 0 || !sameAgentHTTPOrigin(via[0].URL, next.URL) {+ return errAgentRedirectOrigin+ }+ if previousRedirectPolicy != nil {+ if err := previousRedirectPolicy(next, via); err != nil {+ return err+ }+ // A caller's callback may edit the proposed request.+ if !sameAgentHTTPOrigin(via[0].URL, next.URL) {+ return errAgentRedirectOrigin+ }+ } else if len(via) >= 10 {+ return errors.New("stopped after 10 redirects")+ }+ return nil+ }+ resp, err := guarded.Do(req)+ if errors.Is(err, errAgentRedirectOrigin) {+ // net/http wraps redirect errors with the destination URL. Do not expose+ // its userinfo, path or query through MCP results or adapter logs.+ return nil, errAgentRedirectOrigin}- return http.DefaultClient+ return resp, err+}++func sameAgentHTTPOrigin(from, to *url.URL) bool {+ if from == nil || to == nil || from.Hostname() == "" || to.Hostname() == "" || from.Opaque != "" || to.Opaque != "" {+ return false+ }+ if !strings.EqualFold(from.Scheme, to.Scheme) || !strings.EqualFold(from.Hostname(), to.Hostname()) {+ return false+ }+ port := func(u *url.URL) string {+ if p := u.Port(); p != "" {+ return p+ }+ if strings.EqualFold(u.Scheme, "https") {+ return "443"+ }+ return "80"+ }+ return (strings.EqualFold(from.Scheme, "http") || strings.EqualFold(from.Scheme, "https")) &&+ port(from) == port(to) && from.User.String() == to.User.String()}diff --git a/internal/agentcapabilities/http_test.go b/internal/agentcapabilities/http_test.goindex cc4cba8c72..4a3fd2b2bd 100644--- a/internal/agentcapabilities/http_test.go+++ b/internal/agentcapabilities/http_test.go@@ -8,6 +8,7 @@ import ("io""net/http""net/http/httptest"+ "net/url""strings""sync/atomic""testing"@@ -147,6 +148,59 @@ func TestAgentHTTPRedirectsRetainDefaultLimit(t *testing.T) {}}+func TestAgentHTTPRedirectCallbackCannotWidenOrigin(t *testing.T) {+ var foreignRequests, callbackCalls atomic.Int32+ foreign := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { foreignRequests.Add(1) }))+ defer foreign.Close()+ origin := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ http.Redirect(w, r, "/accepted", http.StatusTemporaryRedirect)+ }))+ defer origin.Close()+ client := origin.Client()+ client.CheckRedirect = func(next *http.Request, _ []*http.Request) error {+ callbackCalls.Add(1)+ next.URL, _ = url.Parse(foreign.URL + "/elsewhere")+ return nil+ }+ _, err := FetchManifest(context.Background(), client, origin.URL)+ if !errors.Is(err, errAgentRedirectOrigin) || callbackCalls.Load() != 1 || foreignRequests.Load() != 0 {+ t.Fatalf("callback escaped boundary: err=%v callbacks=%d foreign=%d", err, callbackCalls.Load(), foreignRequests.Load())+ }+}++func TestAgentHTTPRedirectsPreserveTLSAndCancellation(t *testing.T) {+ var foreignRequests atomic.Int32+ foreign := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { foreignRequests.Add(1) }))+ defer foreign.Close()+ origin := httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ switch r.URL.Path {+ case "/accepted":+ _, _ = io.WriteString(w, `{"version":"v1"}`)+ case "/downgrade":+ http.Redirect(w, r, foreign.URL, http.StatusTemporaryRedirect)+ default:+ http.Redirect(w, r, "/accepted", http.StatusTemporaryRedirect)+ }+ }))+ defer origin.Close()+ client := origin.Client() // Includes this fixture's trusted TLS certificate.+ if _, err := FetchManifest(context.Background(), client, origin.URL); err != nil {+ t.Fatalf("configured TLS transport lost: %v", err)+ }+ response, err := CallCapabilityHTTP(context.Background(), client, origin.URL, "synthetic-token", Capability{Method: http.MethodGet, Path: "/downgrade"}, nil)+ if !errors.Is(err, errAgentRedirectOrigin) || response.StatusCode != 0 || foreignRequests.Load() != 0 {+ t.Fatalf("TLS downgrade escaped boundary: err=%v status=%d foreign=%d", err, response.StatusCode, foreignRequests.Load())+ }+ ctx, cancel := context.WithCancel(context.Background())+ cancel()+ if _, err := FetchManifest(ctx, client, origin.URL); !errors.Is(err, context.Canceled) {+ t.Fatalf("request cancellation lost: %v", err)+ }+ if client.CheckRedirect != nil {+ t.Fatal("caller TLS client was mutated")+ }+}+func TestFetchManifestUsesSharedDiscoveryPath(t *testing.T) {server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {if r.URL.Path != AgentCapabilitiesPath {diff --git a/internal/agentcapabilities/sse.go b/internal/agentcapabilities/sse.goindex b594edfc00..40a7831faa 100644--- a/internal/agentcapabilities/sse.go+++ b/internal/agentcapabilities/sse.go@@ -87,7 +87,7 @@ func StreamAgentSSERecords(ctx context.Context, client HTTPDoer, baseURL, path,return err}req.Header.Set("Accept", AgentSSEAccept)- resp, err := httpClient(client).Do(req)+ resp, err := DoAgentHTTPRequest(client, req)if err != nil {return err}