Skip to content

Commit 3db5026

Browse files
committed
fix permission delegation vulnerability
1 parent 0fd2f71 commit 3db5026

File tree

21 files changed

+298
-298
lines changed

21 files changed

+298
-298
lines changed

include/xrpl/protocol/TER.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ enum TERcodes : TERUnderlyingType {
225225
terQUEUED, // Transaction is being held in TxQ until fee drops
226226
terPRE_TICKET, // Ticket is not yet in ledger but might be on its way
227227
terNO_AMM, // AMM doesn't exist for the asset pair
228-
terADDRESS_COLLISION, // Failed to allocate AccountID when trying to
229-
// create a pseudo-account
228+
terADDRESS_COLLISION, // Failed to allocate AccountID when trying to
229+
// create a pseudo-account
230+
terNO_DELEGATE_PERMISSION, // Delegate does not have permission
230231
};
231232

232233
//------------------------------------------------------------------------------
@@ -361,6 +362,9 @@ enum TECcodes : TERUnderlyingType {
361362
tecLIMIT_EXCEEDED = 195,
362363
tecPSEUDO_ACCOUNT = 196,
363364
tecPRECISION_LOSS = 197,
365+
// DEPRECATED: This error code tecNO_DELEGATE_PERMISSION is reserved for
366+
// backward compatibility with historical data on non-prod networks, can be
367+
// reclaimed after those networks reset.
364368
tecNO_DELEGATE_PERMISSION = 198,
365369
};
366370

include/xrpl/protocol/detail/features.macro

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
// If you add an amendment here, then do not forget to increment `numFeatures`
3333
// in include/xrpl/protocol/Feature.h.
3434

35+
XRPL_FEATURE(PermissionDelegationV1_1, Supported::yes, VoteBehavior::DefaultNo)
3536
XRPL_FIX (IncludeKeyletFields, Supported::yes, VoteBehavior::DefaultNo)
3637
XRPL_FEATURE(DynamicMPT, Supported::no, VoteBehavior::DefaultNo)
3738
XRPL_FIX (TokenEscrowV1, Supported::yes, VoteBehavior::DefaultNo)
38-
XRPL_FIX (DelegateV1_1, Supported::no, VoteBehavior::DefaultNo)
3939
XRPL_FIX (PriceOracleOrder, Supported::yes, VoteBehavior::DefaultNo)
4040
XRPL_FIX (MPTDeliveredAmount, Supported::no, VoteBehavior::DefaultNo)
4141
XRPL_FIX (AMMClawbackRounding, Supported::yes, VoteBehavior::DefaultNo)
@@ -45,7 +45,6 @@ XRPL_FIX (AMMv1_3, Supported::yes, VoteBehavior::DefaultNo
4545
XRPL_FEATURE(PermissionedDEX, Supported::yes, VoteBehavior::DefaultNo)
4646
XRPL_FEATURE(Batch, Supported::yes, VoteBehavior::DefaultNo)
4747
XRPL_FEATURE(SingleAssetVault, Supported::no, VoteBehavior::DefaultNo)
48-
XRPL_FEATURE(PermissionDelegation, Supported::yes, VoteBehavior::DefaultNo)
4948
XRPL_FIX (PayChanCancelAfter, Supported::yes, VoteBehavior::DefaultNo)
5049
// Check flags in Credential transactions
5150
XRPL_FIX (InvalidTxFlags, Supported::yes, VoteBehavior::DefaultNo)

include/xrpl/protocol/detail/transactions.macro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ TRANSACTION(ttTRUST_SET, 20, TrustSet,
316316
#endif
317317
TRANSACTION(ttACCOUNT_DELETE, 21, AccountDelete,
318318
Delegation::notDelegatable,
319-
uint256{},
319+
featureDeletableAccounts,
320320
mustDeleteAcct,
321321
({
322322
{sfDestination, soeREQUIRED},
@@ -837,7 +837,7 @@ TRANSACTION(ttPERMISSIONED_DOMAIN_DELETE, 63, PermissionedDomainDelete,
837837
#endif
838838
TRANSACTION(ttDELEGATE_SET, 64, DelegateSet,
839839
Delegation::notDelegatable,
840-
featurePermissionDelegation,
840+
featurePermissionDelegationV1_1,
841841
noPriv,
842842
({
843843
{sfAuthorize, soeREQUIRED},

src/libxrpl/protocol/Permissions.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -161,25 +161,22 @@ Permission::isDelegatable(
161161
auto const txType = permissionToTxType(permissionValue);
162162
auto const it = delegatableTx_.find(txType);
163163

164-
if (rules.enabled(fixDelegateV1_1))
165-
{
166-
if (it == delegatableTx_.end())
167-
return false;
164+
if (it == delegatableTx_.end())
165+
return false;
168166

169-
auto const txFeaturesIt = txFeatureMap_.find(txType);
170-
XRPL_ASSERT(
171-
txFeaturesIt != txFeatureMap_.end(),
172-
"ripple::Permissions::isDelegatable : tx exists in txFeatureMap_");
173-
174-
// fixDelegateV1_1: Delegation is only allowed if the required amendment
175-
// for the transaction is enabled. For transactions that do not require
176-
// an amendment, delegation is always allowed.
177-
if (txFeaturesIt->second != uint256{} &&
178-
!rules.enabled(txFeaturesIt->second))
179-
return false;
180-
}
181-
182-
if (it != delegatableTx_.end() && it->second == Delegation::notDelegatable)
167+
auto const txFeaturesIt = txFeatureMap_.find(txType);
168+
XRPL_ASSERT(
169+
txFeaturesIt != txFeatureMap_.end(),
170+
"ripple::Permissions::isDelegatable : tx exists in txFeatureMap_");
171+
172+
// Delegation is only allowed if the required amendment for the transaction
173+
// is enabled. For transactions that do not require an amendment, delegation
174+
// is always allowed.
175+
if (txFeaturesIt->second != uint256{} &&
176+
!rules.enabled(txFeaturesIt->second))
177+
return false;
178+
179+
if (it->second == Delegation::notDelegatable)
183180
return false;
184181

185182
return true;

src/libxrpl/protocol/TER.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ transResults()
127127
MAKE_ERROR(tecLIMIT_EXCEEDED, "Limit exceeded."),
128128
MAKE_ERROR(tecPSEUDO_ACCOUNT, "This operation is not allowed against a pseudo-account."),
129129
MAKE_ERROR(tecPRECISION_LOSS, "The amounts used by the transaction cannot interact."),
130-
MAKE_ERROR(tecNO_DELEGATE_PERMISSION, "Delegated account lacks permission to perform this transaction."),
131130

132131
MAKE_ERROR(tefALREADY, "The exact transaction was already in this ledger."),
133132
MAKE_ERROR(tefBAD_ADD_AUTH, "Not authorized to add account."),
@@ -235,6 +234,7 @@ transResults()
235234
MAKE_ERROR(terPRE_TICKET, "Ticket is not yet in ledger."),
236235
MAKE_ERROR(terNO_AMM, "AMM doesn't exist for the asset pair."),
237236
MAKE_ERROR(terADDRESS_COLLISION, "Failed to allocate an unique account address."),
237+
MAKE_ERROR(terNO_DELEGATE_PERMISSION, "Delegated account lacks permission to perform this transaction."),
238238

239239
MAKE_ERROR(tesSUCCESS, "The transaction was applied. Only final in a validated ledger."),
240240
};

src/test/app/Batch_test.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,14 +3946,13 @@ class Batch_test : public beast::unit_test::suite
39463946
tesSUCCESS,
39473947
batch::outer(gw, seq, batchFee, tfIndependent),
39483948
batch::inner(jv1, seq + 1),
3949-
// tecNO_DELEGATE_PERMISSION: not authorized to clear freeze
3949+
// terNO_DELEGATE_PERMISSION: not authorized to clear freeze
39503950
batch::inner(jv2, seq + 2));
39513951
env.close();
39523952

39533953
std::vector<TestLedgerData> testCases = {
39543954
{0, "Batch", "tesSUCCESS", batchID, std::nullopt},
39553955
{1, "TrustSet", "tesSUCCESS", txIDs[0], batchID},
3956-
{2, "TrustSet", "tecNO_DELEGATE_PERMISSION", txIDs[1], batchID},
39573956
};
39583957
validateClosedLedger(env, testCases);
39593958
}

0 commit comments

Comments
 (0)