feat(gossip): Add RPC limits#350
Open
bismuth01 wants to merge 1 commit into
Open
Conversation
Added RPC limit options to Gossip protocol to control the amount of processing of each message type and message id. This helps prevent memory exhaustion attacks.
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.
The current gossip protocol implementation takes the whole RPC message and processes them. The lack of an upper bound on the amount of each type of message creates the possibility of memory exhaustion attacks as reported in #349 by @tonghuaroot.
What this PR adds: -
libp2p::protocol::gossip::RPCLimitswhich defines the possible RPC message parsing limits.libp2p::protocol::gossip::MessageParserto enforce usage of these limits. Logically, the parsing process counts the number of messages processed and once it reaches the defined limits, it ignores the rest.test/libp2p/protocol/gossip/gossip_rpc_limits_test.cppfor reproducable testing of the modified RPC message parsing logic.How I checked if everything works correctly: -
gossip_chat_examplewhose source code lies inexample/03-gossipcompiles without any modifications and works as expected showing that the current changes add a default limit to the RPC message parsing and does not hinder existing code either.The default value for the limits were copied from js-libp2p interface default values.
NOTE: This PR solves only half the problem of memory exhaustion attacks as defined in #349 and another layer of configuration must be added to gossip to limit in increase of size
libp2p::protocol::gossip::RemoteSubscriptionsand related classes & structs which handle information about remote peers.Thanks to @tonghuaroot for identifying and reporting the issue.