Skip to content

Commit cadf4da

Browse files
authored
fix: Adding validation for unknown field names (#223)
1 parent bd0d657 commit cadf4da

File tree

6 files changed

+22
-9
lines changed

6 files changed

+22
-9
lines changed

src/models/blockchain/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub mod stellar;
1111

1212
/// Supported blockchain platform types
1313
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
14+
#[serde(deny_unknown_fields)]
1415
pub enum BlockChainType {
1516
/// Ethereum Virtual Machine based chains
1617
EVM,

src/models/config/monitor_config.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@ mod tests {
229229
"contract_spec": null
230230
}
231231
],
232-
"description": "Test monitor configuration",
233232
"match_conditions": {
234233
"functions": [
235234
{"signature": "transfer(address,uint256)"}
@@ -239,8 +238,8 @@ mod tests {
239238
],
240239
"transactions": [
241240
{
242-
"signature": "Transfer(address,address,uint256)",
243-
"status": "Success"
241+
"status": "Success",
242+
"expression": null
244243
}
245244
]
246245
},
@@ -293,7 +292,6 @@ mod tests {
293292
"contract_spec": null
294293
}
295294
],
296-
"description": "Test monitor configuration",
297295
"match_conditions": {
298296
"functions": [
299297
{"signature": "transfer(address,uint256)"}
@@ -303,8 +301,8 @@ mod tests {
303301
],
304302
"transactions": [
305303
{
306-
"signature": "Transfer(address,address,uint256)",
307-
"status": "Success"
304+
"status": "Success",
305+
"expression": null
308306
}
309307
]
310308
},
@@ -322,7 +320,6 @@ mod tests {
322320
"contract_spec": null
323321
}
324322
],
325-
"description": "Test monitor configuration",
326323
"match_conditions": {
327324
"functions": [
328325
{"signature": "transfer(address,uint256)"}
@@ -332,8 +329,8 @@ mod tests {
332329
],
333330
"transactions": [
334331
{
335-
"signature": "Transfer(address,address,uint256)",
336-
"status": "Success"
332+
"status": "Success",
333+
"expression": null
337334
}
338335
]
339336
},

src/models/core/monitor.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::models::blockchain::ContractSpec;
1212
/// to the matched transactions before triggering the notifications
1313
/// - Triggers to execute when conditions are met
1414
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
15+
#[serde(deny_unknown_fields)]
1516
pub struct Monitor {
1617
/// Unique name identifying this monitor
1718
pub name: String,
@@ -37,6 +38,7 @@ pub struct Monitor {
3738

3839
/// Contract address with optional ABI for decoding transactions and events
3940
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
41+
#[serde(deny_unknown_fields)]
4042
pub struct AddressWithSpec {
4143
/// Contract address in the network's native format
4244
pub address: String,
@@ -47,6 +49,7 @@ pub struct AddressWithSpec {
4749

4850
/// Collection of conditions that can trigger a monitor
4951
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
52+
#[serde(deny_unknown_fields)]
5053
pub struct MatchConditions {
5154
/// Function calls to match
5255
pub functions: Vec<FunctionCondition>,
@@ -60,6 +63,7 @@ pub struct MatchConditions {
6063

6164
/// Condition for matching contract function calls
6265
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
66+
#[serde(deny_unknown_fields)]
6367
pub struct FunctionCondition {
6468
/// Function signature (e.g., "transfer(address,uint256)")
6569
pub signature: String,
@@ -70,6 +74,7 @@ pub struct FunctionCondition {
7074

7175
/// Condition for matching contract events
7276
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
77+
#[serde(deny_unknown_fields)]
7378
pub struct EventCondition {
7479
/// Event signature (e.g., "Transfer(address,address,uint256)")
7580
pub signature: String,
@@ -80,6 +85,7 @@ pub struct EventCondition {
8085

8186
/// Condition for matching transaction states
8287
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
88+
#[serde(deny_unknown_fields)]
8389
pub struct TransactionCondition {
8490
/// Required transaction status
8591
pub status: TransactionStatus,
@@ -90,6 +96,7 @@ pub struct TransactionCondition {
9096

9197
/// Possible transaction execution states
9298
#[derive(Debug, Copy, Clone, Deserialize, Serialize, PartialEq)]
99+
#[serde(deny_unknown_fields)]
93100
pub enum TransactionStatus {
94101
/// Match any transaction status
95102
Any,
@@ -101,6 +108,7 @@ pub enum TransactionStatus {
101108

102109
/// Conditions that should be met prior to triggering notifications
103110
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
111+
#[serde(deny_unknown_fields)]
104112
pub struct TriggerConditions {
105113
/// The path to the script
106114
pub script_path: String,

src/models/core/network.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::models::{BlockChainType, SecretValue};
77
/// Defines connection details and operational parameters for a specific blockchain network,
88
/// supporting both EVM and Stellar-based chains.
99
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
10+
#[serde(deny_unknown_fields)]
1011
pub struct Network {
1112
/// Type of blockchain (EVM, Stellar, etc)
1213
pub network_type: BlockChainType,
@@ -44,6 +45,7 @@ pub struct Network {
4445

4546
/// RPC endpoint configuration with load balancing weight
4647
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
48+
#[serde(deny_unknown_fields)]
4749
pub struct RpcUrl {
4850
/// Type of RPC endpoint (e.g. "rpc")
4951
pub type_: String,

src/models/core/trigger.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize};
44

55
/// Configuration for actions to take when monitored conditions are met.
66
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
7+
#[serde(deny_unknown_fields)]
78
pub struct Trigger {
89
/// Unique name identifying this trigger
910
pub name: String,
@@ -18,6 +19,7 @@ pub struct Trigger {
1819
/// Supported trigger action types
1920
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
2021
#[serde(rename_all = "lowercase")]
22+
#[serde(deny_unknown_fields)]
2123
pub enum TriggerType {
2224
/// Send notification to Slack
2325
Slack,
@@ -35,6 +37,7 @@ pub enum TriggerType {
3537

3638
/// Notification message fields
3739
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
40+
#[serde(deny_unknown_fields)]
3841
pub struct NotificationMessage {
3942
/// Notification title or subject
4043
pub title: String,
@@ -44,6 +47,7 @@ pub struct NotificationMessage {
4447

4548
/// Type-specific configuration for triggers
4649
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
50+
#[serde(deny_unknown_fields)]
4751
#[serde(untagged)]
4852
pub enum TriggerTypeConfig {
4953
/// Slack notification configuration

src/models/security/secret.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub async fn get_vault_client() -> SecurityResult<&'static VaultType> {
117117
/// All variants implement `ZeroizeOnDrop` to ensure secure memory cleanup.
118118
#[derive(Debug, Clone, Serialize, ZeroizeOnDrop)]
119119
#[serde(tag = "type", content = "value")]
120+
#[serde(deny_unknown_fields)]
120121
pub enum SecretValue {
121122
/// A plain text secret value
122123
Plain(SecretString),

0 commit comments

Comments
 (0)