From d51b59afd7503c8703f7ac0ff8c564cbc4f6eaf4 Mon Sep 17 00:00:00 2001 From: brentstone Date: Sun, 8 Sep 2024 15:19:50 +0200 Subject: [PATCH 1/2] add check on metadata name --- crates/apps_lib/src/config/genesis/transactions.rs | 9 +++++++++ crates/sdk/src/tx.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/crates/apps_lib/src/config/genesis/transactions.rs b/crates/apps_lib/src/config/genesis/transactions.rs index 94cc9d038c..4ab224db20 100644 --- a/crates/apps_lib/src/config/genesis/transactions.rs +++ b/crates/apps_lib/src/config/genesis/transactions.rs @@ -1417,6 +1417,15 @@ pub fn validate_validator_account( ); } } + if let Some(name) = metadata.name.as_ref() { + if name.len() as u64 > MAX_VALIDATOR_METADATA_LEN { + panic!( + "The name metadata of the validator with address {} is too \ + long, must be within {MAX_VALIDATOR_METADATA_LEN} characters", + signed_tx.data.address + ); + } + } // Check signature let mut is_valid = { diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 79475db3b4..116ed815e7 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -846,6 +846,18 @@ pub async fn build_validator_metadata_change( } } } + if let Some(name) = name.as_ref() { + if name.len() as u64 > MAX_VALIDATOR_METADATA_LEN { + edisplay_line!( + context.io(), + "Name provided is too long, must be within \ + {MAX_VALIDATOR_METADATA_LEN} characters" + ); + if !tx_args.force { + return Err(Error::from(TxSubmitError::MetadataTooLong)); + } + } + } // If there's a new commission rate, it must be valid if let Some(rate) = commission_rate.as_ref() { From 46eb69b3367f205d55f3343b08a6a680e88ab26a Mon Sep 17 00:00:00 2001 From: brentstone Date: Sun, 8 Sep 2024 15:21:45 +0200 Subject: [PATCH 2/2] changelog: add #3779 --- .../unreleased/improvements/3779-restrict-metadat-name-len.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changelog/unreleased/improvements/3779-restrict-metadat-name-len.md diff --git a/.changelog/unreleased/improvements/3779-restrict-metadat-name-len.md b/.changelog/unreleased/improvements/3779-restrict-metadat-name-len.md new file mode 100644 index 0000000000..55f0bd84ba --- /dev/null +++ b/.changelog/unreleased/improvements/3779-restrict-metadat-name-len.md @@ -0,0 +1,2 @@ +- Check the string length of the validator name in provided metadata. + ([\#3779](https://github.com/anoma/namada/pull/3779)) \ No newline at end of file