pub struct GuardrailsFilter { /* private fields */ }Expand description
Rejects requests matching string, regex, or PII rules against headers and/or body content.
§YAML configuration
filter: guardrails
action: flag # or "reject" (default)
rules:
# Detect PII in a header
- target: header
name: "Authorization"
contains: [ssn, credit_card, email]
# Detect PII in body
- target: body
contains: [ssn, credit_card, phone, email]
# Block SQL injection in body
- target: body
contains: "DROP TABLE"
# Block requests from bad bots
- target: header
name: "User-Agent"
pattern: "bad-bot.*"
# Require body to look like JSON (reject if NOT matching)
- target: body
pattern: "^\\{.*\\}$"
negate: true§Example
use praxis_filter::GuardrailsFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(
r#"
rules:
- target: header
name: User-Agent
contains: bad-bot
"#,
)
.unwrap();
let filter = GuardrailsFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "guardrails");Implementations§
Source§impl GuardrailsFilter
impl GuardrailsFilter
Sourcepub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
pub fn from_config(config: &Value) -> Result<Box<dyn HttpFilter>, FilterError>
Create a guardrails filter from parsed YAML config.
Compiles all regex patterns at init time. Returns an error if a rule has an invalid regex, missing fields, or unknown target.
use praxis_filter::GuardrailsFilter;
let yaml: serde_yaml::Value = serde_yaml::from_str(
r#"
rules:
- target: body
pattern: "SELECT.*FROM"
"#,
)
.unwrap();
let filter = GuardrailsFilter::from_config(&yaml).unwrap();
assert_eq!(filter.name(), "guardrails");§Errors
Returns FilterError if rules are empty or contain invalid regex.
Trait Implementations§
Source§impl HttpFilter for GuardrailsFilter
impl HttpFilter for GuardrailsFilter
Source§fn name(&self) -> &'static str
fn name(&self) -> &'static str
Unique name identifying this filter type (e.g.
"router", "rate_limit").Source§fn request_body_access(&self) -> BodyAccess
fn request_body_access(&self) -> BodyAccess
Declares what access this filter needs to request bodies. Read more
Source§fn request_body_mode(&self) -> BodyMode
fn request_body_mode(&self) -> BodyMode
Declares the delivery mode for request body chunks. Read more
Source§fn on_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_request<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each incoming request, in pipeline order.
Source§fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
body: &'life3 mut Option<Bytes>,
end_of_stream: bool,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
fn on_request_body<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
body: &'life3 mut Option<Bytes>,
end_of_stream: bool,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Called for each chunk of request body data, in pipeline order. Read more
Source§fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn on_response<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
ctx: &'life1 mut HttpFilterContext<'life2>,
) -> Pin<Box<dyn Future<Output = Result<FilterAction, FilterError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Called for each response, in reverse pipeline order. Read more
Source§fn response_body_access(&self) -> BodyAccess
fn response_body_access(&self) -> BodyAccess
Declares what access this filter needs to response bodies. Read more
Source§fn response_body_mode(&self) -> BodyMode
fn response_body_mode(&self) -> BodyMode
Declares the delivery mode for response body chunks. Read more
Source§fn needs_request_context(&self) -> bool
fn needs_request_context(&self) -> bool
Whether this filter needs the original request context
during body phases. Read more
Source§fn apply_insecure_options(&self, _options: &InsecureOptions)
fn apply_insecure_options(&self, _options: &InsecureOptions)
Apply global
InsecureOptions to this filter. Read moreSource§fn compression_config(&self) -> Option<&CompressionConfig>
fn compression_config(&self) -> Option<&CompressionConfig>
Returns the compression configuration if this filter enables
response compression. Read more
Source§fn on_response_body(
&self,
ctx: &mut HttpFilterContext<'_>,
body: &mut Option<Bytes>,
end_of_stream: bool,
) -> Result<FilterAction, FilterError>
fn on_response_body( &self, ctx: &mut HttpFilterContext<'_>, body: &mut Option<Bytes>, end_of_stream: bool, ) -> Result<FilterAction, FilterError>
Called for each chunk of response body data, in reverse
pipeline order. Read more
Auto Trait Implementations§
impl Freeze for GuardrailsFilter
impl RefUnwindSafe for GuardrailsFilter
impl Send for GuardrailsFilter
impl Sync for GuardrailsFilter
impl Unpin for GuardrailsFilter
impl UnsafeUnpin for GuardrailsFilter
impl UnwindSafe for GuardrailsFilter
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more