fix(auth): redact secrets in Debug output for StoredCredentials and StoredAuthorizationState#744
Open
peatey wants to merge 8 commits intomodelcontextprotocol:mainfrom
Open
fix(auth): redact secrets in Debug output for StoredCredentials and StoredAuthorizationState#744peatey wants to merge 8 commits intomodelcontextprotocol:mainfrom
peatey wants to merge 8 commits intomodelcontextprotocol:mainfrom
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.
Fixes modelcontextprotocol#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>
- 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>
Author
|
ok fmt now run (its in the workflow so not sure what happened there, sorry) - issues addressed. |
DaleSeo
reviewed
Mar 12, 2026
DaleSeo
reviewed
Mar 12, 2026
DaleSeo
reviewed
Mar 12, 2026
DaleSeo
reviewed
Mar 12, 2026
DaleSeo
approved these changes
Mar 12, 2026
Member
|
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. 😂 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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]