Skip to content

Commit 1ca66d8

Browse files
authored
fix: Limit max bundle size (#2355)
## Why is this change needed? `submitBulkMessages` and `submitMessageBundle` were not validating size of the bundle and allowing unbounded input. ## Merge Checklist _Choose all relevant options below by adding an `x` now or at any time before submitting for review_ - [x] PR title adheres to the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard - [x] PR has a [changeset](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#35-adding-changesets) - [x] PR has been tagged with a change label(s) (i.e. documentation, feature, bugfix, or chore) - [ ] PR includes [documentation](https://github.com/farcasterxyz/hub-monorepo/blob/main/CONTRIBUTING.md#32-writing-docs) if necessary. <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on limiting the size of message bundles in the application to enhance performance and prevent overload. ### Detailed summary - Added a new export `MAX_BUNDLE_SIZE` in `apps/hubble/src/network/p2p/bundleCreator.ts`. - Implemented a check in `apps/hubble/src/hubble.ts` to reject message bundles exceeding `MAX_BUNDLE_SIZE`. - Added a similar check in `apps/hubble/src/rpc/server.ts` for gRPC message submissions. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent 23758b5 commit 1ca66d8

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

.changeset/real-hounds-divide.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@farcaster/hubble": patch
3+
---
4+
5+
fix: Limit message bundle size

apps/hubble/src/hubble.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ import { diagnosticReporter } from "./utils/diagnosticReport.js";
9898
import { startupCheck, StartupCheckStatus } from "./utils/startupCheck.js";
9999
import { AddressInfo } from "node:net";
100100
import { MeasureSyncHealthJobScheduler } from "./network/sync/syncHealthJob.js";
101+
import { MAX_BUNDLE_SIZE } from "./network/p2p/bundleCreator.js";
101102

102103
export type HubSubmitSource =
103104
| "gossip"
@@ -1867,6 +1868,16 @@ export class Hub implements HubInterface {
18671868
);
18681869
}
18691870

1871+
if (messageBundle.messages.length > MAX_BUNDLE_SIZE) {
1872+
log.warn(
1873+
{ bundleSize: messageBundle.messages.length, maxBundleSize: MAX_BUNDLE_SIZE },
1874+
"submitMessageBundle rejected: Message bundle is too large",
1875+
);
1876+
return messageBundle.messages.map(() =>
1877+
err(new HubError("bad_request.invalid_param", "Message bundle is too large")),
1878+
);
1879+
}
1880+
18701881
const start = Date.now();
18711882
const allResults: Map<number, HubResult<number>> = new Map();
18721883

apps/hubble/src/network/p2p/bundleCreator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Message, MessageBundle } from "@farcaster/hub-nodejs";
22
import { GossipPublishResult, LibP2PNode } from "./gossipNodeWorker.js";
33
import { blake3Truncate160 } from "../../utils/crypto.js";
44

5-
const MAX_BUNDLE_SIZE = 256;
5+
export const MAX_BUNDLE_SIZE = 256;
66
const DEFAULT_BUNDLE_TIME_MS = 1000;
77

88
export class BundleCreator {

apps/hubble/src/rpc/server.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import axios from "axios";
8686
import { fidFromEvent } from "../storage/stores/storeEventHandler.js";
8787
import { rustErrorToHubError } from "../rustfunctions.js";
8888
import { handleUnaryCall, sendUnaryData, ServerDuplexStream, ServerUnaryCall } from "@grpc/grpc-js";
89+
import { MAX_BUNDLE_SIZE } from "../network/p2p/bundleCreator.js";
8990

9091
const HUBEVENTS_READER_TIMEOUT = 1 * 60 * 60 * 1000; // 1 hour
9192
const STREAM_METHODS_TIMEOUT = 8 * 1000; // 2 seconds
@@ -960,6 +961,16 @@ export default class Server {
960961
return;
961962
}
962963

964+
if (call.request.messages.length > MAX_BUNDLE_SIZE) {
965+
logger.warn({ total: call.request.messages.length }, "gRPC submitBulkMessages received too many messages");
966+
callback(
967+
toServiceError(
968+
new HubError("bad_request.validation_failure", `Too many messages. Max is ${MAX_BUNDLE_SIZE}`),
969+
),
970+
);
971+
return;
972+
}
973+
963974
const submissionTime = getFarcasterTime();
964975
if (submissionTime.isErr()) {
965976
callback(toServiceError(submissionTime.error));

0 commit comments

Comments
 (0)