rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
313 stars 231 forks source link

HTTP client doesn't automatically include the Host header #357

Open mprakhov17 opened 1 month ago

mprakhov17 commented 1 month ago

I'm using test_against_node.rs example When I set up my URL (as an example http://bitcoin.test.node), DNS name during request converted to 11.11.11.11 and I', getting 400 response due to Host header is not added (Cloudflare 1003 error)

Is it possible to automatically include the Host header or do it manually?

apoelstra commented 1 month ago

Which version of rust-bitcoincore-rpc are you using?

This header was added to rust-jsonrpc in http://github.com/apoelstra/rust-jsonrpc/pull/85 which appeared in jsonrpc 0.14.1 used by this library.

Or is this a new issue introduced by our switch to minreq (but which has not been released yet)?

mprakhov17 commented 1 month ago

@apoelstra The issue is observed on bitcoincore-rpc = "0.14.0" Today I clone bitcoincore-rpc repo (version = "0.19.0") - the same problem Are there any ad-hoc solutions? It is blocking our development now 😢

apoelstra commented 1 month ago

0.17 or 0.18 will definitely work because they have a fix for this particular issue.

0.19 possibly reintroduced it when we switched the underlying HTTP transport to minreq.

mprakhov17 commented 1 month ago

it seems the problem is that rust-jsonrpc convert domain name to IP address and as a result we got request like: curl -X POST --user user:pass \ http://11.11.11.11 \ -H 'Content-Type: application/json' -H 'Host: 11.11.11.11' \ -d '{"method":"getblockchaininfo","params":[],"id":1,"jsonrpc":"2.0"}'

Which will be blocked by cloudflare with a 1003 error because host contains IP too instead domain name

apoelstra commented 1 month ago

Is this on 0.19 or pre-0.19? The rust-jsonrpc simple_http backend uses whatever hostname you provide when constructing the client, and will not do any DNS lookups. The minreq backend is not really in our control. Possibly this is a bug for them. Or possibly a bug for cloudflare.

mprakhov17 commented 1 month ago

0.17, 0.18, 0.19 I think it is jsonrpc bug... will create a ticket there