Skip to content

fix: hide credentials in regtest errors - #203

Merged
ovitrif merged 3 commits into
masterfrom
fix/regtest-url
Nov 11, 2026
Merged

ovitrif merged 3 commits into
masterfrom
fix/regtest-url

Conversation

@ovitrif

@ovitrif ovitrif commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #201 from @coreyphillips's review.

This PR:

  • joins regtest/<path> onto the Blocktank base URL with Url::join, as the Blocktank client does, so a base URL with a query string (https://host/api/?x=1) still targets /api/regtest/...
  • removes credentials embedded in the base URL from regtest error messages
  • when auth is given, drops credentials embedded in the base URL from the request, so it carries a single Authorization header with auth
  • adds the auth parameter to the regtest signatures in both READMEs and notes that staging requires it

Tests

  • regtest_url_tests: the query-string base URL joins to /api/regtest/chain/mine; a user:secret@ base URL never shows secret in regtest_mine's error; with auth and URL credentials, the built request has exactly one Authorization header, from auth
  • test_regtest_mine and test_regtest_deposit still pass against staging with BLOCKTANK_REGTEST_AUTH set

@ovitrif ovitrif self-assigned this Nov 11, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ❌ Failed 2026-11-11T00:51:30.720830Z
We couldn’t complete this review. Comment @codex review to try again.
f930735 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@ovitrif ovitrif changed the title fix: regtest url join and redaction fix: hide credentials in regtest errors Nov 11, 2026
Base automatically changed from feat/regtest-auth to master November 11, 2026 00:35
@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Retargeted to master: #201 merged.

@talosmachina talosmachina 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.

No findings. Builds the regtest URL with Url::join on a slash-normalised base and strips userinfo from the URL shown in regtest errors; README signatures gain auth. Reviewed f930735, full tier (api.rs is the HTTP path that carries basic auth).

Build skipped: talos-pr-run could not confirm the author's permission on this repo with the token it uses, and it fails closed, so this review is static.

What I checked, and 5 candidates I ruled out

Read in full: src/modules/blocktank/api.rs, src/modules/blocktank/db.rs (new, update_blocktank_url), rust-blocktank-client 0.0.16 client.rs (normalize_url, build_url)
Call sites traced: regtest_request from all five regtest_* methods; blocktank_url set in BlocktankDB::new and update_blocktank_url
CI: SwiftPM, manifests, paykit-route, wake green; Android/iOS bindgen and usdt pending at review time. No workflow runs modules::blocktank, so the new regtest_url_tests are not exercised by CI.

Ruled out

  • Join diverges from the client: regtest_url is the same append-slash, Url::parse, join sequence as BlocktankClient::normalize_url + build_url, so regtest and non-regtest routes resolve against the same base.
  • Base with a query and no trailing slash (https://host/api?x=1): the appended slash lands in the query and the join resolves to /regtest/..., dropping /api. The client resolves its own routes the same way and the old format! produced /api?x=1/regtest/..., also wrong, so this diff does not introduce it.
  • payment_id steering the join: the relative reference always starts with regtest/, so no id can make it scheme-relative or absolute; ?, # and .. in an id behave as they did when reqwest parsed the formatted string.
  • Other places the URL leaks: both reqwest errors go through without_url(), url::ParseError does not carry the input, and the 401 path returns a fixed string.
  • Auth from base-URL userinfo: reqwest still takes it from the URL as before; only the displayed copy is redacted.

Merge confidence: 4/5, no findings, but the new tests are not run by CI and I could not run them here.

@coreyphillips coreyphillips 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.

Two independent reviews, nothing blocking a merge.

worth doing, does not block

  • Base URL credentials override the auth argument on regtest calls (src/modules/blocktank/api.rs:238-241). If the Blocktank base URL contains credentials and the caller also passes auth, the regtest request goes out with two Authorization headers. A Node server keeps the first one, which comes from the URL, so auth is silently ignored. The cause: reqwest's RequestBuilder::new moves URL userinfo into a basic auth header (reqwest 0.12.28, async_impl/request.rs:176-179). Then basic_auth at api.rs:241 appends a second header instead of replacing the first. How I confirmed it: I built a scratch binary against this branch that calls update_blocktank_url("http://urluser:urlpass@127.0.0.1:PORT/api") and then regtest_mine(None, Some("paramuser:parampass")). A raw socket listener received: POST /api/regtest/chain/mine HTTP/1.1 authorization: Basic dXJsdXNlcjp1cmxwYXNz (urluser:urlpass) authorization: Basic cGFyYW11c2VyOnBhcmFtcGFzcw== (paramuser:parampass) Against a Node 24 http server, req.headers.authorization was the URL pair. This branch treats credentials in the base URL as a real configuration, since it redacts them. On master, URL credentials were the only way to authenticate these routes, so a setup that already uses them and then adopts auth will get 401s it can't explain. Two possible fixes: clear the userinfo on url before client.request when auth is set, or reject the combination.
  • URL credentials and explicit auth create duplicate Authorization headers (src/modules/blocktank/api.rs:238-241). Supplying auth alongside credentials in the base URL creates two Authorization headers. client.request() extracts URL credentials, then basic_auth() appends another header. I confirmed this by constructing a request with http://base:old-password@127.0.0.1/api and auth = "regtest:new-password". The old credentials remain first, so servers may ignore valid explicit credentials or reject the duplicate headers.

nits

  • New constants sit between use statements (src/modules/blocktank/api.rs:5-7). REGTEST_TIMEOUT_SECS and ERR_REGTEST_UNAUTHORIZED are declared between the use serde_json/std::time imports and the use rust_blocktank_client import. Moving them below the imports keeps the module header in the usual order.

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

@coreyphillips fixed in 25ff03f: with auth set, the base URL's credentials are dropped before the request is built, so it carries one Authorization header from auth (new test auth_replaces_base_url_credentials); without auth, URL credentials still apply as on master. The constants now sit below the imports. The ruleset needs an approval of the last push, so could you re-approve?

@coreyphillips coreyphillips 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.

Rechecked after 3 new commits (3443a0c, 69d16db, 25ff03f). Nothing blocking remains.

addressed

  • Base URL credentials override the auth argument on regtest calls (src/modules/blocktank/api.rs:238-241). Fixed: regtest_request_builder (src/modules/blocktank/api.rs:472) passes without_credentials(&url) (api.rs:458) to client.request whenever auth is non-empty. It clears userinfo the same way reqwest 0.12.28's extract_authority does, so reqwest adds no URL-derived header and basic_auth adds the only one. I ran regtest_url_tests (4 pass, including auth_replaces_base_url_credentials). I also built a scratch binary that calls update_blocktank_url("http://urluser:urlpass@127.0.0.1:PORT/api") and then regtest_mine(None, Some("paramuser:parampass")) against a raw socket. The socket received exactly one authorization: Basic cGFyYW11c2VyOnBhcmFtcGFzcw==. With auth set to None or an empty string, it received one header carrying the URL pair, as on master.
  • New constants sit between use statements (src/modules/blocktank/api.rs:5-7). Fixed: REGTEST_TIMEOUT_SECS and ERR_REGTEST_UNAUTHORIZED now sit at src/modules/blocktank/api.rs:9-11, after the last use line. cargo fmt --check passes on the file.
  • URL credentials and explicit auth create duplicate Authorization headers (src/modules/blocktank/api.rs:238-241). Fixed: This is the same defect as point 1, and the same change answers it. regtest_request_builder (api.rs:472) strips URL userinfo before building the request when auth is set. The wire check covered urluser:urlpass@ and the password-only :urlpass@ base URLs, and both sent a single Authorization header taken from auth.

@ovitrif

ovitrif commented Nov 11, 2026

Copy link
Copy Markdown
Collaborator Author

Merged: approved by @coreyphillips on 25ff03f, no open threads, required checks green (Bindgen jobs still running, not required).

@ovitrif
ovitrif merged commit f69c298 into master Nov 11, 2026
7 checks passed
@ovitrif
ovitrif deleted the fix/regtest-url branch November 11, 2026 01:26
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.

3 participants