fix(protocol): don't terminate retrieval threads on messages with trailing bytes (DoS)#5105
Open
damip wants to merge 1 commit into
Open
fix(protocol): don't terminate retrieval threads on messages with trailing bytes (DoS)#5105damip wants to merge 1 commit into
damip wants to merge 1 commit into
Conversation
… bytes The block and operation retrieval workers each run one long-lived loop for all peers. On a deserialized message with trailing bytes they did 'println!(...); return;', terminating the shared thread, so one peer could DoS block/operation handling for everyone. Log a warning and continue the loop instead, keeping the worker alive. Findings F120, F128. Co-authored-by: Cursor <cursoragent@cursor.com>
Leo-Besancon
approved these changes
Jul 22, 2026
Leo-Besancon
left a comment
Member
There was a problem hiding this comment.
LGTM, indeed peer banning as follow-up seems like a good idea.
Is there an issue regarding this?
modship
approved these changes
Jul 22, 2026
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.
Summary
The block and operation retrieval workers each run a single long-lived
select!loopthat serves all peers. When a network message deserialized successfully but left
trailing bytes (
!rest.is_empty()), both loops did:A
returnhere kills the entire retrieval thread, so a single peer sending a validmessage prefix followed by junk bytes can permanently stop block/operation protocol
handling for every peer — a denial-of-service. The stray
println!also bypasses thelogging framework.
Change
In both
block_handler::retrievalandoperation_handler::retrieval, treat a messagewith trailing bytes as a per-message error: log a
warn!(including the offending peerand the number of trailing bytes) and
continuethe loop instead of returning. Theworker keeps serving other peers.
Testing
cargo build/cargo clippyclean formassa_protocol_worker.return→continue) inside the workers' largeselect!loops; a faithful regression test would require standing up the fullretrieval worker with network/pool/mock wiring, so no bespoke unit test is added.
The change is small and self-contained.
Risk
Low — well-behaved peers never send trailing bytes, so the only behavioural change is
that a malformed/hostile message no longer tears down the shared worker. We
intentionally keep the change minimal (log + skip) and do not add peer-banning here;
banning on trailing bytes can be considered as a follow-up.
Tracking: findings F120 and F128.