fix(cosmossdk): reject malformed tx history cursor at request boundary#1279
Conversation
📝 WalkthroughWalkthrough
ChangesCursor State Validation
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
A caller-controlled cursor with a null state value (e.g. {"state":{"x":null}})
decodes to a nil *CursorState entry. That entry is later dereferenced in a
filterByCursor errgroup worker goroutine, where the panic is not recovered by
net/http (it only recovers the handler goroutine) and crashes the process.
Validate the decoded cursor in ValidatePagingParams and return 400 Bad Request
before any source state is built or worker goroutine is spawned, so a malformed
cursor can never reach the crash path.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
8f0945c to
85a36fc
Compare
Description
A caller-supplied
cursoris unmarshalled into the server-initialized pagination state.json.Unmarshalstores a JSONnullstate value as a nil*CursorState.filterByCursorlater iteratesCursor.Stateand dereferences each entry — and that dereference runs in anerrgroupworker goroutine, so the resulting panic is not recovered bynet/http(it only recovers the request handler goroutine). One crafted, unauthenticated request therefore crashes the whole process instead of failing a single request.This validates the cursor at the request boundary so a malformed value can never reach the crash path:
ValidatePagingParamsdecodes the cursor and rejects any nil state entry, returning 400 Bad Request before any source state is built or worker goroutine is spawned.Cursor.Decodestays a pure decode;filterByCursor/history.goare left untouched.Verification
Didn't run
go build/tests locally per the repo CLAUDE.md (CI handles build validation). Well-formed cursors are unaffected; only structurally-invalid cursors (bad base64/JSON or a null state entry) now get a 400 instead of reaching pagination.