internal/jsonrpc2: reject fractional and out-of-range request IDs - #1178
Open
ez-lbz wants to merge 1 commit into
Open
internal/jsonrpc2: reject fractional and out-of-range request IDs#1178ez-lbz wants to merge 1 commit into
ez-lbz wants to merge 1 commit into
Conversation
MakeID currently truncates any float64 request ID with int64(), so a request with id 1.9 is answered with id 1. JSON-RPC 2.0 specifies that request IDs must be integers, strings, or null; silently rewriting a non-integer ID breaks response correlation for the client and can cause responses for distinct requests to be mixed up. Validate that float64 IDs are whole numbers within the int64 range and return a parse error otherwise, matching the behavior of the other official SDKs.
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.
Summary
MakeIDcurrently truncates anyfloat64request ID withint64(), so a request carrying{"id": 1.9, ...}is answered with{"id": 1, ...}. JSON-RPC 2.0 specifies that request IDs must be integers, strings, or null; silently rewriting a non-integer ID breaks response correlation for clients that match responses by ID, and can cause responses for distinct requests to be mixed up.This change validates that
float64IDs are whole numbers within theint64range before converting, and returns a parse error otherwise.Behavior
1.912.529.3e18424242Tests
TestMakeIDRejectsNonInteger,TestMakeIDAcceptsInteger, andTestDecodeMessageRejectsFractionalIDininternal/jsonrpc2/wire_test.go.