Skip to content

Commit

Permalink
APIv2(account_info): handle invalid "signer_lists" value (XRPLF#4585)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
PeterChen13579 authored and ckeshava committed Jul 10, 2023
1 parent 25c03c6 commit be217d9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/ripple/rpc/handlers/AccountInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ doAccountInfo(RPC::JsonContext& context)
}
result[jss::account_flags] = std::move(acctFlags);

// The document states that signer_lists is a bool, however
// assigning any string value works. Do not allow this.
// This check is for api Version 2 onwards only
if (!params[jss::signer_lists].isBool() && context.apiVersion > 1)
{
RPC::inject_error(rpcINVALID_PARAMS, result);
return result;
}

// Return SignerList(s) if that is requested.
if (params.isMember(jss::signer_lists) &&
params[jss::signer_lists].asBool())
Expand Down
11 changes: 11 additions & 0 deletions src/test/rpc/AccountInfo_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,10 @@ class AccountInfo_test : public beast::unit_test::suite
"\"api_version\": 2, \"account\": \"" + alice.human() + "\", " +
"\"signer_lists\": true }";

auto const withSignersAsString = std::string("{ ") +
"\"api_version\": 2, \"account\": \"" + alice.human() + "\", " +
"\"signer_lists\": asdfggh }";

// Alice has no SignerList yet.
{
// account_info without the "signer_lists" argument.
Expand Down Expand Up @@ -263,6 +267,13 @@ class AccountInfo_test : public beast::unit_test::suite
auto const& entry0 = signerEntries[0u][sfSignerEntry.jsonName];
BEAST_EXPECT(entry0[sfSignerWeight.jsonName] == 3);
}
{
// account_info with "signer_lists" as not bool should error out
auto const info =
env.rpc("json", "account_info", withSignersAsString);
BEAST_EXPECT(info[jss::status] == "error");
BEAST_EXPECT(info[jss::error] == "invalidParams");
}

// Give alice a big signer list
Account const demon{"demon"};
Expand Down

0 comments on commit be217d9

Please sign in to comment.