fix: Check network ID in transactionSignFor (#7102)

This commit is contained in:
Sergey Kuznetsov
2026-05-13 17:03:57 +01:00
committed by GitHub
parent 648ec747f2
commit 977e5a7dba
2 changed files with 49 additions and 8 deletions

View File

@@ -148,17 +148,23 @@ public:
}
[[nodiscard]] constexpr E const&
error() const
error() const&
{
return Base::error();
}
constexpr E&
error()
[[nodiscard]] constexpr E&
error() &
{
return Base::error();
}
[[nodiscard]] constexpr E&&
error() &&
{
return std::move(Base::error());
}
constexpr explicit
operator bool() const
{
@@ -215,17 +221,23 @@ public:
}
[[nodiscard]] constexpr E const&
error() const
error() const&
{
return Base::error();
}
constexpr E&
error()
[[nodiscard]] constexpr E&
error() &
{
return Base::error();
}
[[nodiscard]] constexpr E&&
error() &&
{
return std::move(Base::error());
}
constexpr explicit
operator bool() const
{

View File

@@ -14,6 +14,7 @@
#include <xrpl/basics/Blob.h>
#include <xrpl/basics/Buffer.h>
#include <xrpl/basics/Expected.h>
#include <xrpl/basics/Log.h>
#include <xrpl/basics/Number.h>
#include <xrpl/basics/Slice.h>
@@ -54,6 +55,7 @@
#include <algorithm>
#include <chrono>
#include <cstdint>
#include <exception>
#include <functional>
#include <memory>
@@ -405,6 +407,25 @@ checkTxJsonFields(
return ret;
}
static Expected<void, json::Value>
checkNetworkID(json::Value const& txJson, uint32_t appNetworkId)
{
if (appNetworkId > 1024)
{
if (!txJson.isMember(jss::NetworkID))
{
return Unexpected(
RPC::makeError(RpcInvalidParams, RPC::missingFieldMessage("tx_json.NetworkID")));
}
if (!txJson[jss::NetworkID].isIntegral() || txJson[jss::NetworkID].asUInt() != appNetworkId)
{
return Unexpected(
RPC::makeError(RpcInvalidParams, RPC::invalidFieldMessage("tx_json.NetworkID")));
}
}
return Expected<void, json::Value>();
}
//------------------------------------------------------------------------------
// A move-only struct that makes it easy to return either a json::Value or a
@@ -1165,8 +1186,16 @@ transactionSignFor(
if (!txJson.isObject())
return RPC::objectFieldError(jss::tx_json);
// If the tx_json.SigningPubKey field is missing,
// insert an empty one.
if (auto checkResult =
detail::checkNetworkID(txJson, app.getNetworkIDService().getNetworkID());
!checkResult)
{
return std::move(checkResult).error();
}
// If the tx_json.SigningPubKey field is missing, insert an empty one,
// in order for the `checkMultiSignFields` to not return an error
// for non-multisign transactions.
if (!txJson.isMember(sfSigningPubKey.getJsonName()))
txJson[sfSigningPubKey.getJsonName()] = "";
}