fix(jsonrpc): enforce maxBlockRange on eth_getFilterLogs#15
Conversation
📝 WalkthroughWalkthroughThis PR introduces two related safeguards for JSON-RPC queries on forked or orphaned chains: (1) block range validation at query time in ChangesBlock range re-validation on
Orphaned block detection in receipts and block queries
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai review |
✅ Action performedReview finished.
|
7091ccd to
8b92075
Compare
What does this PR do?
Applies the
jsonRpcMaxBlockRangecap toeth_getFilterLogs, closing a gap wherethe block-range limit could be bypassed via the filter path.
eth_getLogsbuilds itsLogFilterWrapperwithcheckBlockRange=true, so the capis enforced. But
eth_newFilterbuilds the wrapper withcheckBlockRange=false, andeth_getFilterLogsreuses that stored wrapper without re-checking — so the cap wasnever applied when querying logs through a filter. A client could create a filter
with a wide range (e.g.
fromBlock=0x0,toBlockfar ahead) and calleth_getFilterLogsto trigger an unbounded historical scan (CPU/IO pressure,potential OOM).
Changes:
LogFilterWrapperconstructor into a reusablevalidateBlockRange(currentMaxBlockNum)method (logic and error message unchanged).eth_getFilterLogsnow callsvalidateBlockRangeagainst the current headbefore scanning, mirroring
eth_getLogs.JsonRpcInvalidParamsExceptionon thegetFilterLogsimpl (the interfaceand its
@JsonRpcError(code=-32602)mapping already declared it).Creation-time behavior is intentionally left unchanged:
eth_newFilterstill acceptswide ranges (no creation-time gate), matching geth's "creation accepts, query
enforces" model and preserving forward polling via
eth_getFilterChanges(which doesnot scan a range).
Why are these changes required?
Without this,
jsonRpcMaxBlockRangeonly protectseth_getLogs; theeth_newFiltereth_getFilterLogspath silently bypasses it, leaving a DoS vector on full nodeswith JSON-RPC enabled.
This PR has been tested by:
Follow up
Extra details