Repository navigation
fix(security): redact rpc_url from chain-RPC transport errors (#954) - #958
Conversation
Any failed chain-RPC call surfaced the full `rpc_url` — including the path/query where Infura/Alchemy API keys live — in operator output. reqwest's Display appends ` for url (<url>)` and alloy forwards it transparently; both binaries' `main()` returned `anyhow::Result` (Debug prints the whole source chain), and the daemon additionally logs chain errors via `tracing` `warn!(%err)`. Add a shared sanitizer in `decdn-common::redact` (`strip_urls`, `sanitize_rpc_display`, `sanitize_err_chain`) and apply it at every boundary where a chain-RPC error reaches output: - CLI + daemon `main()` become `ExitCode` chokepoints that print the sanitized chain — covers all propagated commands and fatal bring-up. - Daemon mid-run `tracing` sites (chain_staker_set, chain_origin_directory, node_address, reputation_indexer, payment_settlement, buyer_channel, runtime watchers/bootstrap) route the rendered error through the sanitizer; non-RPC store/IO/lock renders are left untouched. - `bundle pull` sanitizes per-entry failures at construction (they bypass `main()` via stderr + the `--json` report). - `discovery` parse-error path aligns to the `<redacted> (N chars)` form used by `chain_ctx` / `setup`. `strip_urls` keys off the `://` separator so it scrubs any scheme/case as a backstop, in addition to dropping reqwest's ` for url (...)` clause. Tests: unit cases for the sanitizer (uppercase/any-scheme, query-only and userinfo secrets, URL-only, multiple/unterminated clauses, UTF-8 safety) plus an integration test driving the real `decdn` binary against an unreachable RPC, asserting the key never reaches stdout/stderr. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request addresses issue #954 by implementing robust credential and URL redaction across CLI commands and node services to prevent sensitive rpc_url secrets (such as Infura/Alchemy API keys in paths or queries) from leaking into logs, stderr, or JSON reports. It introduces utility functions in crates/common/src/redact.rs to strip entire URLs from error chains and transport failures, updates main entry points and logging sites to use these sanitizers, and adds a regression test. Feedback on the PR suggests an optimization in strip_urls to avoid an unnecessary string allocation when processing owned strings that do not contain bare URLs.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #954 by preventing chain-RPC transport failures from leaking the configured rpc_url (including path/query API keys) into operator-facing output. It introduces shared URL-stripping sanitizers in decdn-common and applies them at the main error-print boundaries and at mid-run tracing log sites across the daemon and CLI.
Changes:
- Added
strip_urls+sanitize_rpc_display/sanitize_err_chainhelpers incrates/commonand unit tests for URL stripping behavior. - Switched both binaries’
main()to print a sanitized error chain and returnExitCode, avoidinganyhow’s default termination printing of the full source chain. - Routed daemon mid-run
warn!/error!sites (and CLI bundle pull per-entry failures) through the sanitizer; added an end-to-end CLI integration regression test.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/common/src/redact.rs | Implements URL stripping/sanitizing helpers and adds unit tests. |
| crates/cli/src/main.rs | Prints sanitized error chains at the CLI boundary and returns ExitCode. |
| crates/node/src/main.rs | Prints sanitized error chains at the daemon boundary and returns ExitCode. |
| crates/node/src/runtime/mod.rs | Sanitizes tracing output for chain-RPC failures (bootstrap + watchdog). |
| crates/node/src/reputation_indexer.rs | Sanitizes watcher RPC error logs. |
| crates/node/src/payment_settlement.rs | Sanitizes chain-RPC related logs in settlement paths. |
| crates/node/src/dht/node_address.rs | Sanitizes node-address watcher RPC error logs. |
| crates/node/src/dht/chain_staker_set.rs | Sanitizes staker-set watcher and resolve failure logs. |
| crates/node/src/dht/chain_origin_directory.rs | Sanitizes origin-directory watcher/resolve failure logs. |
| crates/node/src/buyer_channel.rs | Sanitizes buyer-channel chain-RPC error logs. |
| crates/cli/src/commands/bundle_pull.rs | Sanitizes per-entry failures that bypass main() and can be serialized to JSON. |
| crates/cli/src/commands/discovery.rs | Updates malformed-URL parse error messaging to fully redact rpc_url. |
| crates/cli/tests/setup_redacts_rpc_error.rs | Adds end-to-end regression test to ensure rpc_url does not leak in CLI output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Coverage reportTotal: 83.79% (was 83.68%, ▲ +0.11%) — 39375/46991 lines
History
|
…assertion Review feedback (gemini-code-assist, copilot): - strip_urls: skip the redundant clone in the owned-no-URL fast path. - remove_for_url_clauses / redact_bare_urls: a `)` (or other sub-delim) can appear unescaped in a URL path/query, and stopping the scan there would strand the secret-bearing tail. Scan the whitespace-free URL token to the next whitespace/end instead; over-consuming adjacent punctuation is safe, leaking a secret is not. Add a regression test for a `)`-bearing URL. - redact_bare_urls: walk back over the full RFC-3986 scheme charset (alnum + `+` `-` `.`) so `git+ssh://…` etc. are covered, matching the "any scheme" doc. - discovery.rs: reword the redaction comment to describe the policy rather than claim an exact format match. - setup_redacts_rpc_error: the host:port assertion still checked the stale `127.0.0.1:1` after the switch to an ephemeral refused port; assert against the actual host:port and the full rpc_url instead. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
* fix: keep the RPC URL out of sponsord errors and logs reqwest names the URL in its transport errors (` for url (<url>)`) and alloy forwards that text, so a failed chain call printed SPONSORD_RPC_URL, often with a provider API key in its path, in the exit error and in the keeper's and the HTTP API's warnings. - ChainPool renders each chain-call error's cause chain with the URLs stripped (decdn_common::redact::strip_urls), so its errors keep the failure class (connection refused, timeout, DNS, TLS) and never carry the URL. - The keeper and HTTP log sites go through sanitize_err_chain / sanitize_rpc_display as a backstop. - main() prints its error through sanitize_err_chain instead of returning it to anyhow's Termination impl, as decdn-node does (decdn/decdn#958). FakePool's failures now read like reqwest's error and name FAKE_RPC_URL, and test_support gains CapturedLog, so the failure tests also assert that the key never reaches a log line. A binary test checks the exit error. Closes #38 Co-Authored-By: Claude Opus 5.5 <[email protected]> * test: cover the keeper's remaining-read warning redaction Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix: close the remaining RPC URL leaks and keep decdn's top-up markers Review follow-ups for #38: - RUST_LOG=debug printed the URL on every chain call: alloy's `ReqwestTransport` debug span records it, and every event inside the span (reqwest's, hyper's) prints the span's fields. main() now builds the RUST_LOG filter itself with `alloy_transport_http=info` added, which only drops that span and alloy's own debug/trace events. - `--help` printed SPONSORD_RPC_URL's value; it is now hidden like the token and password. - `ChainConfig`'s Debug showed the URL; it now shows its length. - Flattening `top_up` errors to text lost decdn's `TopUpUnconfirmed` and `AllowanceShortfall` markers, which callers downcast on (the former means the top-up may have mined). `redacted_top_up` re-attaches them. - The http.rs log sites used `sanitize_rpc_display` on an anyhow::Error, which renders only the outermost message; they use `sanitize_err_chain` now. - The listener is bound before the keeper starts, so a bind failure can no longer drop a top-up between the approve and the top-up. Adds unit tests for `redacted()` and the marker handling, a closed-port test of every ChainPool method, a `--help` test, and a binary test at RUST_LOG=trace. Fixes the doc on main (the Termination impl is std's), the changelog wording, and moves sponsord-core's Security section last. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
Summary
Fixes #954. Any failed chain-RPC call surfaced the full
rpc_url— including the path/query where Infura/Alchemy API keys live — in operator-facing output.reqwest'sErrorDisplay appendsfor url (<url>),alloy's#[error("{0}")]-transparent transport error forwards it verbatim, and:main()returnedanyhow::Result<()>, so theTerminationimplDebug-prints the entire source chain → raw URL; anddecdn-nodedaemon additionally logs chain errors mid-run viatracingwarn!(%err).This bypassed the established policy that
config validatealready follows (rpc_url: <redacted> (N chars)).Approach
A shared sanitizer in
decdn-common::redact, applied at every boundary where a chain-RPC error reaches output:strip_urls— drops reqwest'sfor url (...)clause and, as a backstop, redacts any bare<scheme>://token (keys off://so it covers any scheme/case). Borrows through clean text.sanitize_rpc_display(tracing sites) /sanitize_err_chain(main()boundaries).Applied via:
main()chokepoints (ExitCode, print the sanitized chain) — one edit each covers all propagated commands and fatal bring-up.tracingsites acrosschain_staker_set,chain_origin_directory,node_address,reputation_indexer,payment_settlement,buyer_channel, andruntimewatchers/bootstrap. Each%errrendering of a chain-RPC error is routed through the sanitizer; non-RPC store/IO/lock/validation renders are left untouched.bundle pullsanitizes per-entry failures at the singleEntryOutcome::failedconstruction site (they bypassmain()via stderr and the--jsonreport).discoveryparse-error path aligned to the<redacted> (N chars)form used bychain_ctx/setup.The
runtimeRPC watchdog (probe_rpc) was already URL-safe (%erris plain Display = URL-free anyhow top context) but was sanitized anyway for robustness and its stale userinfo-only comment rewritten.Tests
for url (...)clauses, UTF-8 safety.crates/cli/tests/setup_redacts_rpc_error.rs) drives the realdecdnbinary (setup --dry-runagainst an unreachable ephemeral port with a fake key in the path) and asserts the key/host never reach stdout/stderr while the failure class survives.Verification
cargo clippy --all-targetsclean ·cargo fmt -- --checkcleandecdn-common+decdn-cli+decdn-nodesuites: 1517 tests passReview
This PR incorporates findings from a multi-agent review (code quality, silent failures, test coverage, comments): three additional missed daemon leak sites, the
bundle pullstderr/JSON leak, the uppercase-scheme backstop gap, and the stale module/watchdog comments were all caught and fixed before opening.🤖 Generated with Claude Code