Skip to content

Commit 09e0f10

Browse files
authored
fix: check for valid public key in attestations (#4798)
1 parent 056255e commit 09e0f10

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

src/ripple/app/tx/impl/XChainBridge.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,9 @@ attestationPreflight(PreflightContext const& ctx)
12111211
if (ctx.tx.getFlags() & tfUniversalMask)
12121212
return temINVALID_FLAG;
12131213

1214+
if (!publicKeyType(ctx.tx[sfPublicKey]))
1215+
return temMALFORMED;
1216+
12141217
auto const att = toClaim<TAttestation>(ctx.tx);
12151218
if (!att)
12161219
return temMALFORMED;

src/test/app/XChain_test.cpp

+68
Original file line numberDiff line numberDiff line change
@@ -4209,6 +4209,73 @@ struct XChain_test : public beast::unit_test::suite,
42094209
}
42104210
}
42114211

4212+
void
4213+
testBadPublicKey()
4214+
{
4215+
using namespace jtx;
4216+
4217+
testcase("Bad attestations");
4218+
{
4219+
// Create a bridge and add an attestation with a bad public key
4220+
XEnv scEnv(*this, true);
4221+
std::uint32_t const claimID = 1;
4222+
std::optional<Account> dst{scBob};
4223+
auto const amt = XRP(1000);
4224+
scEnv.tx(create_bridge(Account::master, jvb))
4225+
.tx(jtx::signers(Account::master, quorum, signers))
4226+
.close();
4227+
scEnv.tx(xchain_create_claim_id(scAlice, jvb, reward, mcAlice))
4228+
.close();
4229+
auto jvAtt = claim_attestation(
4230+
scAttester,
4231+
jvb,
4232+
mcAlice,
4233+
amt,
4234+
payees[UT_XCHAIN_DEFAULT_QUORUM],
4235+
true,
4236+
claimID,
4237+
dst,
4238+
signers[UT_XCHAIN_DEFAULT_QUORUM]);
4239+
{
4240+
// Change to an invalid keytype
4241+
auto k = jvAtt["PublicKey"].asString();
4242+
k.at(1) = '9';
4243+
jvAtt["PublicKey"] = k;
4244+
}
4245+
scEnv.tx(jvAtt, ter(temMALFORMED)).close();
4246+
}
4247+
{
4248+
// Create a bridge and add an create account attestation with a bad
4249+
// public key
4250+
XEnv scEnv(*this, true);
4251+
std::uint32_t const createCount = 1;
4252+
Account dst{scBob};
4253+
auto const amt = XRP(1000);
4254+
auto const rewardAmt = XRP(1);
4255+
scEnv.tx(create_bridge(Account::master, jvb))
4256+
.tx(jtx::signers(Account::master, quorum, signers))
4257+
.close();
4258+
auto jvAtt = create_account_attestation(
4259+
scAttester,
4260+
jvb,
4261+
mcAlice,
4262+
amt,
4263+
rewardAmt,
4264+
payees[UT_XCHAIN_DEFAULT_QUORUM],
4265+
true,
4266+
createCount,
4267+
dst,
4268+
signers[UT_XCHAIN_DEFAULT_QUORUM]);
4269+
{
4270+
// Change to an invalid keytype
4271+
auto k = jvAtt["PublicKey"].asString();
4272+
k.at(1) = '9';
4273+
jvAtt["PublicKey"] = k;
4274+
}
4275+
scEnv.tx(jvAtt, ter(temMALFORMED)).close();
4276+
}
4277+
}
4278+
42124279
void
42134280
run() override
42144281
{
@@ -4226,6 +4293,7 @@ struct XChain_test : public beast::unit_test::suite,
42264293
testXChainCreateAccount();
42274294
testFeeDipsIntoReserve();
42284295
testXChainDeleteDoor();
4296+
testBadPublicKey();
42294297
}
42304298
};
42314299

0 commit comments

Comments
 (0)