mirror of
https://github.com/XRPLF/clio.git
synced 2026-10-09 05:18:58 +00:00
fix: Reject CTID network IDs above 16 bits (#3232)
Co-authored-by: Alex Kremer <akremer@ripple.com>
This commit is contained in:
committed by
GitHub
parent
04d5f79c72
commit
a9715bf269
@@ -236,7 +236,7 @@ toExpandedJson(
|
||||
data::TransactionAndMetadata const& blobs,
|
||||
std::uint32_t const apiVersion,
|
||||
NFTokenjson nftEnabled,
|
||||
std::optional<uint16_t> networkId
|
||||
std::optional<uint32_t> networkId
|
||||
)
|
||||
{
|
||||
auto [txn, meta] = deserializeTxPlusMeta(blobs, blobs.ledgerSequence);
|
||||
@@ -269,7 +269,7 @@ toExpandedJson(
|
||||
}
|
||||
|
||||
std::optional<std::string>
|
||||
encodeCTID(uint32_t ledgerSeq, uint16_t txnIndex, uint16_t networkId) noexcept
|
||||
encodeCTID(uint32_t ledgerSeq, uint16_t txnIndex, uint32_t networkId) noexcept
|
||||
{
|
||||
static constexpr uint32_t kMaxLedgerSeq = 0x0FFF'FFFF;
|
||||
static constexpr uint32_t kMaxTxnIndex = 0xFFFF;
|
||||
|
||||
@@ -144,7 +144,7 @@ toExpandedJson(
|
||||
data::TransactionAndMetadata const& blobs,
|
||||
std::uint32_t apiVersion,
|
||||
NFTokenjson nftEnabled = NFTokenjson::DISABLE,
|
||||
std::optional<uint16_t> networkId = std::nullopt
|
||||
std::optional<uint32_t> networkId = std::nullopt
|
||||
);
|
||||
|
||||
/**
|
||||
@@ -779,7 +779,7 @@ getNFTID(boost::json::object const& request);
|
||||
* @return The encoded CTID or std::nullopt if the input is invalid
|
||||
*/
|
||||
std::optional<std::string>
|
||||
encodeCTID(uint32_t ledgerSeq, uint16_t txnIndex, uint16_t networkId) noexcept;
|
||||
encodeCTID(uint32_t ledgerSeq, uint16_t txnIndex, uint32_t networkId) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Decode the CTID from a string or a uint64_t
|
||||
|
||||
@@ -344,6 +344,12 @@ TEST_F(RPCHelpersTest, EncodeCTID)
|
||||
EXPECT_FALSE(encodeCTID(0x1FFFFFFF, 0x67, 0x89));
|
||||
}
|
||||
|
||||
TEST_F(RPCHelpersTest, EncodeCTIDRejectsNetworkIdAbove16Bits)
|
||||
{
|
||||
uint32_t const networkId = 0x10000;
|
||||
EXPECT_FALSE(encodeCTID(0x1234, 0x67, networkId));
|
||||
}
|
||||
|
||||
TEST_F(RPCHelpersTest, DecodeCTIDString)
|
||||
{
|
||||
auto const ctid = decodeCTID("C000123400670089");
|
||||
|
||||
@@ -991,6 +991,38 @@ TEST_F(RPCTxTest, ReturnCTIDForTxInput)
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, OmitCTIDWhenNetworkIdExceeds16Bits)
|
||||
{
|
||||
TransactionAndMetadata tx;
|
||||
tx.metadata =
|
||||
createMetaDataForCreateOffer(kCurrency, kAccount, 100, 200, 300).getSerializer().peekData();
|
||||
tx.transaction =
|
||||
createCreateOfferTransactionObject(kAccount, 2, 100, kCurrency, kAccount2, 200, 300)
|
||||
.getSerializer()
|
||||
.peekData();
|
||||
tx.ledgerSequence = 100;
|
||||
|
||||
EXPECT_CALL(*backend_, fetchTransaction(xrpl::uint256{kTxnId}, _)).WillOnce(Return(tx));
|
||||
EXPECT_CALL(*backend_, fetchLedgerBySequence(tx.ledgerSequence, _))
|
||||
.WillOnce(Return(std::nullopt));
|
||||
|
||||
auto const rawETLPtr = dynamic_cast<MockETLService*>(mockETLServicePtr_.get());
|
||||
ASSERT_NE(rawETLPtr, nullptr);
|
||||
EXPECT_CALL(*rawETLPtr, getETLState).WillOnce(Return(etl::ETLState{.networkID = 0x10000}));
|
||||
|
||||
runSpawn([this](auto yield) {
|
||||
auto const handler = AnyHandler{TestTxHandler{backend_, mockETLServicePtr_}};
|
||||
auto const req = boost::json::parse(
|
||||
fmt::format(R"JSON({{"command": "tx", "transaction": "{}"}})JSON", kTxnId)
|
||||
);
|
||||
auto const output = handler.process(req, Context{.yield = yield, .apiVersion = 2u});
|
||||
ASSERT_TRUE(output);
|
||||
auto const& result = output.result->as_object();
|
||||
EXPECT_FALSE(result.contains("ctid"));
|
||||
EXPECT_FALSE(result.at("tx_json").as_object().contains("ctid"));
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(RPCTxTest, NotReturnCTIDIfETLNotAvailable)
|
||||
{
|
||||
static constexpr auto kOut = R"JSON({
|
||||
|
||||
Reference in New Issue
Block a user