FilterValidator

Struct FilterValidator 

Source
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:

  1. Field whitelist - only specific fields can be queried
  2. Operator blacklist - dangerous operators can be denied
  3. Nesting depth limit - prevent complex nested queries
  4. 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: usize

Maximum nesting depth for complex filters.

Implementations§

Source§

impl FilterValidator

Source

pub fn new() -> Self

Create a new validator with secure defaults.

Defaults:

  • No field restrictions (allow all)
  • Denies Regex operator (ReDoS prevention)
  • 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"]);
Source

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();
Source

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.

Source

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.

Source

pub fn max_depth(self, depth: usize) -> Self

Set maximum nesting depth.

Prevents complex nested queries that could impact performance. Default is 5.

Source

pub fn validate(&self, filter: &Filter) -> Result<(), ValidationError>

Validate a filter against the configured rules.

Returns an error if:

  • Field is not in the allowed list (when list is not empty)
  • Operator is in the denied list
  • Array nesting depth exceeds maximum

Trait Implementations§

Source§

impl Clone for FilterValidator

Source§

fn clone(&self) -> FilterValidator

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterValidator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for FilterValidator

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.