Skip to content

Limit control message size of RPCs - #707

Merged
MarcoPolo merged 6 commits into
masterfrom
marco/limit-control-message-size
Jul 4, 2026
Merged

MarcoPolo merged 6 commits into
masterfrom
marco/limit-control-message-size

Conversation

@MarcoPolo

Copy link
Copy Markdown
Contributor

This adds a new option to limit to total size of control fields (including subscriptions) when receiving a pb rpc. This fixes an issue where allowing a large message payload should not also allow a large amount of control messages at once.

This depends on #706

@MarcoPolo
MarcoPolo requested a review from sukunrt May 27, 2026 21:11
@MarcoPolo
MarcoPolo force-pushed the marco/limit-control-message-size branch from 202759d to b953720 Compare May 29, 2026 22:59
@MarcoPolo
MarcoPolo force-pushed the marco/migrate-to-google-pb branch from 62d9b32 to b33023e Compare May 30, 2026 00:09
@MarcoPolo
MarcoPolo force-pushed the marco/limit-control-message-size branch from b953720 to 5806415 Compare May 30, 2026 00:09
Comment thread pb/validator.go Resolved
Comment thread pubsub.go Resolved
Comment thread pubsub.go
Comment on lines +571 to +579
func controlRPCSize(rpc *RPC) int {
if rpc == nil {
return 0
}
return proto.Size(&pb.RPC{
Subscriptions: rpc.Subscriptions,
Control: rpc.Control,
})
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

maybe set publish and partial to nil here to check the length. This will help avoid allocation.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it'll also make it similar to the validation on the inbound side.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed so this func doesn't allocate

Base automatically changed from marco/migrate-to-google-pb to master June 30, 2026 10:04
@MarcoPolo
MarcoPolo force-pushed the marco/limit-control-message-size branch from 5806415 to 0d4b712 Compare July 3, 2026 19:31
@MarcoPolo
MarcoPolo merged commit 1688fbf into master Jul 4, 2026
7 checks passed
@MarcoPolo
MarcoPolo deleted the marco/limit-control-message-size branch July 4, 2026 21:15
lucassaldanha added a commit to libp2p/jvm-libp2p that referenced this pull request Aug 28, 2026
Add maxControlMessageSize to PubsubRpcLimits and accumulate the control-plane
wire size during the walk validateRpc already performs, rejecting the frame
before it reaches ProtobufDecoder if the total exceeds the limit.

Subscriptions and control are charged in full, as is every other top-level
field, known or unknown. Publish and RPC.partial are charged for their envelope
with only their opaque payload lengths exempt (Message.data, partialMessage,
partsMetadata), so large payloads stay cheap while envelope-heavy frames do not.

Unknown fields consume the budget rather than triggering rejection. go-libp2p
retains and re-emits unknown fields, so rejecting them would break interop on
the next schema addition anywhere in the ecosystem.

Follows the same approach as
libp2p/go-libp2p-pubsub#707 and
libp2p/rust-libp2p#6468, which both bound control size
ahead of decoding rather than counting per-field.

Co-authored-by: Enrico Del Fante <enrico.delfante@consensys.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants