pub struct FilterValidator {
pub allowed_fields: Vec<String>,
pub denied_operators: Vec<Operator>,
pub max_depth: usize,
}Expand description
Validation configuration for user-provided filters.
Provides four layers of security:
- Field whitelist - only specific fields can be queried
- Operator blacklist - dangerous operators can be denied
- Nesting depth limit - prevent complex nested queries
- Total node count limit - prevent DoS via large arrays
Fields§
§allowed_fields: Vec<String>Allowed field names (whitelist). Empty = allow all fields.
denied_operators: Vec<Operator>Denied operators (blacklist).
max_depth: usizeMaximum nesting depth for complex filters.
Implementations§
Source§impl FilterValidator
impl FilterValidator
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new validator with secure defaults.
Defaults:
- No field restrictions (allow all)
- Denies
Regexoperator (ReDoSprevention) - Max nesting depth: 5
This is the recommended constructor for user-facing filters.
For internal/trusted filters where you need all operators,
use permissive().
§Example
use mik_sql::FilterValidator;
let validator = FilterValidator::new()
.allow_fields(&["name", "email", "status"]);Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive validator that allows all operators.
Warning: Only use this for trusted/internal filters, never for
user-provided input. The Regex operator can cause ReDoS attacks.
§Example
use mik_sql::FilterValidator;
// Only for trusted internal filters!
let validator = FilterValidator::permissive();Sourcepub fn allow_fields(self, fields: &[&str]) -> Self
pub fn allow_fields(self, fields: &[&str]) -> Self
Set allowed fields (whitelist).
Only fields in this list can be used in user filters. If empty, all fields are allowed.
Sourcepub fn deny_operators(self, ops: &[Operator]) -> Self
pub fn deny_operators(self, ops: &[Operator]) -> Self
Set denied operators (blacklist).
These operators cannot be used in user filters. Useful for blocking regex, pattern matching, or other expensive operations.
Trait Implementations§
Source§impl Clone for FilterValidator
impl Clone for FilterValidator
Source§fn clone(&self) -> FilterValidator
fn clone(&self) -> FilterValidator
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more