-
Notifications
You must be signed in to change notification settings - Fork 14
Fix: origin-rewriting wrappers bypass high-security restrictions #610
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
96fc033
6ae322e
e196524
32c521a
ed2522c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ use pallet_ranked_collective::Linear; | |
| use pallet_transaction_payment::{ConstFeeMultiplier, FungibleAdapter, Multiplier}; | ||
| use smallvec::smallvec; | ||
|
|
||
| use qp_high_security::HighSecurityInspector; | ||
| use qp_scheduler::BlockNumberOrTimestamp; | ||
| use sp_runtime::{ | ||
| traits::{AccountIdConversion, BlakeTwo256, One}, | ||
|
|
@@ -623,6 +624,77 @@ impl qp_high_security::HighSecurityInspector<AccountId, RuntimeCall> for HighSec | |
| // Delegate to reversible-transfers pallet | ||
| pallet_reversible_transfers::Pallet::<Runtime>::get_guardian(who) | ||
| } | ||
|
|
||
| fn is_call_allowed(who: &AccountId, call: &RuntimeCall) -> bool { | ||
| Self::call_allowed_for(who, call, 0) | ||
| } | ||
| } | ||
|
|
||
| impl HighSecurityConfig { | ||
| /// Maximum wrapper nesting the high-security resolver traverses. Far above any realistic | ||
| /// legitimate nesting yet far below `frame_support::MAX_EXTRINSIC_DEPTH` (256, enforced at | ||
| /// decode), so it bounds resolver work even if the decode limit ever changed. Calls nested | ||
| /// deeper fail closed (the transaction is rejected) rather than escaping the whitelist. | ||
| const MAX_CALL_DEPTH: u32 = 16; | ||
|
|
||
| /// Recursively verify that `call`, dispatched with `signer` as the effective signed | ||
| /// origin, never reaches a non-whitelisted call as a high-security account. | ||
| /// | ||
| /// Origin-rewriting wrappers (`Utility::as_derivative`, `Recovery::as_recovered`) | ||
| /// synthesize a fresh `Signed` origin *after* top-level transaction validation, so the | ||
| /// high-security whitelist must be re-checked at the effective origin. Origin-preserving | ||
| /// combinators (`batch`/`batch_all`/`force_batch`/`if_else`) are traversed with the same | ||
| /// signer. `dispatch_as`/`with_weight` and the scheduler are root-only, so they are not an | ||
| /// unprivileged bypass and are intentionally not traversed. | ||
| fn call_allowed_for(signer: &AccountId, call: &RuntimeCall, depth: u32) -> bool { | ||
| if depth > Self::MAX_CALL_DEPTH { | ||
| return false; | ||
| } | ||
| if Self::is_high_security(signer) && !Self::is_whitelisted(call) { | ||
| return false; | ||
| } | ||
| match call { | ||
| RuntimeCall::Utility(pallet_utility::Call::as_derivative { index, call }) => { | ||
| let pseudonym = pallet_utility::derivative_account_id(signer.clone(), *index); | ||
| Self::call_allowed_for(&pseudonym, call, depth + 1) | ||
| }, | ||
| RuntimeCall::Recovery(pallet_recovery::Call::as_recovered { account, call }) => | ||
| match account { | ||
| sp_runtime::MultiAddress::Id(target) => | ||
| Self::call_allowed_for(target, call, depth + 1), | ||
| // Other address kinds are unresolvable by the runtime lookup and cannot | ||
| // dispatch, so there is no effective origin to enforce. | ||
| _ => true, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recovery non-Id skips HS checkHigh Severity In Reviewed by Cursor Bugbot for commit 32c521a. Configure here. |
||
| }, | ||
| RuntimeCall::Utility(pallet_utility::Call::batch { calls }) | | ||
| RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) | | ||
| RuntimeCall::Utility(pallet_utility::Call::force_batch { calls }) => | ||
| calls.iter().all(|c| Self::call_allowed_for(signer, c, depth + 1)), | ||
| RuntimeCall::Utility(pallet_utility::Call::if_else { main, fallback }) => | ||
| Self::call_allowed_for(signer, main, depth + 1) && | ||
| Self::call_allowed_for(signer, fallback, depth + 1), | ||
| _ => true, | ||
| } | ||
| } | ||
|
|
||
| /// Upper bound on the `is_high_security` storage reads `call_allowed_for` performs for | ||
| /// `call` (one per traversed node), used to weight the transaction extension. | ||
| pub(crate) fn high_security_read_count(call: &RuntimeCall) -> u64 { | ||
| let inner = match call { | ||
| RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) | | ||
| RuntimeCall::Recovery(pallet_recovery::Call::as_recovered { call, .. }) => | ||
| Self::high_security_read_count(call), | ||
| RuntimeCall::Utility(pallet_utility::Call::batch { calls }) | | ||
| RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) | | ||
| RuntimeCall::Utility(pallet_utility::Call::force_batch { calls }) => | ||
| calls.iter().map(Self::high_security_read_count).sum(), | ||
| RuntimeCall::Utility(pallet_utility::Call::if_else { main, fallback }) => | ||
| Self::high_security_read_count(main) | ||
| .saturating_add(Self::high_security_read_count(fallback)), | ||
| _ => 0, | ||
| }; | ||
| inner.saturating_add(1) | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weight counts unbounded call depthMedium Severity
Reviewed by Cursor Bugbot for commit 32c521a. Configure here. |
||
| } | ||
|
|
||
| impl pallet_multisig::Config for Runtime { | ||
|
|
||


There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Propose skips recursive HS check
Medium Severity
proposestill gates high-security multisigs with a shallowis_high_securityplusis_whitelistedcheck on the decoded call, whileexecutenow usesis_call_allowed, which applies the depth limit and recursive origin resolution. Proposals can be created and approved whose inner callsexecutewill always reject.Additional Locations (1)
pallets/multisig/src/lib.rs#L1127-L1135Reviewed by Cursor Bugbot for commit 32c521a. Configure here.