rpc: reject trailing bytes in sendrawtransaction#2556
Closed
Lrifton92 wants to merge 1 commit into
Closed
Conversation
handleSendRawTransaction deserialized the supplied hex into a MsgTx but
never verified that the entire input was consumed. wire.MsgTx's
Deserialize reads exactly the bytes that make up a transaction from the
reader and stops, so any extra bytes appended after a fully-formed
transaction were silently discarded and the transaction was still
accepted and relayed.
This diverges from bitcoind, which rejects such input with a
deserialization error ("TX decode failed") rather than broadcasting a
transaction parsed from a malformed payload.
Read the serialized transaction through a *bytes.Reader and, after a
successful Deserialize, check that no unread bytes remain. If any are
left over the input is not a valid serialized transaction and an
ErrRPCDeserialization error is returned, matching Core's behavior. This
mirrors the same hardening applied to decoderawtransaction in btcsuite#2550 and
to the PSBT global unsigned tx in btcsuite#2541.
A regression test exercises the trailing-bytes case by appending a
spurious byte to an otherwise valid transaction and asserting the
handler now returns ErrRPCDeserialization.
Signed-off-by: Lrifton92 <[email protected]>
7 tasks
Contributor
|
Replacing this PR with #2558 |
Member
|
Folded into #2558 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
handleSendRawTransactiondeserializes the supplied hex into awire.MsgTxbut never verifies that the entire input was consumed:MsgTx.Deserializereads exactly the bytes that make up a transaction and stops, so any extra bytes appended after a fully-formed transaction are silently discarded — and the transaction is still accepted and relayed.This diverges from
bitcoind, whosesendrawtransactionrejects such input with a deserialization error (TX decode failed) instead of broadcasting a transaction parsed from a malformed payload.Fix
Read the serialized transaction through a
*bytes.Readerand, after a successfulDeserialize, check that no unread bytes remain. If any are left over, returnErrRPCDeserialization, matching Core's behavior.This mirrors the same trailing-bytes hardening applied to
decoderawtransactionin #2550 and to the PSBT global unsigned tx in #2541 — completing the set across the RPC tx-decode paths.Test
TestHandleSendRawTransactionTrailingBytesappends a spurious byte to an otherwise valid transaction and asserts the handler now returnsErrRPCDeserialization. Verified red before the fix (the handler proceeded past deserialization) and green after.go build ./...,go vet .,gofmt -land the RPC handler tests all pass.