Skip to content

Commit

Permalink
fix: metadata key validation for cotnract analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
hugocaillard committed Nov 15, 2024
1 parent f27c84f commit 7f86352
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions stackslib/src/net/api/getclaritymetadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,6 @@ impl HttpRequest for RPCGetClarityMetadataRequestHandler {

let contract_identifier = request::get_contract_address(captures, "address", "contract")?;

// Validate that the metadata key is well-formed. It must be of data type:
// DataMapMeta (5) | VariableMeta (6) | FungibleTokenMeta (7) | NonFungibleTokenMeta (8)
// or Contract (9) followed by a valid contract metadata name
match captures
.name("data_type")
.and_then(|data_type| StoreType::try_from(data_type.as_str()).ok())
{
Some(data_type) => match data_type {
StoreType::DataMapMeta
| StoreType::VariableMeta
| StoreType::FungibleTokenMeta
| StoreType::NonFungibleTokenMeta => {}
StoreType::Contract => {
if captures
.name("var_name")
.and_then(|var_name| ContractDataVarName::try_from(var_name.as_str()).ok())
.is_none()
{
return Err(Error::DecodeError("Invalid metadata var name".to_string()));
}
}
_ => {
return Err(Error::DecodeError("Invalid metadata type".to_string()));
}
},
None => {
return Err(Error::DecodeError("Invalid metadata type".to_string()));
}
}

let metadata_key = match captures.name("clarity_metadata_key") {
Some(key_str) => key_str.as_str().to_string(),
None => {
Expand All @@ -137,6 +107,42 @@ impl HttpRequest for RPCGetClarityMetadataRequestHandler {
}
};

if metadata_key != "analysis" {
// Validate that the metadata key is well-formed. It must be of data type:
// DataMapMeta (5) | VariableMeta (6) | FungibleTokenMeta (7) | NonFungibleTokenMeta (8)
// or Contract (9) followed by a valid contract metadata name
match captures
.name("data_type")
.and_then(|data_type| StoreType::try_from(data_type.as_str()).ok())
{
Some(data_type) => match data_type {
StoreType::DataMapMeta
| StoreType::VariableMeta
| StoreType::FungibleTokenMeta
| StoreType::NonFungibleTokenMeta => {}
StoreType::Contract => {
if captures
.name("var_name")
.and_then(|var_name| {
ContractDataVarName::try_from(var_name.as_str()).ok()
})
.is_none()
{
return Err(Error::DecodeError(
"Invalid metadata var name".to_string(),
));
}
}
_ => {
return Err(Error::DecodeError("Invalid metadata type".to_string()));
}
},
None => {
return Err(Error::DecodeError("Invalid metadata type".to_string()));
}
}
}

self.contract_identifier = Some(contract_identifier);
self.clarity_metadata_key = Some(metadata_key);

Expand Down

0 comments on commit 7f86352

Please sign in to comment.