Repository navigation
Conversation
…wing the stack nlohmann::json 3.1.2 parses recursively with no depth limit, so a single unauthenticated HTTP request like [[[[...]]]] crashed wallet-api. ApiBase now pre-scans the request (O(n), no allocations) and rejects nesting deeper than 128 levels with InvalidJsonRpc before json::parse. fromError, which re-parses the request to recover its id, is guarded the same way.
Author
|
See also #2146, an alternative fix for #2144 that applies the same pre-scan (also limited to 128) to every place that parses JSON from outside, not only
The TCP mode of |
Author
|
Note: this also fixes the default TCP mode, which turned out to be exposed as well (one 64 KB line of |
This was referenced Oct 6, 2026
Author
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.
Fixes #2144.
The vendored nlohmann::json (3.1.2) parses recursively with no depth limit. A single unauthenticated HTTP request such as
[[[[...]]]](80 000 levels, about 160 KB) overflowed the stack and killedwallet-api.Fix
ApiBasepre-scans the request beforejson::parse: one pass, no allocations. It tracks string and escape state so brackets inside strings don't count.InvalidJsonRpc("JSON nesting is too deep."). Real API requests nest only a few levels. 128 matches serde_json's default.fromErrorre-parses the request to recover itsid(apps API path), so it is guarded the same way.ApiBase, so it covers every transport: HTTP, TCP, websockets, apps API and wasm.Tests
wallet_api_test: a 1 000 000-level array is rejected (segfaulted before the fix). Depth 129 is rejected and depth 128 still parses. Brackets inside strings and after escaped quotes are not counted.wallet-api --use_http=1with the repro from the issue. The unfixed binary dies at depth 80 000. The fixed binary returns-32600 JSON nesting is too deep.for depths 80 000 and 400 000, and keeps servingwallet_statusafterwards.