Skip to content

Limit nesting depth in (deprecated) JSON reader - #2188

Merged
acogoluegnes merged 1 commit into
v5.xfrom
json-reader-fix
Nov 17, 2026
Merged

acogoluegnes merged 1 commit into
v5.xfrom
json-reader-fix

Conversation

@acogoluegnes

Copy link
Copy Markdown
Contributor

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.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

@acogoluegnes
acogoluegnes marked this pull request as ready for review November 17, 2026 08:45
@acogoluegnes
acogoluegnes merged commit b4fb470 into v5.x Nov 17, 2026
5 checks passed
@acogoluegnes
acogoluegnes deleted the json-reader-fix branch November 17, 2026 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants