Skip to content

fix: redact authorization tokens from trace logs - #218

Merged
oleonardolima merged 3 commits into
bitcoindevkit:masterfrom
EddieHouston:fix/redact-authorization-trace
Jul 23, 2026
Merged

fix: redact authorization tokens from trace logs#218
oleonardolima merged 3 commits into
bitcoindevkit:masterfrom
EddieHouston:fix/redact-authorization-trace

Conversation

@EddieHouston

@EddieHouston EddieHouston commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

fixes #215.

Description

The authorization token added via AuthProvider (#194) was logged verbatim
at TRACE level in call and batch_call, since both traced the raw wire
bytes.

This redacts the token before serialization instead of inspecting serialized
bytes:

  • new crate-private Request::redacted returns a copy of the request with the
    token replaced by <REDACTED>
  • call traces the redacted request; batch_call collects its requests into
    a Vec and derives both the wire bytes and the trace output from it

Notes to the reviewers

Redacting the struct before serialization removes the JSON re-parse and the
fail-closed path of the previous approach, and keeps the trace line in the
same field order as the wire format. batch_call still attaches the token
only to the first request of the batch.

Changelog notice

### Fixed

- Fix `authorization` token leaking into TRACE logs in `call` and `batch_call` #218

Checklists

All Submissions:

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@EddieHouston

Copy link
Copy Markdown
Contributor Author

note... had to pin zeroize in new commit due to MSRV:
image

@sdmg15 sdmg15 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tAck ab750e3.

I also tested a case in batch requests where one is valid json and another is not and in the logs we have ==> <request redaction failed>

Comment thread src/raw_client.rs Outdated
let redacted = redact_authorization(raw);
let request: serde_json::Value = serde_json::from_slice(&redacted).unwrap();

assert_eq!(request["authorization"], "<redacted>");

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think we can use the constant value REDACTED_AUTHORIZATION here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done. Both test assertions now use REDACTED_AUTHORIZATION.

@EddieHouston
EddieHouston force-pushed the fix/redact-authorization-trace branch 2 times, most recently from f50ec35 to c9372db Compare July 22, 2026 10:35
@oleonardolima
oleonardolima force-pushed the fix/redact-authorization-trace branch from c9372db to 3130ac5 Compare July 22, 2026 17:16
@oleonardolima
oleonardolima force-pushed the fix/redact-authorization-trace branch from 3130ac5 to 3e12007 Compare July 22, 2026 17:22
@oleonardolima oleonardolima added the bug Something isn't working label Jul 22, 2026
@oleonardolima oleonardolima moved this to Needs Review in BDK Chain Jul 22, 2026
@oleonardolima
oleonardolima force-pushed the fix/redact-authorization-trace branch from 3e12007 to a59df78 Compare July 22, 2026 18:32
@oleonardolima

Copy link
Copy Markdown
Collaborator

@EddieHouston I did pushed a commit to fix the CI, and some others with a different approach. Let me know what you think.

I don't want this one to be a breaking change, so we can have it as patch release. However, I think the ideal solution would be to have this constraint at type level as follow-up.

EddieHouston and others added 2 commits July 22, 2026 15:38
- introduce `Request::redacted`, which returns a copy of the request
  with the authorization token replaced by a `<REDACTED>` placeholder
- trace the redacted request in `RawClient::call` instead of the raw
  wire bytes

Signed-off-by: Leonardo Lima <oleonardolima@users.noreply.github.com>
- collect the batch requests into a Vec so the wire bytes and the
  trace log both derive from the same source
- serialize each request through `Request::redacted` in the trace line

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Signed-off-by: Leonardo Lima <oleonardolima@users.noreply.github.com>
@oleonardolima
oleonardolima force-pushed the fix/redact-authorization-trace branch from a59df78 to 77f9c78 Compare July 22, 2026 18:39
@oleonardolima
oleonardolima requested a review from sdmg15 July 22, 2026 18:39
@oleonardolima

Copy link
Copy Markdown
Collaborator

ping @luisschwab

@luisschwab

Copy link
Copy Markdown
Member

@oleonardolima missing the changelog entry

@EddieHouston

Copy link
Copy Markdown
Contributor Author

@EddieHouston I did pushed a commit to fix the CI, and some others with a different approach. Let me know what you think.

I don't want this one to be a breaking change, so we can have it as patch release. However, I think the ideal solution would be to have this constraint at type level as follow-up.

Fine with me, as long as it builds... pinning whatever needs to is great 👍

@sdmg15 sdmg15 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re-tAck 77f9c78

@oleonardolima oleonardolima left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self-ACK 77f9c78

@oleonardolima
oleonardolima merged commit 3c07187 into bitcoindevkit:master Jul 23, 2026
18 checks passed
@github-project-automation github-project-automation Bot moved this from Needs Review to Done in BDK Chain Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Authorization token leaks into TRACE logs (full request is logged)

4 participants