HomePhabricator

RPC: Reject RPC requests with same named parameter specified multiple times

Description

RPC: Reject RPC requests with same named parameter specified multiple times

Summary:

Make the JSON-RPC server reject requests with the same named parameter specified multiple times, instead of silently overwriting earlier parameter values with later ones.

Generally JSON keys are supposed to unique, and their order isn't supposed to be significant, so having the server silently discard duplicate keys is error-prone. Most likely if an RPC client is sending a request with duplicate keys it means something is wrong with the request and there should be an error.

After this change, named parameters are still allowed to specified multiple times on the bitcoin-cli command line, since bitcoin-cli automatically replaces earlier values with later values before sending the JSON-RPC request. This makes sense, since it's not unusual for the order of command line options to be significant or for later command line options to override earlier ones.

Backport of core#26628.

Test Plan:

ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D16242

Details

Provenance
Ryan Ofsky <ryan@ofsky.org>Authored on Dec 2 2022, 22:37
FabienCommitted on May 29 2024, 16:35
FabienPushed on May 29 2024, 16:35
Reviewer
Restricted Project
Differential Revision
D16242: RPC: Reject RPC requests with same named parameter specified multiple times
Parents
rABC9c150a6a4832: rpc: Allow named and positional arguments to be used together
Branches
Unknown
Tags
Unknown