Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions cmd/mcpproxy/upstream_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/smart-mcp-proxy/mcpproxy-go/internal/configimport"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/health"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/logs"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/oauth"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/reqcontext"
)

Expand Down Expand Up @@ -1783,14 +1784,21 @@ func outputImportResultStructured(result *configimport.ImportResult, format stri

// buildImportedServersOutput builds the output structure for imported servers
func buildImportedServersOutput(imported []*configimport.ImportedServer) []map[string]interface{} {
// Issue #1148, round 8: the import preview echoes the operator's source
// file back as CLI JSON — a shape an agent pipes as readily as a human
// reads. The shared LIVE rule leaves an ordinary command, path or URL
// byte-identical and renders a credential as `••••<last2> (<N> chars)`, so
// the operator can still verify that the secret imported and how long it
// is without the value itself reaching stdout.
result := make([]map[string]interface{}, len(imported))
for i, s := range imported {
view := oauth.RedactedConfigView("", s.Server)
result[i] = map[string]interface{}{
"name": s.Server.Name,
"protocol": s.Server.Protocol,
"url": s.Server.URL,
"command": s.Server.Command,
"args": s.Server.Args,
"url": viewOr(view, "url", s.Server.URL),
"command": viewOr(view, "command", s.Server.Command),
"args": oauth.LiveRedaction.Argv(s.Server.Args),
"enabled": s.Server.Enabled,
"quarantined": s.Server.Quarantined,
"source_format": s.SourceFormat,
Expand Down Expand Up @@ -2285,3 +2293,14 @@ func runUpstreamPatch(_ *cobra.Command, args []string) error {
fmt.Println()
return nil
}

// viewOr reads one string leaf out of a redacted server view (see
// oauth.RedactedConfigView), falling back to the raw value when the key was
// omitted — every string field of config.ServerConfig is `omitempty`, and an
// empty value carries no secret.
func viewOr(view map[string]interface{}, key, fallback string) string {
if v, ok := view[key].(string); ok {
return v
}
return fallback
}
44 changes: 42 additions & 2 deletions internal/httpapi/diagnostics_per_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

"github.com/go-chi/chi/v5"

"github.com/smart-mcp-proxy/mcpproxy-go/internal/config"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/contracts"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/diagnostics"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/oauth"
Expand All @@ -34,7 +35,11 @@ func redactHealthDetail(healthRaw interface{}, reveal bool) interface{} {
return healthRaw
}
clone := *hs
clone.Detail = oauth.RedactSensitiveData(clone.Detail)
// Round 8 finding 2: oauth.ScrubUpstreamText is the ONE rule for
// free-form upstream text. RedactSensitiveData alone is its name half, and
// oauth.RedactServerSecretFields scrubs this very field with both halves on
// the sibling /api/v1/servers door.
clone.Detail = oauth.ScrubUpstreamText(clone.Detail)
return &clone
}

Expand All @@ -45,7 +50,8 @@ func redactDiagnosticCause(diag map[string]interface{}, reveal bool) {
return
}
if cause, ok := diag["cause"].(string); ok && cause != "" {
diag["cause"] = oauth.RedactSensitiveData(cause)
// Round 8 finding 2: the same one rule the sibling REST door applies.
diag["cause"] = oauth.ScrubUpstreamText(cause)
}
}

Expand Down Expand Up @@ -127,3 +133,37 @@ func (s *Server) handleGetServerDiagnostics(w http.ResponseWriter, r *http.Reque

s.writeSuccess(w, resp)
}

// viewString reads one string leaf out of a redacted server view (see
// oauth.RedactedConfigView), falling back to the raw value when the key was
// omitted — every string field of config.ServerConfig is `omitempty`, and an
// empty value carries no secret. It is the httpapi twin of the helper the MCP
// door uses, so the two build their echoes from the view the same way.
func viewString(view map[string]interface{}, key, fallback string) string {
if v, ok := view[key].(string); ok {
return v
}
return fallback
}

// redactedRegistrySummary renders one registry source for a REST echo with its
// URLs masked by the shared LIVE rule.
//
// Issue #1148, round 8: a CUSTOM registry source is operator-configured, so its
// URL can carry a credential in the query string exactly as an upstream URL
// can — and it was echoed verbatim by add-source / edit-source / remove-source
// and republished by `list_registries` on every surface. The write doors
// (Server.AddRegistrySource / EditRegistrySource) refuse an echoed mask rather
// than persisting it over the credential, which is the same bind-or-refuse
// answer the server write path gives.
func redactedRegistrySummary(entry *config.RegistryEntry) contracts.RegistrySummary {
return contracts.RegistrySummary{
ID: entry.ID,
Name: entry.Name,
URL: oauth.LiveRedaction.URLValue(entry.URL),
ServersURL: oauth.LiveRedaction.URLValue(entry.ServersURL),
Protocol: entry.Protocol,
Provenance: entry.Provenance,
Trusted: entry.IsTrusted(),
}
}
18 changes: 15 additions & 3 deletions internal/httpapi/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"time"

"github.com/smart-mcp-proxy/mcpproxy-go/internal/configimport"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/oauth"
)

// ImportRequest represents a request to import servers from JSON/TOML content
Expand Down Expand Up @@ -427,12 +428,23 @@ func (s *Server) runImport(r *http.Request, content []byte, formatHint string, s
}

for i, imported := range result.Imported {
// Issue #1148, round 9: this preview echoes the operator's SOURCE FILE
// back — an agent pipes it as readily as a human reads it — and it did
// so with `url`, `command` and `args` raw, while its CLI twin
// (`upstream import`, buildImportedServersOutput) was routed through
// the shared LIVE rule in round 8. Same data, two doors, one redacted.
//
// The shared rule leaves an ordinary command, path or flag
// byte-identical and renders a credential as `••••<last2> (<N> chars)`,
// so the operator can still verify that a secret imported and how long
// it is without the value itself reaching the wire.
view := oauth.RedactedConfigView("", imported.Server)
response.Imported[i] = ImportedServerResponse{
Name: imported.Server.Name,
Protocol: imported.Server.Protocol,
URL: imported.Server.URL,
Command: imported.Server.Command,
Args: imported.Server.Args,
URL: viewString(view, "url", imported.Server.URL),
Command: viewString(view, "command", imported.Server.Command),
Args: oauth.LiveRedaction.Argv(imported.Server.Args),
SourceFormat: string(imported.SourceFormat),
OriginalName: imported.OriginalName,
FieldsSkipped: imported.FieldsSkipped,
Expand Down
55 changes: 55 additions & 0 deletions internal/httpapi/round8_diagnostics_rule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package httpapi

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/smart-mcp-proxy/mcpproxy-go/internal/contracts"
"github.com/smart-mcp-proxy/mcpproxy-go/internal/oauth"
)

// Issue #1148, round 8 finding 2.
//
// `health.detail` and `diagnostic.cause` are the SAME two strings that
// oauth.RedactServerSecretFields scrubs on GET /api/v1/servers and on the
// /events servers.changed payload, where the rule is the name rule PLUS the
// value-shaped detector. The per-server diagnostics route scrubbed them with
// the name rule ALONE, so a credential under an unrecognised query parameter
// was masked on one door and published on its sibling.

const round8GHPToken = "ghp_1234567890abcdefghijABCDEFGHIJ123456"

func TestRedactHealthDetail_UsesTheSharedFreeTextRule(t *testing.T) {
detail := `Post "https://h/mcp?opaque=` + round8GHPToken + `": no such host`

got := redactHealthDetail(&contracts.HealthStatus{Detail: detail}, false)
hs, ok := got.(*contracts.HealthStatus)
require.True(t, ok)

assert.NotContains(t, hs.Detail, round8GHPToken,
"the diagnostics door published a credential its sibling REST door masks")
assert.Equal(t, oauth.ScrubUpstreamText(detail), hs.Detail,
"health.detail must be scrubbed with the one shared free-text rule")
}

func TestRedactDiagnosticCause_UsesTheSharedFreeTextRule(t *testing.T) {
cause := `Get "https://h/mcp?opaque=` + round8GHPToken + `": connection refused`
diag := map[string]interface{}{"cause": cause}

redactDiagnosticCause(diag, false)

assert.NotContains(t, diag["cause"], round8GHPToken,
"the diagnostics door published a credential its sibling REST door masks")
assert.Equal(t, oauth.ScrubUpstreamText(cause), diag["cause"],
"diagnostic.cause must be scrubbed with the one shared free-text rule")
}

func TestRedactHealthDetail_RevealStillOptsOut(t *testing.T) {
detail := "raw " + round8GHPToken
got := redactHealthDetail(&contracts.HealthStatus{Detail: detail}, true)
hs, ok := got.(*contracts.HealthStatus)
require.True(t, ok)
assert.Equal(t, detail, hs.Detail)
}
Loading
Loading