Repository navigation
fix(httpapi): refuse config-to-secret for values that embed a reference - #1782
Conversation
The guard only rejected values starting with ${keyring: or ${env:. A
${file:...} reference, or a composite such as "Bearer ${keyring:gh}",
was stored in the keyring as literal text and the field was rewritten
to ${keyring:<name>}. Resolution is single-pass, so the upstream then
received the unresolved reference text as its credential.
Use secret.IsSecretRef so any value containing a reference is refused.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…a reference
Review finding (P2): the broader IsSecretRef guard sends mixed values such
as "postgres://app:hunter2@${env:DB_HOST}/app" to the 400 branch, which
echoed the full value and leaked its literal credential part even with
reveal_secret_headers off. The error now names only the scope and key.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Verified the bug on main and the fix; thank you! The review found one gap, so I pushed a small maintainer commit on top of your branch: with the broader I will merge once CI is green. |
Dumbris
left a comment
There was a problem hiding this comment.
Verified: the bug reproduces on main and the PR fixes it. The review found one gap, closed by the maintainer commit on top (regression test included). Race tests and CI lint for the touched packages are clean on this branch merged with main, and the result was cross-reviewed clean.
|
Merged. Thank you, @rudycelekli! Config-to-secret now refuses Contributions like this are what keep MCPProxy moving, and they matter a lot to the project. One small ask, only if you feel like it: a short public note about your change (a tweet, a LinkedIn post, a line in a community you are part of) helps more people discover MCPProxy. No pressure at all, and I would be glad to repost it. |
Bug
POST /api/v1/servers/{id}/config-to-secretrefuses to convert a value that is already a reference, but the check isstrings.HasPrefix(value, "${keyring:") || strings.HasPrefix(value, "${env:"). Two kinds of values get past it:${file:/path}reference (the provider added in feat(secret): ${file:/absolute/path} references (Spec 111 FR-030) #1717);"Authorization": "Bearer ${keyring:github-token}"(docs/features/keyring-integration.md).For these values the handler stores the literal text in the keyring and rewrites the field to
${keyring:<secret_name>}. Secret expansion runs once, so on the next connect the upstream gets the unresolved text, for exampleBearer ${keyring:github-token}or${file:/run/secrets/github-token}, as its credential.The API masks both values on the read path because
IsConfigReferenceonly passes through an exact${keyring:..}or${env:..}value. The UI therefore shows them as plain secrets and offers Convert-to-secret.Trigger
POST /api/v1/servers/<name>/config-to-secretwith{"scope":"header","key":"Authorization","secret_name":"gh2"}succeeds. After that, the header sent upstream is the literalBearer ${keyring:github-token}.Fix
Use
secret.IsSecretRef(value), which matches any${type:name}reference anywhere in the value. The handler then returns the existing 400 "already a reference" error for these values.Test
Two cases added to
TestHandleConvertConfigToSecret_ValidationErrors: an env value${file:/run/secrets/github-token}and a headerBearer ${keyring:github-token}. Both must be rejected with 400 before the resolver is called.Commands run
CGO_ENABLED=0 go test -count=1 ./internal/httpapi: okserver.goreverted, both new cases fail (expected: 400, actual: 500). The handler gets past validation and reaches the resolver, which the mock leaves nil.go vet ./internal/httpapi,gofmt -l internal/httpapi/: clean