Skip to content

Comments

rpc: add method name length limit and configurable message size limit#3063

Merged
alex-10072 merged 2 commits intodevelopfrom
ws-improvements
May 6, 2025
Merged

rpc: add method name length limit and configurable message size limit#3063
alex-10072 merged 2 commits intodevelopfrom
ws-improvements

Conversation

@MatusKysel
Copy link
Contributor

@MatusKysel MatusKysel commented Apr 30, 2025

This PR introduces two important improvements to the RPC system:

  1. Method Name Length Limit
  • Adds a limit of 256 characters for RPC method names to prevent potential abuse
  • Prevents large method names from leading to excessive response sizes
  • Limit is enforced in:
    • handleCall for regular RPC method calls
    • handleSubscribe for subscription method calls
  • Added tests in websocket_test.go to verify the length limit functionality
  1. Configurable WebSocket Message Size Limit
  • Adds support for configuring message size limits on both client and server sides
  • Previously, server side used a fixed default limit while client side supported configurable limits
  • Changes include:
    • Modified WebsocketHandler to accept a messageSizeLimit parameter
    • Added messageSizeLimit field to wsConfig struct
    • Updated server code to pass the message size limit through to WebSocket handler
    • Updated test cases to pass appropriate message size limits
    • Fixed linter errors in test files by providing proper int64 values

Both changes maintain backward compatibility:

  • Method name length limit only affects new calls with names exceeding 256 characters
  • Message size limit defaults to wsDefaultReadLimit when not specified

@MatusKysel MatusKysel changed the title rpc: add method name length limit rpc: add method name length limit and configurable message size limit Apr 30, 2025
@MatusKysel MatusKysel requested a review from Copilot April 30, 2025 12:31
@MatusKysel MatusKysel marked this pull request as ready for review April 30, 2025 12:31
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces two improvements to the RPC system: enforcing a 256-character limit on RPC method names and enabling configurable WebSocket message size limits.

  • Added validations in the RPC handler for both standard and subscription method calls to enforce the method name length limit.
  • Modified the WebSocket handler and related configuration to accept a messageSizeLimit parameter, with corresponding test updates.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rpc/websocket_test.go Updated WebsocketHandler invocations and added tests for method name length limit.
rpc/websocket.go Modified WebsocketHandler signature and logic to use a configurable messageSizeLimit.
rpc/json.go Defined maxMethodNameLength constant.
rpc/handler.go Added method name length validation in handleCall and handleSubscribe.
rpc/client_test.go Updated WebsocketHandler invocations to pass messageSizeLimit.
node/rpcstack.go Updated WebsocketHandler instantiation to accept messageSizeLimit from config.
node/node.go Forwarded WSMessageSizeLimit from node configuration.
node/config.go Added WSMessageSizeLimit configuration field.
node/api.go Propagated WSMessageSizeLimit in API setup.

@MatusKysel MatusKysel requested a review from zzzckck April 30, 2025 12:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces two improvements to the RPC system: enforcing a 256‑character limit on RPC method names and making the WebSocket message size limit configurable.

  • Adds checks in both regular calls and subscription requests for method name length limits.
  • Propagates a new configurable messageSizeLimit parameter throughout the server, client tests, and node configurations.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
rpc/websocket_test.go Updates tests to pass an explicit messageSizeLimit parameter and adds tests for method name length limits.
rpc/websocket.go Modifies the WebsocketHandler signature to accept and use messageSizeLimit.
rpc/json.go Introduces a constant for maxMethodNameLength.
rpc/handler.go Adds error responses for method/subscription name lengths exceeding the limit.
rpc/client_test.go Updates WebsocketHandler invocations to include a messageSizeLimit parameter.
node/* Passes the new messageSizeLimit from node configuration to the RPC stack.

@alex-10072
Copy link
Contributor

@alex-10072 alex-10072 merged commit 3ca5cbf into develop May 6, 2025
7 checks passed
@zzzckck zzzckck deleted the ws-improvements branch May 14, 2025 06:23
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.

3 participants