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

feat(relay): check message data doesn't exceed a configurable limit #195

Merged
merged 7 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -5,6 +5,7 @@ MUD is an engine for autonomous worlds.
To get started, have a look at the [documentation](https://mud.dev) and [reference implementation](https://github.com/latticexyz/mudbasics) of a simple MUD project.

## Local dev setup

- Clone MUD: `git clone https://github.com/latticexyz/mud`
- Install go (to build packages/services): `https://go.dev/doc/install`
- Install jq (for various yarn commands): `https://stedolan.github.io/jq/download/`
Expand Down
4 changes: 4 additions & 0 deletions packages/services/cmd/ecs-relay/main.go
Expand Up @@ -16,8 +16,10 @@ var (
idleDisconnectInterval = flag.Int("idle-disconnect-interval", 60, "Time in seconds for how often to disconnect idle clients. Defaults to 60s")
messageDriftTime = flag.Int("message-drift-time", 5, "Time in seconds that is acceptable as drift before message is not relayed. Defaults to 5s")
minAccountBalance = flag.Uint64("min-account-balance", 1000000000000000, "Minimum balance in wei for an account to get its messages relayed. Defaults to 0.001 ETH")
maxDataSize = flag.Int("max-data-size", 1024, "Size limit for message data. Defaults to 1024 bytes")
verifyMessageSignature = flag.Bool("verify-msg-sig", false, "Whether to service-side verify the signature on each relayed message. Defaults to false.")
verifyAccountBalance = flag.Bool("verify-account-balance", false, "Whether to service-side verify that the account has sufficient balance when relaying message. Defaults to false.")
verifyDataSize = flag.Bool("verify-data-size", false, "Whether to service-side verify that size of the data of messages doesn't surpass max-data-size. Defaults to false.")
messageRateLimit = flag.Int("msg-rate-limit", 10, "Rate limit for messages per second that a single client can push to be relayed. Defaults to 10")
metricsPort = flag.Int("metrics-port", 6060, "Prometheus metrics http handler port. Defaults to port 6060")
)
Expand All @@ -37,8 +39,10 @@ func main() {
IdleDisconnectInterval: *idleDisconnectInterval,
MessageDriftTime: *messageDriftTime,
MinAccountBalance: *minAccountBalance,
MaxDataSize: *maxDataSize,
VerifyMessageSignature: *verifyMessageSignature,
VerifyAccountBalance: *verifyAccountBalance,
VerifyDataSize: *verifyDataSize,
MessageRateLimit: *messageRateLimit,
}

Expand Down
7 changes: 7 additions & 0 deletions packages/services/pkg/grpc/relay.go
Expand Up @@ -266,6 +266,13 @@ func (server *ecsRelayServer) VerifyMessage(message *pb.Message, identity *pb.Id
return fmt.Errorf("signature is not defined")
}

// Verify that the message data size is OK to relay if config flag is on.
if server.config.VerifyDataSize {
if len(message.Data) > server.config.MaxDataSize {
return fmt.Errorf("data exceeds size limit")
}
}

// Verify that the message is OK to relay if config flag is on.
if server.config.VerifyMessageSignature {
// Recover the signer to verify that it is the same identity as the one making the RPC call.
Expand Down
2 changes: 2 additions & 0 deletions packages/services/pkg/relay/core.go
Expand Up @@ -17,9 +17,11 @@ type RelayServerConfig struct {
IdleDisconnectInterval int
MessageDriftTime int
MinAccountBalance uint64
MaxDataSize int

VerifyMessageSignature bool
VerifyAccountBalance bool
VerifyDataSize bool
MessageRateLimit int
}

Expand Down