Repository navigation
Commit 607a80e
authored
fix(server): record redacted mutation payloads and target server in the activity log (smart-mcp-proxy#1149)
* fix(server): record redacted mutation payloads and the target server in activity (smart-mcp-proxy#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.
* fix(server): mask argv secrets and stop caller-forged attribution in activity
Cross-model review of smart-mcp-proxy#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 smart-mcp-proxy#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.
* fix(server): close the remaining activity-redaction leaks (round 3)
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.1 parent 84ef98c commit 607a80e
14 files changed
Lines changed: 1926 additions & 91 deletions
File tree
- internal
- httpapi
- oauth
- server
- testdata/toolslist_goldens
- storage
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
757 | | - | |
| 757 | + | |
| 758 | + | |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
758 | 772 | | |
759 | 773 | | |
760 | 774 | | |
761 | 775 | | |
762 | | - | |
763 | 776 | | |
764 | 777 | | |
765 | 778 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
50 | 72 | | |
51 | 73 | | |
52 | 74 | | |
| |||
58 | 80 | | |
59 | 81 | | |
60 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
61 | 89 | | |
62 | 90 | | |
63 | 91 | | |
| |||
159 | 187 | | |
160 | 188 | | |
161 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
162 | 205 | | |
163 | 206 | | |
164 | 207 | | |
165 | 208 | | |
166 | 209 | | |
167 | 210 | | |
168 | | - | |
| 211 | + | |
169 | 212 | | |
170 | 213 | | |
171 | 214 | | |
| |||
191 | 234 | | |
192 | 235 | | |
193 | 236 | | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
194 | 247 | | |
195 | 248 | | |
196 | 249 | | |
| |||
218 | 271 | | |
219 | 272 | | |
220 | 273 | | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
221 | 280 | | |
222 | 281 | | |
223 | 282 | | |
224 | 283 | | |
225 | 284 | | |
226 | | - | |
| 285 | + | |
227 | 286 | | |
228 | 287 | | |
229 | 288 | | |
| |||
239 | 298 | | |
240 | 299 | | |
241 | 300 | | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
242 | 305 | | |
243 | | - | |
| 306 | + | |
244 | 307 | | |
245 | 308 | | |
246 | | - | |
| 309 | + | |
247 | 310 | | |
248 | 311 | | |
249 | 312 | | |
| |||
302 | 365 | | |
303 | 366 | | |
304 | 367 | | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
305 | 374 | | |
306 | 375 | | |
307 | 376 | | |
| |||
318 | 387 | | |
319 | 388 | | |
320 | 389 | | |
321 | | - | |
| 390 | + | |
322 | 391 | | |
323 | 392 | | |
324 | 393 | | |
| |||
351 | 420 | | |
352 | 421 | | |
353 | 422 | | |
354 | | - | |
| 423 | + | |
355 | 424 | | |
356 | 425 | | |
357 | 426 | | |
| |||
382 | 451 | | |
383 | 452 | | |
384 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
385 | 487 | | |
386 | 488 | | |
387 | 489 | | |
| |||
0 commit comments