Repository navigation
Conversation
TryReadRequest() only checked m_req_busy, so after the reply to a "Connection: close" request had been queued it still parsed what was left in the receive buffer and handed it to a worker. The pipelined request was executed, and its reply was dropped once the closing reply had been flushed and the client disconnected. A client that resends it, as RFC 9112 section 9.6 allows, executes it twice. The libevent based server freed the connection right after writing the close reply, so this is a regression from the HTTP server rewrite. Record that a closing reply has been queued and stop reading requests from such a client, as well as from one flagged for disconnection. Adjust the state machine unit test, which relied on reading a request behind an HTTP/1.0 reply, and add unit and functional tests.
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code Coverage & BenchmarksFor details see: https://corecheck.dev/bitcoin/bitcoin/pulls/36355. ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
|
The CI failure in "Windows, test cross-built" looks unrelated to this PR: https://github.com/bitcoin/bitcoin/actions/runs/36297704387/job/108561658571 The only failing test is This PR only touches the HTTP server and its tests, and all other jobs passed. I could not reproduce the failure locally (12 runs of My guess at the cause, not verified: the test sends with a fee rate exactly equal to |
|
concept ACK, have not reviewed the code but this behavior has been reported by red team as well. Seems reasonable to fix but not a high priority. I don't think there is a security issue here, if anything the current server might just be more accommodating / flexible to misbehaving clients. |
|
Closing this for now. We only need to implement a subset of the HTTP protocol for our purposes and unless a server behavior is a security vulnerability or seriously disrupts a legitimate user workflow, we are going to kindly pass on the submission. |
After the reply to a
Connection: closerequest has been queued,TryReadRequest()still parses whatever is left in the receive buffer and hands it to a worker (it only checksm_req_busy), so a request pipelined behind theConnection: closerequest is executed. Once the reply has been flushed,MaybeSendBytesFromBuffer()flags the client for disconnection and the client is removed at the end of the I/O loop iteration, so the reply to the pipelined request is dropped (m_client.lock()fails inWriteReply()). If the closing reply is not flushed right away (large reply, slow client), the pipelined request is even answered and, since the last reply decidesm_keep_alive, a keep-alive request pipelined behind the close request keeps the connection open.RFC 9112 section 9.6 requires a server that sends a close response not to process any further requests on that connection. A client that relies on this and resends the request executes it twice, which matters for RPCs with side effects. The libevent based server freed the connection right after writing the close reply (
evhttp_send_done()→evhttp_connection_free()), discarding any pipelined bytes, so this is a regression from #35182. It requires an authenticated client that pipelines behind aConnection: closerequest, so it is a robustness issue rather than a security one.The fix records in the client that a closing reply has been queued (
m_closing, set inSend()when the reply is not keep-alive) and makesTryReadRequest()stop reading from such a client, as well as from a client already flagged for disconnection (m_disconnect, which also covers permanent send and receive errors). The state machine unit test relied on reading a request pipelined behind an HTTP/1.0 reply without keep-alive; that request is now keep-alive, and two cases are added: a closing reply that is flushed by the optimistic send, and one that stays queued because the socket does not accept data.The functional test pipelines a
setnetworkactive falserequest behind a blockingwaitforblockheightrequest that carriesConnection: close, generates a block, and checks that the server closed the connection right after the first reply, that only one request from that connection was handed to a worker (the I/O thread logs every request it hands over, with the client's address and port, before it closes the connection), and that the network is still active.