Skip to content

fix(security): redact env secrets and URL query params in server listings - #875

Merged
Dumbris merged 7 commits into
mainfrom
fix/872-redact-env-url
Jul 21, 2026
Merged

Dumbris merged 7 commits into
mainfrom
fix/872-redact-env-url

Conversation

@Dumbris

@Dumbris Dumbris commented Jul 21, 2026

Copy link
Copy Markdown
Member

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: MCP upstream_servers list, REST GET /api/v1/servers, and the SSE servers.changed payload. Repro also showed the raw URL echoing into connection_status.last_error/health.detail on connect failures.

Change

  • New helpers next to the security(headers): redact sensitive header values in upstream_servers list and /api/v1/servers #425 code in 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 regex RedactURL, which would mask reference values); masks sensitive query param values, keeps references visible, preserves URL validity.
  • Applied at all three seams, gated by the existing reveal_secret_headers flag; also scrubs URL secrets from last_error/health.detail/diagnostic.cause.
  • Follow-up hardening from review: per-server diagnostics endpoint and /api/v1/diagnostics + doctor no longer leak the raw connect error; macOS tray saveEdits no 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.
  • Write paths untouched: PATCH deep-merge means diff-sending clients never round-trip masked values (verified live).

Verification

  • Live app: headers masked as before; URL query values masked with valid URL structure; API_KEY/MY_TOKEN masked, LOG_LEVEL readable, ${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 -race green 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.

Dumbris added 4 commits July 21, 2026 09:10
…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.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 21, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

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

View logs

@codecov-commenter

codecov-commenter commented Jul 21, 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 82.49027% with 45 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/oauth/logging.go 85.14% 15 Missing and 11 partials ⚠️
internal/httpapi/server.go 71.87% 8 Missing and 1 partial ⚠️
internal/runtime/event_bus.go 50.00% 3 Missing and 3 partials ⚠️
internal/httpapi/diagnostics_per_server.go 80.95% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 21, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/872-redact-env-url

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (22 MB)
  • installer-dmg-darwin-arm64 (20 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 29825849868 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

Dumbris added 3 commits July 21, 2026 14:09
…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).
@Dumbris

Dumbris commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

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 (Analyze (go), not required).

@Dumbris
Dumbris marked this pull request as ready for review July 21, 2026 13:32
@Dumbris
Dumbris merged commit d34a3d2 into main Jul 21, 2026
37 of 38 checks passed
@Dumbris
Dumbris deleted the fix/872-redact-env-url branch July 21, 2026 13:58
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.

upstream_servers list should redact env secrets and sensitive URL query params

2 participants