Skip to content

Commit 7dcaaf2

Browse files
authored
Merge pull request #2473 from oasisprotocol/peternose/trivial/validate-app-id
runtime-sdk/src/modules/rofl: Verify proxy app ID
2 parents 8ff0d6c + 2b52055 commit 7dcaaf2

1 file changed

Lines changed: 16 additions & 5 deletions

File tree

  • runtime-sdk/src/modules/rofl

runtime-sdk/src/modules/rofl/mod.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ impl<Cfg: Config> Module<Cfg> {
712712
fn resolve_payer_from_tx<C: Context>(
713713
ctx: &C,
714714
tx: &Transaction,
715+
app_id: app_id::AppId,
715716
_app_policy: &policy::AppAuthPolicy,
716717
) -> Result<Option<Address>, anyhow::Error> {
717718
let caller_pk = tx
@@ -724,6 +725,9 @@ impl<Cfg: Config> Module<Cfg> {
724725
"rofl.Register" => {
725726
// For registration transactions, extract endorsing node.
726727
let body: types::Register = cbor::from_value(tx.call.body.clone())?;
728+
if body.app != app_id {
729+
return Err(Error::InvalidArgument.into());
730+
}
727731
if body.expiration <= ctx.epoch() {
728732
return Err(Error::RegistrationExpired.into());
729733
}
@@ -751,9 +755,14 @@ impl<Cfg: Config> Module<Cfg> {
751755
Some(pk) => pk,
752756
None => return Ok(None),
753757
};
754-
755-
Ok(state::get_endorser(&caller_pk)
756-
.map(|ei| Address::from_consensus_pk(&ei.node_id)))
758+
let endorser = match state::get_endorser(&caller_pk) {
759+
Some(ei) => ei,
760+
None => return Ok(None),
761+
};
762+
if endorser.app_id != app_id {
763+
return Err(Error::InvalidArgument.into());
764+
}
765+
Ok(Some(Address::from_consensus_pk(&endorser.node_id)))
757766
}
758767
}
759768
}
@@ -788,8 +797,10 @@ impl<Cfg: Config> module::FeeProxyHandler for Module<Cfg> {
788797
// Application needs to figure out a way to pay, defer to regular handler.
789798
Ok(None)
790799
}
791-
FeePolicy::EndorsingNodePays => Self::resolve_payer_from_tx(ctx, tx, &app_policy)
792-
.map_err(modules::core::Error::InvalidArgument),
800+
FeePolicy::EndorsingNodePays => {
801+
Self::resolve_payer_from_tx(ctx, tx, app_id, &app_policy)
802+
.map_err(modules::core::Error::InvalidArgument)
803+
}
793804
}
794805
}
795806
}

0 commit comments

Comments
 (0)