Skip to content

fix(upstream): never send an unresolved secret reference to an HTTP upstream - #1933

Merged
Dumbris merged 4 commits into
mainfrom
fix/f9-unresolved-header-secret
Nov 18, 2026
Merged

Dumbris merged 4 commits into
mainfrom
fix/f9-unresolved-header-secret

Conversation

@Dumbris

@Dumbris Dumbris commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Description

Release QA finding F9: when a configured upstream HTTP header contained a ${keyring:...} reference that could not be resolved, mcpproxy sent the raw text to the upstream (Authorization: Bearer ${keyring:name}), and the server's health stayed green.

Cause. core.NewClientWithOptions expands secret references with ExpandStructSecretsCollectErrors. A field that fails keeps its original value. The failure was only logged, at ERROR, and that log line also carried the field's full value. Nothing stopped the connection.

Changes

  • Refuse before any HTTP request. A secret reference in the url, the headers or the oauth settings that cannot be resolved when the client is built records a core.UnresolvedSecretError on the client. With that error present, the client does not connect (Connect), does not start a sign-in (every manual-login entry point), and does not refresh a token (RefreshOAuthTokenDirect). Nothing is dialled.
  • Actionable error, with no secret values in it. The error names each reference that failed and its field, but never a field value. For example:
    unresolved secret reference ${keyring:my_api_key} in Headers[Authorization]: the secret is not available, so nothing was sent to the upstream. Add it with: mcpproxy secrets set my_api_key, then restart the server (mcpproxy upstream restart my-server)
    If a field mixes references, those that resolve are not named. The error classifies as MCPX_CONFIG_MISSING_SECRET.
  • Health. health.ExtractMissingSecret recognises the error, so the server shows Missing secret (unhealthy, needs_secret) with the set_secret action and the reference name as the detail. It no longer shows green.
  • Scope. The refusal applies only to HTTP-family servers (DetermineTransportType on the resolved config, the same decision Connect makes). Each reference that resolves is still substituted, and other servers are unaffected. A stdio server keeps the existing behaviour for every field: it never sends its headers, url or oauth values, and a missing reference in env, args or working_dir is logged and used as written.
  • Behaviour change. Any unresolvable ${type:name} text in an HTTP server's URL, headers or OAuth settings is now refused rather than sent literally. That includes ${env:NAME} for an unset variable. For ${env:} the fix hint says to restart mcpproxy, because the env provider reads mcpproxy's own environment.
  • Logs. The resolution-failure log names the references only (references: ["${keyring:x}"]), never the field's value.
  • Restart after the secret is added. mcpproxy upstream restart already builds a new client, which resolves secrets again. Storing a secret through REST or the Web UI (NotifySecretsChanged) restarted only servers that referenced it in env or args. It now also restarts servers that reference it in the URL, headers, working directory or OAuth settings. It also skips disabled servers, because a restart enables a disabled server; until now, storing or deleting a secret re-enabled a disabled stdio server that used it.
  • Docs. docs/errors/MCPX_CONFIG_MISSING_SECRET.md gains "HTTP upstreams: nothing is sent" and the restart step.

Testing

  • I have tested these changes locally
  • I have added/updated tests that prove my fix is effective or my feature works
  • All existing tests pass

internal/runtime/unresolved_header_secret_test.go runs through the normal configuration and connection path (runtime.New → StartBackgroundInitialization). It uses a fake keyring and real streamable-HTTP MCP upstreams that record every request and its headers. The server under test has Authorization: Bearer ${keyring:f9-missing} (missing) and X-Present: ${keyring:f9-present} (present). The test checks that:

  • the unrelated server connects;
  • the server with the missing secret sends no request;
  • its last_error names the reference, the field and the fix;
  • its health is "Missing secret" / set_secret with detail f9-missing.

After the key is added, the server connects with Bearer <value> and the valid X-Present substitution. No request ever carries ${keyring:. This is run in two subtests: one through RestartServer, one through NotifySecretsChanged (storing the secret through the API). Every log entry is checked for the secret values.

On main the same test fails: the upstream received Authorization: Bearer ${keyring:f9-missing}. The API subtest also fails if the header scan is removed from serverReferencesSecret.

internal/upstream/core/unresolved_secrets_test.go covers:

  • one header mixing literal text, a reference that resolves and a missing one: only the missing one is named, and neither the literal nor the resolved value appears in the error or the logs;
  • connect, sign-in (guard and quick start) and token refresh: all refused with zero requests;
  • classification and health extraction;
  • the URL and OAuth.ClientSecret cases;
  • a stdio env reference and a header whose references all resolve: neither is blocked.

Race tests pass for ./internal/upstream/..., ./internal/runtime, ./internal/httpapi, ./internal/secret/..., ./internal/health/..., ./internal/diagnostics/... and ./internal/config/.... golangci-lint with .github/.golangci.yml, bare and with --build-tags=server, reports 0 new issues.

Independent review: an Opus 5.5 agent with fresh context, two rounds.

  • Round 1 found no MAJOR issues and 4 MINOR plus 6 NIT findings. Fixed: the stdio transport gate, the ${env:} hint, skipping disabled servers, the provider reason restored in the log, the log checks covering array fields, both sign-in flows tested with OAuth applicable, the race fallback, and the docs.
  • Left as they are: transient parking (TestTransientCodes_StayRetryable pins it deliberately) and the gaps below that predate this PR.
  • Round 2: CLEAN. Its two NITs are applied in 3baa5d2fc.

Not covered / known gaps:

  • A reference that becomes resolvable later is only picked up by a restart, or automatically when the secret is stored through REST or the Web UI. A mcpproxy secrets set run while no core is running needs mcpproxy upstream restart <server>; the error says so.
  • secret.Resolver.ExtractConfigSecrets (the Web UI's secret listing) does not walk maps, so header references are not listed there. This predates this PR and is unchanged.
  • These gaps predate this PR and are left as follow-ups:
    • serverReferencesSecret does not scan the isolation fields.
    • The server edition's AuthBroker.ClientSecret is not expanded on the broker path.
    • httpapi.checkMissingSecrets ignores headers.
    • The login REST endpoint answers this refusal with a 500 rather than a coded 409.
  • Related, but a different defect: contributor PR feat(secret): secret_file_dirs allow-list for ${file:} and MCPPROXY_API_KEY_FILE, upstream secret guards (#1721) #1884 adds a secret_file_dirs policy for ${file:} references and its own connect-time refusal. The two touch nearby code in internal/upstream/core; whichever merges second may need a small rebase.

…pstream

Release QA F9: a ${keyring:...} reference that could not be resolved in a
configured header was sent to the upstream verbatim
("Authorization: Bearer ${keyring:name}") and health stayed green. The core
client logged the failure and kept the raw value.

- A secret reference in the URL, headers or OAuth settings that cannot be
  resolved when the client is built now makes the client refuse to connect,
  sign in or refresh a token, before any HTTP request
  (core.UnresolvedSecretError). The error names the reference and field, never
  a value, and says how to add the secret and restart the server. It
  classifies as MCPX_CONFIG_MISSING_SECRET and health shows "Missing secret"
  with the set_secret action. References that resolve on the same server and
  other servers are unaffected; local stdio fields keep the old behaviour.
- The resolution-failure log names the references only, not the field value.
- Storing a secret through REST or the Web UI restarted only servers that
  referenced it in env or args; servers referencing it in the URL, headers or
  OAuth settings are now restarted too.

Tests go through the runtime: a missing synthetic keyring key is refused with
nothing sent, an unrelated server connects, and after the key is added an
upstream restart (or storing the secret through the API) connects with the
resolved header and keeps a valid substitution; no secret value is logged.
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: dc86405
Status: ✅  Deploy successful!
Preview URL: https://7e931d09.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-f9-unresolved-header-sec.mcpproxy-docs.pages.dev

View logs

Review r1 on the F9 fix:
- Only an HTTP-family server sends its URL, headers and OAuth settings, so a
  stale reference in those fields of a stdio server no longer stops it.
- The fix hint for ${env:NAME} says to restart mcpproxy: the env provider
  reads mcpproxy's own environment, which a server restart cannot change.
- A field whose references resolve on a second look is reported with its
  first reference, so health still reads "Missing secret".
- The resolution-failure log carries the provider's reason again (it names
  references only), so "keyring unavailable" and "not found" stay apart.
- Storing or deleting a secret no longer restarts, and so re-enables, a
  disabled server that references it.
- Tests check every logged field (arrays too), exercise both sign-in flows
  with OAuth applicable, the hints, the reference scan and the disabled skip.
- Docs: ${env:} and other ${type:name} text in those fields is now refused
  when it cannot be resolved; which restart picks a secret up.
@Dumbris
Dumbris enabled auto-merge (squash) November 18, 2026 17:49
@Dumbris
Dumbris disabled auto-merge November 18, 2026 19:08
@Dumbris
Dumbris enabled auto-merge (squash) November 18, 2026 19:09
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/f9-unresolved-header-secret

Available Artifacts

  • archive-darwin-amd64 (33 MB)
  • archive-darwin-arm64 (29 MB)
  • archive-linux-amd64 (20 MB)
  • archive-linux-arm64 (18 MB)
  • archive-windows-amd64 (32 MB)
  • archive-windows-arm64 (29 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (29 MB)
  • installer-dmg-darwin-arm64 (26 MB)
  • smart-mcp-proxymcpproxy-goV3Q8AO.dockerbuild (0 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 44377578287 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@codecov-commenter

codecov-commenter commented Nov 18, 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 81.51261% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/upstream/core/unresolved_secrets.go 70.90% 10 Missing and 6 partials ⚠️
internal/health/calculator.go 14.28% 5 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Dumbris
Dumbris merged commit 78e6938 into main Nov 18, 2026
55 checks passed
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.

2 participants