Repository navigation
fix(security): redact env secrets and URL query params in server listings - #875
Conversation
…ings (#872) Server listings masked header values but returned env values and URL query secrets in clear text at all three parity seams (upstream_servers MCP list, GET /api/v1/servers, and the SSE servers.changed payload), and echoed the raw upstream URL (query secrets and all) into connection_status.last_error / health.detail on connect failure. Add two helpers next to the #425 header redactors in internal/oauth/logging.go: RedactEnvValues (masks values under sensitive-looking keys via MaskValue, references pass through, non-sensitive keys stay readable) and RedactURLQueryParams (net/url parse, masks sensitive query values while leaving the path, non-sensitive params, and ${env:}/${keyring:} references verbatim). Apply both at all three seams gated by the existing reveal_secret_headers flag, and scrub URL secrets out of last_error / health.detail with RedactSensitiveData. Rename the httpapi/runtime redactServerHeaders methods to redactServerSecrets to reflect the wider scope; REST↔SSE parity is preserved so the Web UI merge does not flicker. Write paths (PATCH deep-merge) are untouched.
…ings (#872) The #872 redaction masked env/URL/header secrets and scrubbed last_error / health.detail, but the Spec 044 structured diagnostic.cause echoes the same raw connect error verbatim, leaking the full upstream URL (query secrets and all) through GET /api/v1/servers and the SSE servers.changed payload. Scrub Diagnostic.Cause with RedactSensitiveData at both parity seams (httpapi redactServerSecretFields + runtime redactServerSecrets), in parity with the existing last_error / health.detail scrub. Also update two stale E2E assertions that expected plaintext env values under sensitive-looking keys (TEST_KEY, API_KEY); #872 now masks those, so assert the masked-display format instead — matching the headers assertion the fix already updated.
…r/tray Follow-up to the #872 redaction work; the initial fix masked the servers list/SSE/MCP seams but left three sibling surfaces leaking the same URL/env secrets: - macOS tray saveEdits() sent the full env map unconditionally before the diff, so an unchanged secret round-tripped the read-path mask (`••••23 (14 chars)`) and PATCH deep-merge upserted the mask over the real on-disk plaintext. Drop the unconditional send; rely on diffKVMap (upsert + NSNull delete), mirroring headers. - GET /api/v1/servers/{id}/diagnostics returned health.detail and diagnostic.cause raw from GetAllServers, bypassing redaction. Scrub both, gated on reveal_secret_headers. - management.Doctor() (and the httpapi legacy diagnostics fallback) copied unscrubbed health.detail/last_error into UpstreamErrors; scrub them in parity with the list route. Also close two acknowledged gaps on the same seams: add sig/signature to the free-form RedactSensitiveData param list (Azure-SAS URL secrets), and mask basic-auth userinfo passwords in RedactURLQueryParams.
Deploying mcpproxy-docs with
|
| Latest commit: |
9c1ac11
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c6aa4492.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-872-redact-env-url.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 29825849868 --repo smart-mcp-proxy/mcpproxy-go
|
…cs (#872) Address cross-model review findings on the secret-redaction work: - Mask-aware write path (URL/env/headers): the read path masks secrets in the server URL query string and userinfo, but `url` is a single string field with no client-side diff. A client editing a non-secret part and echoing the masked value back would persist the mask over the real credential. RedactURLQueryParams/RedactEnvValues/RedactStringHeaders now have UnmaskURL/UnmaskEnvValues/UnmaskHeaders counterparts applied in both write paths (REST PATCH and MCP upstream_servers update/patch), so an echoed mask is reverted to the stored real value while genuine edits persist. Protects all clients, not just the tray. - Connection-string env vars: values that parse as a URL with userinfo (DATABASE_URL, REDIS_URL, ...) now mask only the password, keeping scheme/host/db readable. DSN / CONNECTION_STRING / CONN_STR keys are added to the whole-value sensitive markers. - URL query redaction now matches on a normalized param name (lowercase, '-'/'_' stripped) against a normalized sensitive set extended with X-Amz-Credential/Signature/Security-Token, authToken and access-token variants; "credential" added to the regex scrubber set for free-form error/health.detail strings. - isConfigReference requires a syntactically complete ${keyring:...} / ${env:...} reference (anchored regex) so a composite like ${env:NAME}garbage is masked instead of passing through unmasked.
#872) Round-2 review hardening of the mask-aware write path: - UnmaskURL now refuses to move a stored secret onto a different scheme/host: a restore happens only when incoming keeps the stored scheme and host:port (and, for the userinfo password, the same username). Redirecting the URL to another host leaves the mask literal so the write fails validation instead of leaking the real credential. - Duplicate sensitive query keys are restored positionally (i-th masked occurrence <- i-th stored occurrence) and only when the incoming and stored occurrence counts for that key match; a mismatch leaves the masks literal rather than guessing. - UnmaskEnvValues unmasks URL-shaped values under non-sensitive keys component-wise via UnmaskURL, so editing a non-secret part of a connection string (db name, an option) restores just the password component — with the same authority safeguard — instead of persisting the password mask as the real password. Whole-value masks (sensitive keys, RedactSensitiveData fallback) keep the exact-match revert.
…ed URL env values (#872) Round-3 review edge case: a URL-shaped value under a non-sensitive env key that is a MALFORMED URL is masked by RedactURLQueryParams via its RedactURL regex fallback (url.Parse fails). The component-wise UnmaskURL branch also fails to parse it and returns the mask unchanged, so an unedited echo would persist the mask over the stored secret. Reorder UnmaskEnvValues to try the whole-value revert (incoming == maskedEnvValue(key, stored) -> stored) BEFORE the component-wise UnmaskURL branch, so a malformed masked value round-trips back to the real secret. Well-formed URL-shaped values with a genuine edit still fall through to component-wise UnmaskURL (with the authority safeguard).
|
Cross-model review (Codex): clean after 4 rounds. R1: masked-URL round-trip on the tray write path + heuristic gaps (DSN-style env vars, param-name variants, unanchored ${env:} refs). R2 caught a high in the new unmask helper — restoring a stored secret onto a changed host — now authority-safe and component-wise. R3: malformed-URL mask persistence edge case. R4: ACCEPT. CI green except the main-broken CodeQL canary ( |
Fixes #872
Server listings masked header values (#425) but returned env values and URL query secrets (
?access_token=…&client_secret=…) in clear text on all three parity seams: MCPupstream_servers list, RESTGET /api/v1/servers, and the SSEservers.changedpayload. Repro also showed the raw URL echoing intoconnection_status.last_error/health.detailon connect failures.Change
internal/oauth/logging.go:RedactEnvValues— masks values of secret-looking env keys (TOKEN/SECRET/KEY/PASSWORD/…) as••••<last2> (<N> chars);${env:…}/${keyring:…}references stay visible; non-sensitive keys (e.g.LOG_LEVEL) stay readable; nil-in/nil-out.RedactURLQueryParams—net/url-based (not the regexRedactURL, which would mask reference values); masks sensitive query param values, keeps references visible, preserves URL validity.reveal_secret_headersflag; also scrubs URL secrets fromlast_error/health.detail/diagnostic.cause./api/v1/diagnostics+ doctor no longer leak the raw connect error; macOS traysaveEditsno longer sends the full (masked) env map back — it now diffs like headers, which also fixes a latent bug where an unrelated tray edit could persist masked values over real secrets.Verification
API_KEY/MY_TOKENmasked,LOG_LEVELreadable,${env:HOME}shown as reference; zero plaintext-secret hits grepping full MCP+REST responses; PATCH round-trip left the on-disk secret intact.go test -racegreen across oauth/httpapi/runtime/server (three stale plaintext-env assertions updated to the masked contract), 65/65 API E2E green, lint clean.Draft: @neylwalecki mentioned having a patch for this — happy to reconcile.