Repository navigation
fix(server): record redacted mutation payloads and target server in the activity log - #1149
Merged
Merged
Conversation
…in activity (#1146) The activity records for the two mutating built-in tools carried only {operation, name}. Every payload field — env_json, headers_json, oauth_json, isolation_json, args_json, command, url, protocol, enabled, trust_mode, init_timeout, registry, id — was dropped, so the audit trail could say that a server was patched but never what changed. The read-only read_cache tool logged more than either mutator. On top of that all 18 emit sites passed targetServer="" and EmitActivityInternalToolCall omits an empty target_server, so the Activity Log Server column rendered "-" and `activity list --server <name>` missed every mutation. Record the FULL argument set instead of a hand-maintained allowlist (the allowlist is what rotted into this bug), redacted through the existing internal/oauth helpers, and thread the resolved server name through every emit site. update/patch additionally record the resolved config diff: patch semantics (deep merge, `null` means remove) make what was requested genuinely different from what changed. Redaction policy: redacted-but-PRESENT. oauth.RedactEnvValues / RedactStringHeaders / RedactURLQueryParams mask values with `••••<last2> (<N> chars)`, so the operator sees THAT API_KEY changed and which credential it was, while ${keyring:…}/${env:…} references and ordinary config (protocol, LOG_LEVEL, image python:3.12) stay readable. The walk is structure-aware: marshalling to JSON and running the regex scrubber over it rewrites across the closing quote and yields invalid JSON. Each string leaf is capped at 512 bytes so one mutation carrying a large env map cannot bloat the store. config.RevealSecretHeaders is deliberately NOT honoured here — the activity store is persisted, CLI-exported and SSE-broadcast, a different durability class from the live `list` projection it governs. Also closes two pre-existing leaks found while wiring this up: config.FieldChange carries raw before/after VALUES, and both handleUpdateUpstream and handlePatchUpstream put configDiff.Modified straight into responseMap["changes"] and into a zap.Any audit line — so a patch echoed another server's env values, Authorization header and oauth.client_secret back to the calling agent, into main.log, into BBolt and over SSE. Both now render through the shared redactedConfigDiff. Field paths and the key set are preserved, which is what agents branch on (TestE2E_PatchPreservesOAuthConfig stays green); only values are masked. handleUpdateUpstream / handlePatchUpstream now return the resolved *config.ConfigDiff; both are unexported with a single caller each.
…activity Cross-model review of #1146 found four ways the "record the full mutation payload" change could leak or be spoofed, plus one unannounced contract change. All five are addressed here. 1. Command-line ARGUMENT VALUES were recorded verbatim. argv has no key to judge by — the slice branch recursed with the parent key ("args"), so every element fell through redactActivityString unmasked. `uvx mcp-foo --api-key sk-live-…` therefore persisted the credential in BBolt, in the SSE payload and in `mcpproxy activity list`, on the exact path #1146 set out to seal. redactActivityArgv now masks by two rules: the flag names the credential (`--api-key VALUE` / `--api-key=VALUE`, delegated to the same env-var rule via the new oauth.IsSensitiveKeyName), and the value is recognisable on its own (internal/security's detector, reused rather than re-invented). Package names, subcommands, paths and ports still round-trip verbatim. 2. targetServer was taken from the unvalidated agent-supplied `name` and hoisted above the dispatch, so operations that never receive the request (list, list_quarantined) attributed their row to a server they never touched. activityAttributedOps is now an allowlist — unknown and unparsed operations default to unattributed — pinned to both operation switches in BOTH directions by an AST test, so a new mutating operation cannot silently lose its Server column either. 3. Populating targetServer let management chatter into /api/v1/activity/summary's top_servers/top_tools, which previously skipped those rows only by the accident of an empty ServerName. Those lists answer "which upstreams is this proxy talking to", so the management built-ins are now excluded explicitly (storage.IsManagementBuiltin — the same population CountsAsCall already names). The rows stay in the totals. 4. Capturing the whole request captured caller-supplied `_auth_*` keys, which internal/runtime copies onto ActivityRecord.UserID/UserEmail. Neither handler calls injectAuthMetadata, so those can only be client-supplied: a caller-controlled identity stamp on the audit row for a privileged mutation. Stripped with security.StripInternalArgs. 5. The masked changes.modified[*].from/.to is agent-observable. Non-secret values already round-trip truthfully (now pinned by a test); the upstream_servers description says so. Goldens regenerated and the delta enumerated on all three surfaces.
Key-name matching was still the only rule on several activity paths, so a
credential whose NAME gave nothing away reached BBolt, the SSE payload and
`mcpproxy activity list` in the clear.
- argv: the inline `--flag=VALUE` form consulted only the flag-name rule, so
`--endpoint=ghp_…` leaked while the identical `--endpoint ghp_…` masked.
redactActivityString now ends in the value-shaped detector for EVERY leaf,
which keeps the two spellings in step by construction.
- headers: oauth's header matcher only recognised whole delimiter-separated
segments, so `X-AuthToken` / `X-SecretValue` matched nothing. It now also
splits CamelCase (X-Author-ID / X-Monkey-ID stay readable), and header values
additionally go through the detector — neither rule alone is sufficient.
- `upstream_servers add` emitted a second, unredacted config_change row built
from the resolved values; it goes through the same redaction now.
- audit surfaces mask with the new oauth.AuditMaskValue (a fixed marker) rather
than MaskValue's `••••<last2> (<N> chars)`: persisted, streamed and exported
rows must not carry a credential's exact length and trailing bytes. The
interactive/read surfaces keep MaskValue — the write path's unmask contract
depends on its exact rendering.
- a `*_json` argument that does not parse now fails CLOSED. Heuristic string
scrubbing is regex-shaped and missed `{"API_KEY" "sk-live-…"}` entirely; the
row records that the parameter was sent and its size, not its bytes.
oauth gains *With variants of the three redactors so the mask can vary without
forking the "which name is sensitive" rules.
Deploying mcpproxy-docs with
|
| Latest commit: |
5d590c2
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f8c799d1.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-1146-activity-payload.mcpproxy-docs.pages.dev |
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 33418347024 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
kabakaev
pushed a commit
to run-a-bot/mcpproxy-go
that referenced
this pull request
Sep 7, 2026
…mous auth revealing them (smart-mcp-proxy#1148) `quarantine_security list_quarantined` json.Marshal'd the raw []*config.ServerConfig from storage, so every credential the struct carries left through the MCP surface in the clear — and /mcp is unprotected by default, so any caller could read them. The leak was wider than reported: env values, header values, oauth.client_secret, URL query credentials AND argv tokens. The response was then recorded verbatim into the activity store (BBolt, SSE, `activity list`). Redacted view (a): New internal/server/mcp_server_view.go builds MCP-facing server payloads by walking the config's OWN JSON through the shared redaction walker from smart-mcp-proxy#1149, not from a hand-written key list — so the next field added to ServerConfig is masked by default rather than leaked by default. The walker is now policy-driven: live surfaces render with oauth.MaskValue, persisted ones with oauth.AuditMaskValue. Env, header and URL leaves deliberately reproduce internal/oauth's own rendering byte for byte on live surfaces, because UnmaskEnvValues/UnmaskHeaders/UnmaskURL recognise an echoed mask by that exact string; rendering them any other way would make a read-modify-write client persist the mask over the real secret. Every other leaf — argv tokens and any future field — is detector-masked unconditionally. argv had no unmask contract, so one is added (unmaskArgv) alongside masking it. Auth gate (b): The gate read `authCtx != nil && !authCtx.IsAdmin()`, so absence of a token passed where a scoped agent token failed. The real path is narrower than "nil is admin": mcpAuthMiddleware deliberately installs an admin context for unauthenticated /mcp back-compat. That upgrade stays — it is why unauthenticated MCP clients work — but the context is now marked Anonymous, and the new nil-safe CanRevealSecrets() distinguishes it from an authenticated admin. Its single consumer is `reveal_secret_headers`. stdio now installs an explicit admin context instead of relying on nil. Behaviour change, exhaustively: list_quarantined is masked for everyone; reveal_secret_headers:true returns raw values only to an API-key/agent admin, a tray socket connection, or stdio; tail_log lines and connection_message strings are scrubbed; activity rows for both management built-ins record the audit-masked response. NOT changed: ordinary tool calls, retrieve_tools, add/update/patch/ enable/disable/restart and every quarantine approval still work for an unauthenticated /mcp session. The REST API is untouched. Sibling paths (c): - upstream_servers list: reveal gate above; argv now masked; the projection is sourced from the view so it cannot drift. - tail_log: lines and connection_status.last_error scrubbed. Fixed at the source too — Connect() logged the raw upstream URL into server-<name>.log on every attempt (logSafeURL). - connection errors: the three unscrubbed sites in monitorConnectionStatus / handleUpdateUpstream now use the same scrubUpstreamText as the list path's last_error. - add_from_registry summary: url and args from the view. - inspect_quarantined: verified safe — it emits tool analysis only, never the server config. Unchanged.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1146.
The problem
The activity log recorded that an upstream server was mutated but not what changed — and the one field it did record leaked secrets.
Reproduced on
mainagainst a scratch instance:Three defects at once: the payload was dropped from
arguments,server_namewas null (so the Server column showed-and server-filtering missed every mutation), and the response diff — which is recorded — stored the env value verbatim in BBolt.upstream_serversandquarantine_securitybuilt their activity args from a two-field allowlist (operation,name), while read-onlyread_cacherecorded all of its parameters. The two tools that mutate security-relevant configuration logged the least.What this changes
env_json,headers_json,oauth_json,args_json,isolation_json, plus the resolvedconfig_diff. Keys survive, values mask — an operator can see which credential changed without the value.target_serverpopulated, via an allowlist of operations that actually act on a named server. Inventory operations (list,list_quarantined) stay unattributed, so an agent cannot pin activity on a server it never touched, and an unknown operation defaults to unattributed too.--api-key VALUEand--api-key=VALUE), and value-shaped detection via the existinginternal/securitydetector — because a credential passed as a bare argv token has no key to match on._auth_*keys are stripped, so a client can no longer stampUserID/UserEmailon the audit row for a privileged mutation./api/v1/activity/summaryper-server totals, using the existingglanceManagementBuiltinspopulation rather than the accident of an emptyServerName.••••) — no trailing bytes, no length — so a persisted record does not carry a credential fingerprint.*_json: a secret-bearing argument that will not parse records a placeholder, not the raw string.Verification
Live instance, adversarial payload covering every shape the reviews flagged:
Note
--session=and--endpoint=— flag names with no sensitive marker — are caught by value shape, which is the gap that survived the first fix round.Gates:
go build ./...,go build -tags server,go test ./internal/... -race, golangci-lint v2 (.github/.golangci.yml) → 0 issues.Review
Three fix→re-review rounds. Findings came from an independent
opencodecross-review (gpt-5.6-sol) and a three-lens adversarial pass (correctness / security / regression); the two converged on the argv leak independently. Final re-review verdict: clean.Every new test was proven to fail against the unfixed code before being committed.
Out of scope
Pre-existing response-path leaks found during this work are filed separately as #1148 (
list_quarantinedreturning raw credentials unauthenticated,tail_log, connection-error strings). They are not fixed here.The
upstream_serverstool description gains aREDACTION (update/patch):note, which moves the frozen tool surface. The delta is description-only and is asserted as such; if you would rather not spend surface churn on a doc sentence, reverting that hunk plus the four golden files leaves the rest intact.