Skip to content

Commit

Permalink
deposit_authorized check that credential belongs to account
Browse files Browse the repository at this point in the history
  • Loading branch information
oleks-rip committed Nov 6, 2024
1 parent 756d000 commit ef82c3b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
46 changes: 42 additions & 4 deletions src/test/rpc/DepositAuthorized_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,11 @@ class DepositAuthorized_test : public beast::unit_test::suite

Account const alice{"alice"};
Account const becky{"becky"};
Account const diana{"diana"};
Account const carol{"carol"};

Env env(*this);
env.fund(XRP(1000), alice, becky, carol);
env.fund(XRP(1000), alice, becky, carol, diana);
env.close();

// carol recognize alice
Expand Down Expand Up @@ -514,14 +515,51 @@ class DepositAuthorized_test : public beast::unit_test::suite
}

{
// diana recognize becky
env(credentials::create(becky, diana, credType));
env.close();
env(credentials::accept(becky, diana, credType));
env.close();

// retrieve the index of the credentials
auto jv = credentials::ledgerEntry(env, becky, diana, credType);
std::string const credBecky =
jv[jss::result][jss::index].asString();

testcase("deposit_authorized account without preauth");
auto const jv = env.rpc(
jv = env.rpc(
"json",
"deposit_authorized",
depositAuthArgs(becky, alice, "validated", {credIdx})
depositAuthArgs(becky, alice, "validated", {credBecky})
.toStyledString());
checkCredentialsResponse(
jv[jss::result], becky, alice, true, {credIdx});
jv[jss::result], becky, alice, true, {credBecky});
}

{
// carol recognize diana
env(credentials::create(diana, carol, credType));
env.close();
env(credentials::accept(diana, carol, credType));
env.close();
// retrieve the index of the credentials
auto jv = credentials::ledgerEntry(env, alice, carol, credType);
std::string const credDiana =
jv[jss::result][jss::index].asString();

// alice try to use credential for different account
jv = env.rpc(
"json",
"deposit_authorized",
depositAuthArgs(becky, alice, "validated", {credDiana})
.toStyledString());
checkCredentialsResponse(
jv[jss::result],
becky,
alice,
false,
{credDiana},
"badCredentials");
}

{
Expand Down
9 changes: 9 additions & 0 deletions src/xrpld/rpc/handlers/DepositAuthorized.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ doDepositAuthorized(RPC::JsonContext& context)
return result;
}

if ((*sleCred)[sfSubject] != srcAcct)
{
RPC::inject_error(
rpcBAD_CREDENTIALS,
"credentials doesn't belong to the root account",
result);
return result;
}

auto [it, ins] = sorted.emplace(
(*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
if (!ins)
Expand Down

0 comments on commit ef82c3b

Please sign in to comment.