feat: redact secret key material in credential toString()#90
Merged
Conversation
KeyCredential and NamedKeyCredential hold secret key material in plain fields. Any code path that stringified them — a log line, an exception message, or a debugger view — could surface the raw secret. Override toString() on both so the key is never rendered: KeyCredential emits `apiKey=***` while keeping the non-secret headerName and prefix, and NamedKeyCredential emits `key=***` while keeping the non-secret name. This matches the existing redaction on BearerToken. The override is toString-only: these are reference types with identity equality, and that behaviour is preserved (covered by tests). Adding an explicit toString() surfaces it as a declared public member, so the sdk-core API snapshot is regenerated accordingly.
The default-fields redaction test only asserted the secret was masked. Add an assertion that the non-secret headerName (Authorization) is still rendered, so the test pins both halves of the contract like the explicit-fields test does.
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
KeyCredentialandNamedKeyCredentialhold secret key material. They are plain classes (notdata classes), so today they inheritObject's identitytoString()and don't actually leak the secret — but they also have no explicit, safe string form. This adds redactingtoString()overrides so the secret can never surface through logs, exception messages, or a debugger, and stays masked under any future change (e.g. a promotion todata class). This matches the existing redaction onBearerToken.KeyCredential→KeyCredential(apiKey=***, headerName=…, prefix=…)NamedKeyCredential→NamedKeyCredential(name=…, key=***)Identity-equality semantics are unchanged (no
equals/hashCodeintroduced). New tests assert the secret never appears while the mask and non-secret fields do. The now-declaredtoString()is reflected in the API snapshot.Closes #47