From b8571a49e5387605f5614165921ce1c89e85259d Mon Sep 17 00:00:00 2001 From: redshiftzero Date: Mon, 16 Sep 2024 19:48:33 -0400 Subject: [PATCH] governance: validate client ID check earlier than component/view.rs --- crates/core/component/governance/src/proposal.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/crates/core/component/governance/src/proposal.rs b/crates/core/component/governance/src/proposal.rs index d979dc444e..8931f2dfc1 100644 --- a/crates/core/component/governance/src/proposal.rs +++ b/crates/core/component/governance/src/proposal.rs @@ -1,5 +1,6 @@ use anyhow::Context; use bytes::Bytes; +use ibc_types::core::client::ClientId; use serde::{Deserialize, Serialize}; use std::str::FromStr; @@ -144,6 +145,9 @@ impl TryFrom for Proposal { if freeze_ibc_client.client_id.len() > 128 { anyhow::bail!("client ID must be less than 128 bytes"); } + // Validation: Check the client ID is valid using the validation inside `ClientId::from_str`. + ClientId::from_str(&freeze_ibc_client.client_id) + .map_err(|e| anyhow::anyhow!("invalid client id: {e}"))?; ProposalPayload::FreezeIbcClient { client_id: freeze_ibc_client.client_id, } @@ -153,6 +157,9 @@ impl TryFrom for Proposal { if unfreeze_ibc_client.client_id.len() > 128 { anyhow::bail!("client ID must be less than 128 bytes"); } + // Validation: Check the client ID is valid using the validation inside `ClientId::from_str`. + ClientId::from_str(&unfreeze_ibc_client.client_id) + .map_err(|e| anyhow::anyhow!("invalid client id: {e}"))?; ProposalPayload::UnfreezeIbcClient { client_id: unfreeze_ibc_client.client_id, }