Repository navigation
Limit nesting depth in (deprecated) JSON reader - #2188
Merged
Merged
Conversation
JSONReader parses arrays and objects with unbounded recursion, so a deeply nested payload (e.g. a JSON-RPC request with ~8000 nested arrays, 16 KB) throws a StackOverflowError. The error is not caught by JsonRpcServer nor RpcServer, so it terminates the RPC server main loop and leaves the request unacknowledged. JSONReader now rejects input nested more than 100 levels deep with an IllegalStateException, which JsonRpcServer maps to a 400 response. This also protects JsonRpcClient, which parses responses with JSONReader.
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the change introducing a 100-level JSON nesting limit.
No open issues 🎉
What changed in this PR
Adds a 100-level nesting limit to the deprecated JSON reader, protecting JSON-RPC request and response parsing from stack overflow caused by deeply nested input.
Changes:
- Rejects arrays and objects exceeding the shared nesting limit with
IllegalStateException - Adds tests for depth boundaries, mixed nesting, sibling structures, reader reuse after failure, and JSON-RPC error handling
| File | Description |
|---|---|
| src/test/java/com/rabbitmq/client/test/JSONReadWriteTest.java | Tests nesting limits and JSON-RPC rejection and recovery |
| src/main/java/com/rabbitmq/tools/json/JSONReader.java | Tracks nesting depth and rejects input beyond 100 levels |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
JSONReader parses arrays and objects with unbounded recursion, so a deeply nested payload (e.g. a JSON-RPC request with ~8000 nested arrays, 16 KB) throws a StackOverflowError. The error is not caught by JsonRpcServer nor RpcServer, so it terminates the RPC server main loop and leaves the request unacknowledged.
JSONReader now rejects input nested more than 100 levels deep with an IllegalStateException, which JsonRpcServer maps to a 400 response. This also protects JsonRpcClient, which parses responses with JSONReader.