Skip to content

Redact credentials from toString() of authorization, encryption and webhook structures - #224

Open
ffumero2003 wants to merge 4 commits into
masterfrom
fix-structures-redact-tostring-secrets
Open

ffumero2003 wants to merge 4 commits into
masterfrom
fix-structures-redact-tostring-secrets

Conversation

@ffumero2003

Copy link
Copy Markdown

Context

Several structures that hold credentials print them in toString(): B2AccountAuthorization (authorization token), B2FileSseForRequest (SSE-C customer key), B2WebhookConfiguration (HMAC signing secret), B2WebhookCustomHeader (header values) and B2HeadersImpl (Authorization and X-Bz-Server-Side-Encryption-Customer-Key). Applications that log these objects, or exceptions and debug output that include them, write those values in clear text.

Changes

  • toString() replaces the sensitive values with [redacted] (a null value still prints as null). Non-secret fields, including the SSE-C key MD5, are unchanged. B2HeadersImpl matches header names case-insensitively.
  • B2EventNotificationRule.COMPARATOR previously ordered rules by the target configuration's toString(). With the redaction, two rules that differ only in a secret would compare equal and one would be dropped from a TreeSet. Webhook targets are now compared field by field (url, custom headers, signing secret, maxEventsPerBatch). Any other target type falls back to toString() ordering, as before, and never throws.
  • CHANGELOG.md: an [Unreleased] entry for both behavior changes.

No public API or serialized form changes; JSON output is unaffected.

Verification

Claim Test
Each structure's toString() omits its secret and keeps non-secret fields B2AccountAuthorizationTest, B2FileSseForRequestTest, B2WebhookConfigurationTest, B2CustomWebhookHeaderTest, B2HeadersImplTest
Header redaction is case-insensitive B2HeadersImplTest
Rules differing only in a redacted value stay distinct and both survive in a TreeSet; compareTo is consistent with equals B2EventNotificationRuleTest
Unknown target configurations are ordered without throwing B2EventNotificationRuleTest.testCompareToOrdersUnknownTargetConfigurationsWithoutThrowing

Each fix was checked against a deliberate break: restoring the comparator's toString() ordering fails three tests; removing the header redaction fails B2HeadersImplTest; restoring an exception for unknown targets fails 1 of 702 core tests.

$ ./gradlew build
BUILD SUCCESSFUL
54 actionable tasks

@ffumero2003 ffumero2003 self-assigned this Oct 30, 2026

This branch has not been deployed

No deployments
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.

1 participant