Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Penalize peers that send an invalid rpc request #6986

Open
wants to merge 5 commits into
base: unstable
Choose a base branch
from

Conversation

ackintosh
Copy link
Member

@ackintosh ackintosh commented Feb 11, 2025

Issue Addressed

Since #6847, invalid BlocksByRange/BlobsByRange requests, which do not comply with the spec, are handled in the Handler. Any peer that sends an invalid request is penalized and disconnected.

However, other kinds of invalid rpc request, which result in decoding errors, are just dropped. No penalty is applied and the connection with the peer remains.

Proposed Changes

I have added handling for the ListenUpgradeError event to notify the application of an RPCError:InvalidData error and disconnect to the peer that sent the invalid rpc request.

I also added tests for handling invalid rpc requests.

@ackintosh ackintosh added the work-in-progress PR is a work-in-progress label Feb 11, 2025
Comment on lines 840 to 853
ConnectionEvent::ListenUpgradeError(e) => {
if matches!(e.error, RPCError::InvalidData(_)) {
// Peer is not complying with the protocol. Notify the application and disconnect.
let inbound_substream_id = self.current_inbound_substream_id;
self.current_inbound_substream_id.0 += 1;

self.events_out.push(HandlerEvent::Err(HandlerErr::Inbound {
id: inbound_substream_id,
proto: Protocol::DataColumnsByRange, // FIXME: replace this hardcoded protocol
error: e.error,
}));
self.shutdown(None);
}
}
Copy link
Member Author

@ackintosh ackintosh Feb 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// FIXME: replace this hardcoded protocol

@jxs

The RPCError::InvalidData error is emitted by the inbound codec here. The problem I'm facing is that the handler cannot determine which protocol the invalid data belongs to. I think changing the type of InboundUpgrade::Error from RPCError to (Protocol, RPCError) might solves this. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in 2ff8cf2

@ackintosh ackintosh changed the title Penalize peers that send an invalid DataColumnsByRange request Penalize peers that send an invalid request Feb 12, 2025
@ackintosh ackintosh changed the title Penalize peers that send an invalid request Penalize peers that send an invalid rpc request Feb 12, 2025
@ackintosh ackintosh marked this pull request as ready for review February 13, 2025 23:02
@ackintosh ackintosh requested a review from jxs as a code owner February 13, 2025 23:02
@ackintosh ackintosh added ready-for-review The code is ready for review and removed work-in-progress PR is a work-in-progress labels Feb 13, 2025
ackintosh added a commit to ackintosh/lighthouse that referenced this pull request Feb 14, 2025
because that such invalid requests are handled in the Handler since the following PRs:

sigp#6847
sigp#6986
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Networking ready-for-review The code is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant