Skip to content

Commit 38ddf41

Browse files
PeterChen13579ckeshava
authored andcommitted
APIv2(account_info): handle invalid "signer_lists" value (XRPLF#4585)
When requesting `account_info` with an invalid `signer_lists` value, the API should return an "invalidParams" error. `signer_lists` should have a value of type boolean. If it is not a boolean, then it is invalid input. The response now indicates that. * This is an API breaking change, so the change is only reflected for requests containing `"api_version": 2` * Fix XRPLF#4539
1 parent 5089fe4 commit 38ddf41

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/ripple/rpc/handlers/AccountInfo.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ doAccountInfo(RPC::JsonContext& context)
125125
}
126126
result[jss::account_flags] = std::move(acctFlags);
127127

128+
// The document states that signer_lists is a bool, however
129+
// assigning any string value works. Do not allow this.
130+
// This check is for api Version 2 onwards only
131+
if (!params[jss::signer_lists].isBool() && context.apiVersion > 1)
132+
{
133+
RPC::inject_error(rpcINVALID_PARAMS, result);
134+
return result;
135+
}
136+
128137
// Return SignerList(s) if that is requested.
129138
if (params.isMember(jss::signer_lists) &&
130139
params[jss::signer_lists].asBool())

src/test/rpc/AccountInfo_test.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,10 @@ class AccountInfo_test : public beast::unit_test::suite
217217
"\"api_version\": 2, \"account\": \"" + alice.human() + "\", " +
218218
"\"signer_lists\": true }";
219219

220+
auto const withSignersAsString = std::string("{ ") +
221+
"\"api_version\": 2, \"account\": \"" + alice.human() + "\", " +
222+
"\"signer_lists\": asdfggh }";
223+
220224
// Alice has no SignerList yet.
221225
{
222226
// account_info without the "signer_lists" argument.
@@ -263,6 +267,13 @@ class AccountInfo_test : public beast::unit_test::suite
263267
auto const& entry0 = signerEntries[0u][sfSignerEntry.jsonName];
264268
BEAST_EXPECT(entry0[sfSignerWeight.jsonName] == 3);
265269
}
270+
{
271+
// account_info with "signer_lists" as not bool should error out
272+
auto const info =
273+
env.rpc("json", "account_info", withSignersAsString);
274+
BEAST_EXPECT(info[jss::status] == "error");
275+
BEAST_EXPECT(info[jss::error] == "invalidParams");
276+
}
266277

267278
// Give alice a big signer list
268279
Account const demon{"demon"};

0 commit comments

Comments
 (0)