Skip to content

Sanitize sensitive data from log messages to prevent privacy leaks - #950

Merged
nothingmuch merged 1 commit into
payjoin:masterfrom
0xZaddyy:sanitizeLogs
Sep 19, 2025
Merged

nothingmuch merged 1 commit into
payjoin:masterfrom
0xZaddyy:sanitizeLogs

Conversation

@0xZaddyy

Copy link
Copy Markdown
Contributor

This PR introduces a privacy safe logging system.
Closes #821, closes #911

Summary

  • Sanitize sensitive data from log messages across the payjoin codebase
  • Remove transaction outpoints, PSBTs, configuration data, and HTTP request details from logs
  • Preserve debugging functionality while protecting user privacy and financial data
  • Move sensitive logs to trace level or replace with sanitized equivalents

@coveralls

coveralls commented Aug 13, 2025 •

Copy link
Copy Markdown
Collaborator

Pull Request Test Coverage Report for Build 17649056846

Details

  • 7 of 8 (87.5%) changed or added relevant lines in 6 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 86.019%

Changes Missing Coverage Covered Lines Changed/Added Lines %
payjoin-cli/src/app/v1.rs 1 2 50.0%
Totals Coverage Status
Change from base Build 17593913920: 0.0%
Covered Lines: 8232
Relevant Lines: 9570

💛 - Coveralls

@nothingmuch nothingmuch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In some places I think too much information has been redacted.

IMO it's fine for trace logs to contain sensitive data, just debug and higher levels should be safe to share without redaction. Also limiting trace events means otherwise important information might no longer be available at all requiring code modifications to inspect.

In particular with regards to query parameters and psbt, that information is potentially important to analyze sender behavior, because the software might be interacting with a different or even unknown implementation, which may send surprising things.

Comment thread payjoin-cli/src/app/v1.rs Outdated
(&Method::GET, "/bip21") => {
let query_string = req.uri().query().unwrap_or("");
log::debug!("{:?}, {query_string:?}", req.method());
log::trace!("Processing GET /bip21 with query length: {}", query_string.len());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

here just changing to the trace level seems enough to me

Suggested change
log::trace!("Processing GET /bip21 with query length: {}", query_string.len());
log::trace!("{:?}, {query_string:?}", req.method());

Comment thread payjoin/src/core/receive/v1/mod.rs Outdated
Comment on lines +215 to +216
log::warn!(
"Request contains a duplicate input. Preventing possible probing attack."
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::warn!(
"Request contains a duplicate input. Preventing possible probing attack."
);
log::warn!(
"Request contains a duplicate input. Preventing possible probing attack."
);
log::trace!("Input outpoint: {}", input.txin.previous_outpoint);

@0xZaddyy
0xZaddyy force-pushed the sanitizeLogs branch 3 times, most recently from 8235890 to ac09fc2 Compare August 16, 2025 12:45
@0xZaddyy
0xZaddyy requested a review from nothingmuch August 16, 2025 12:46
@nothingmuch

Copy link
Copy Markdown
Contributor

sorry i forgot to re-review this PR... the trace lines that used to print the config and psbt should still print that as long as it's only at trace value, that information is useful for debugging and it's much smoother to set RUST_LOG=foo=trace instead of modifying the code to add new log or print statements if you want to dump the data

@nothingmuch

Copy link
Copy Markdown
Contributor

It would be great if we could get this in before 1.0, since that would make it possible to request debug logs from users with no privacy concerns.

@DanGould

Copy link
Copy Markdown
Member

I'm cool getting this in pre-1.0 so that we can debug more effectively. Just needs a rebase.

@arminsabouri

Copy link
Copy Markdown
Contributor

ping @0xZaddyy
Do you mind give this PR a rebase. Thanks

@nothingmuch

Copy link
Copy Markdown
Contributor

fwiw i still have some outstanding feedback but it's fine to address it after the release

@0xZaddyy
0xZaddyy force-pushed the sanitizeLogs branch 4 times, most recently from e95440a to de13362 Compare September 8, 2025 16:58

@nothingmuch nothingmuch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

sorry i didn't mean to suggest you revert everything, just the the redaction of the psbt

Comment thread payjoin-cli/src/app/v1.rs Outdated
req: Request<Incoming>,
) -> Result<Response<BoxBody<Bytes, hyper::Error>>> {
tracing::debug!("Received request: {req:?}");
log::trace!("Received {} request to {}", req.method(), req.uri().path());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("Received {} request to {}", req.method(), req.uri().path());
tracing::trace!("Received {} request to {}", req.method(), req.uri().path());

Comment thread payjoin-cli/src/app/v1.rs Outdated
(&Method::GET, "/bip21") => {
let query_string = req.uri().query().unwrap_or("");
tracing::debug!("{:?}, {query_string:?}", req.method());
log::trace!("{:?}, {query_string:?}", req.method());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("{:?}, {query_string:?}", req.method());
tracing::trace!("{:?}, {query_string:?}", req.method());

Comment thread payjoin-cli/Cargo.toml Outdated
hyper = { version = "1.6.0", features = ["http1", "server"], optional = true }
hyper-rustls = { version = "0.27.7", default-features=false, features = ["ring"], optional = true }
hyper-util = { version = "0.1.16", optional = true }
log = "0.4.27"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log = "0.4.27"

Comment thread payjoin/src/core/receive/v2/mod.rs Outdated
method = "PUT";
}
tracing::debug!("Payjoin PSBT target: {}", target_resource.as_str());
log::trace!("Payjoin PSBT target: {}", target_resource.as_str());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("Payjoin PSBT target: {}", target_resource.as_str());
tracing::trace!("Payjoin PSBT target: {}", target_resource.as_str());

Comment thread payjoin/src/core/receive/mod.rs Outdated

let psbt = unchecked_psbt.validate().map_err(InternalPayloadError::InconsistentPsbt)?;
tracing::debug!("Received original psbt: {psbt:?}");
log::trace!("Received original psbt: {psbt:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("Received original psbt: {psbt:?}");
tracing::trace!("Received original psbt: {psbt:?}");

Comment thread payjoin/src/core/receive/mod.rs Outdated
let params = Params::from_query_pairs(pairs, supported_versions)
.map_err(InternalPayloadError::SenderParams)?;
tracing::debug!("Received request with params: {params:?}");
log::trace!("Received request with params: {params:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("Received request with params: {params:?}");
tracing::trace!("Received request with params: {params:?}");

);

tracing::debug!("parsed optional parameters: {params:?}");
log::trace!("parsed optional parameters: {params:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log::trace!("parsed optional parameters: {params:?}");
tracing::trace!("parsed optional parameters: {params:?}");

Comment thread payjoin/Cargo.toml Outdated
hpke = { package = "bitcoin-hpke", version = "0.13.0", optional = true }
http = { version = "1.3.1", optional = true }
bhttp = { version = "0.6.1", optional = true }
log = "0.4.27"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
log = "0.4.27"

Comment thread payjoin-cli/src/app/config.rs Outdated
}

log::trace!("App config loaded successfully");
tracing::debug!("App config: {config:?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
tracing::debug!("App config: {config:?}");
tracing::trace!("App config: {config:?}");

Comment thread payjoin-cli/src/app/mod.rs Outdated
psbt.inputs.len(),
psbt.unsigned_tx.output.len()
);
tracing::debug!("Proposed psbt: {psbt:#?}");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
tracing::debug!("Proposed psbt: {psbt:#?}");
tracing::trace!("Proposed psbt: {psbt:#?}");

@nothingmuch nothingmuch left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good, please squash these changes as there is some back and forth, I think everything could take the message of the first commit.

- Remove transaction outpoints, PSBTs, configuration data, and HTTP request details from log output to prevent privacy leaks.
- Move sensitive logs to trace level or replace with sanitized equivalents that preserve debugging

restore previous state back to trace

refactor: replace log with existing tracing

chore: update Cargo lock files
@0xZaddyy

Copy link
Copy Markdown
Contributor Author

Looks good, please squash these changes as there is some back and forth, I think everything could take the message of the first commit.

done, thank you @nothingmuch

@spacebear21 spacebear21 added this to the payjoin-1.0 milestone Sep 18, 2025
@nothingmuch
nothingmuch merged commit 23bfbeb into payjoin:master Sep 19, 2025
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.

Redact Sensitive Log at src/core/receive/v1/mod.rs:215 Scrub Logs

6 participants