Uh oh!
There was an error while loading. Please reload this page.
fix(auth): redact secrets in Debug output for StoredCredentials and StoredAuthorizationState - #744
Conversation
…toredAuthorizationState
Removes `Debug` from the derive macros on `StoredCredentials` and
`StoredAuthorizationState` and replaces them with manual `Debug` impls
that print `[REDACTED]` for sensitive fields (access/refresh tokens,
PKCE verifiers, and CSRF tokens), preventing accidental credential
leakage via `{:?}` formatters, log calls, and error chains.
Fixesmodelcontextprotocol#741
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>Adds regression tests for the fix in the previous commit, verifying
that `{:?}` formatting of `StoredAuthorizationState` and
`StoredCredentials` does not emit plaintext secrets.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Remove redundant VendorExtraTokenFields from use super:: in
test_stored_credentials_debug_redacts_token_response (already
imported at module scope)
- Add assert!(debug_output.contains("created_at")) to
test_stored_authorization_state_debug_redacts_secrets to verify
non-secret fields remain visible in Debug output
- Run cargo fmt
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>Co-authored-by: Dale Seo <5466341+DaleSeo@users.noreply.github.com>
peatey
commented
Mar 12, 2026
ok fmt now run (its in the workflow so not sure what happened there, sorry) - issues addressed. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hey @jamadeo, could you help approve/merge this PR? I've fixed the formatting issue on the web, but now it seems like someone else needs to approve it since I've added commits technically. 😂 |
Summary
Fixes#741.
StoredCredentialsandStoredAuthorizationStateboth derived#[derive(Debug)], causing secret fields — OAuth access/refresh tokens, PKCE verifiers, and CSRF tokens — to be printed in plaintext via any{:?}formatter, including log calls andanyhow/thiserrorerror chains.Debugfrom the derive macros on both typesDebugmanually, printing[REDACTED]for sensitive fields and leaving non-secret fields (e.g.client_id,created_at) visible{:?}formatting does not emit plaintext secretsApproach notes
OAuthTokenResponsecomes from theoauth2crate and cannot be wrapped directly, soStoredCredentialsuses a manualDebugimpl that redacts the entiretoken_responsefield.The
secrecycrate was considered forStoredAuthorizationState(wrappingpkce_verifier/csrf_tokeninSecretString), butsecrecyintentionally blocksSerializeonSecret<T>unless the inner type implements theSerializableSecretmarker trait — whichStringdoes not, and orphan rules prevent adding it. Since both types areSerialize + Deserializefor use with customCredentialStore/StateStorebackends, field-type changes would break serialization. ManualDebugimpls are the correct approach for both types.Known scope limitation
The fields
pkce_verifier: Stringandcsrf_token: StringonStoredAuthorizationStateremainpub. This fix protects against accidentally formatting the struct via{:?}, but not against a caller extracting the field and formatting it directly (e.g.format!("{:?}", state.pkce_verifier)). This is an inherent limitation of the manual-Debug approach vs. type-level wrapping, and is noted here for reviewer awareness.Test plan
cargo test -p rmcp --features authpassescargo clippy -p rmcp --features authclean (pre-existing unused import warning unrelated to this change)test_stored_authorization_state_debug_redacts_secrets— asserts{:?}output does not contain raw verifier/csrf values and does contain[REDACTED]test_stored_credentials_debug_redacts_token_response— asserts{:?}output does not contain raw access token and does contain[REDACTED]