Skip to content

fix(server): record redacted mutation payloads and target server in the activity log - #1149

Merged
Dumbris merged 3 commits into
mainfrom
fix/1146-activity-payload
Sep 1, 2026
Merged

Dumbris merged 3 commits into
mainfrom
fix/1146-activity-payload

Conversation

@Dumbris

@Dumbris Dumbris commented Aug 31, 2026

Copy link
Copy Markdown
Member

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 main against a scratch instance:

tool: upstream_servers   server_name: None
ARGUMENTS: {"name": "qa-inherit", "operation": "patch"}
RESPONSE contains secret: True
RESPONSE: ..."env":{"path":"env","from":null,
           "to":{"QA_SECRET_TOKEN":"sk-super-secret-value-12345"}}...

Three defects at once: the payload was dropped from arguments, server_name was 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_servers and quarantine_security built their activity args from a two-field allowlist (operation, name), while read-only read_cache recorded all of its parameters. The two tools that mutate security-relevant configuration logged the least.

What this changes

  • Full payload captured, with redaction: env_json, headers_json, oauth_json, args_json, isolation_json, plus the resolved config_diff. Keys survive, values mask — an operator can see which credential changed without the value.
  • target_server populated, 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.
  • Response diff redacted before it reaches either the MCP response or the activity record.
  • argv secrets masked by two rules: the flag names the credential (--api-key VALUE and --api-key=VALUE), and value-shaped detection via the existing internal/security detector — because a credential passed as a bare argv token has no key to match on.
  • Caller-forged identity dropped: _auth_* keys are stripped, so a client can no longer stamp UserID/UserEmail on the audit row for a privileged mutation.
  • Management chatter excluded from /api/v1/activity/summary per-server totals, using the existing glanceManagementBuiltins population rather than the accident of an empty ServerName.
  • Fixed mask marker on audit surfaces (••••) — no trailing bytes, no length — so a persisted record does not carry a credential fingerprint.
  • Fail-closed on malformed *_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:

server_name: 'qa-inherit'
  LEAKS slack-token (xoxb-…):   False
  LEAKS gh-token (ghp_…):       False
  LEAKS api-key (sk-live-…):    False
  LEAKS header (X-AuthToken):   False
  LEAKS env value:              False
  forged _auth_user_id present: False

ARGS: {"args_json": ["srv", "--session=xoxb…****", "--endpoint=ghp_…****",
                     "--api-key", "••••"], "config_diff": {...}}

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 opencode cross-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_quarantined returning raw credentials unauthenticated, tail_log, connection-error strings). They are not fixed here.

The upstream_servers tool description gains a REDACTION (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.

…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.
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

@github-actions

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/1146-activity-payload

Available Artifacts

  • archive-darwin-amd64 (29 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (29 MB)
  • archive-windows-arm64 (26 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (23 MB)
  • installer-dmg-darwin-arm64 (21 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 33418347024 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

codecov-commenter commented Aug 31, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 79.75709% with 50 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/mcp.go 57.14% 21 Missing and 9 partials ⚠️
internal/server/mcp_activity_args.go 90.20% 9 Missing and 5 partials ⚠️
internal/storage/activity_call_population.go 0.00% 4 Missing ⚠️
internal/oauth/logging.go 93.10% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit 607a80e into main Sep 1, 2026
44 of 45 checks passed
@Dumbris
Dumbris deleted the fix/1146-activity-payload branch September 1, 2026 02:39
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Activity log drops the payload of upstream_servers / quarantine_security mutations (records only operation + name)

2 participants