pub struct Synapse { /* private fields */ }Expand description
Main WAF detection engine facade.
This struct provides the same API as libsynapse::Synapse, enabling a drop-in replacement.
§Example
use synapse_pingora::waf::{Synapse, Request, Action};
let mut synapse = Synapse::new();
synapse.load_rules(rules_json).unwrap();
let verdict = synapse.analyze(&Request {
method: "GET",
path: "/api/users?id=1' OR '1'='1",
..Default::default()
});
assert_eq!(verdict.action, Action::Block);Implementations§
Source§impl Synapse
impl Synapse
Sourcepub fn with_profile_config(profile_config: ProfileStoreConfig) -> Self
pub fn with_profile_config(profile_config: ProfileStoreConfig) -> Self
Create a new Synapse instance with custom profile configuration.
Sourcepub fn load_rules(&mut self, json: &[u8]) -> Result<usize, WafError>
pub fn load_rules(&mut self, json: &[u8]) -> Result<usize, WafError>
Load rules from JSON.
Returns the number of rules loaded on success.
Sourcepub fn precompute_rules(&self, json: &[u8]) -> Result<CompiledRules, WafError>
pub fn precompute_rules(&self, json: &[u8]) -> Result<CompiledRules, WafError>
Precompute all rule structures including regex compilation.
Sourcepub fn reload_from_compiled(&mut self, compiled: CompiledRules)
pub fn reload_from_compiled(&mut self, compiled: CompiledRules)
Fast swap of rule state using precomputed data.
Sourcepub fn parse_rules(json: &[u8]) -> Result<Vec<WafRule>, WafError>
pub fn parse_rules(json: &[u8]) -> Result<Vec<WafRule>, WafError>
Parse rules from JSON bytes without modifying state.
Sourcepub fn reload_rules(&mut self, rules: Vec<WafRule>) -> Result<(), WafError>
pub fn reload_rules(&mut self, rules: Vec<WafRule>) -> Result<(), WafError>
Reload the engine with a new set of pre-parsed rules.
Sourcepub fn analyze_with_trace(
&self,
req: &Request<'_>,
trace: &mut dyn TraceSink,
) -> Verdict
pub fn analyze_with_trace( &self, req: &Request<'_>, trace: &mut dyn TraceSink, ) -> Verdict
Analyze a request and emit evaluation trace events.
Sourcepub fn analyze_with_timeout(
&self,
req: &Request<'_>,
timeout: Duration,
) -> Verdict
pub fn analyze_with_timeout( &self, req: &Request<'_>, timeout: Duration, ) -> Verdict
Sourcepub fn analyze_safe(&self, req: &Request<'_>) -> Verdict
pub fn analyze_safe(&self, req: &Request<'_>) -> Verdict
Analyze a request with the default timeout (50ms).
Recommended for production use to prevent DoS attacks.
Sourcepub fn record_response_status(&self, path: &str, status: u16)
pub fn record_response_status(&self, path: &str, status: u16)
Record response status code for profiling.
Updates the endpoint profile with the observed status code, enabling baseline learning and anomaly detection.
Sourcepub fn get_profiles(&self) -> Vec<EndpointProfile>
pub fn get_profiles(&self) -> Vec<EndpointProfile>
Get all learned profiles.
Returns a snapshot of all endpoint profiles currently in storage.
Sourcepub fn load_profiles(&self, profiles: Vec<EndpointProfile>)
pub fn load_profiles(&self, profiles: Vec<EndpointProfile>)
Load profiles into the engine.
Merges or replaces profiles in storage from a previous snapshot.
Sourcepub fn rule_count(&self) -> usize
pub fn rule_count(&self) -> usize
Get the number of loaded rules.
Sourcepub fn risk_config(&self) -> RiskConfig
pub fn risk_config(&self) -> RiskConfig
Get current risk configuration.
Sourcepub fn set_risk_config(&self, config: RiskConfig)
pub fn set_risk_config(&self, config: RiskConfig)
Set risk configuration.
Updates the risk thresholds for anomaly-based blocking.
Sourcepub fn profile_count(&self) -> usize
pub fn profile_count(&self) -> usize
Get the number of stored profiles.
Sourcepub fn clear_profiles(&self)
pub fn clear_profiles(&self)
Clear all stored profiles.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Synapse
impl !RefUnwindSafe for Synapse
impl Send for Synapse
impl Sync for Synapse
impl Unpin for Synapse
impl UnsafeUnpin for Synapse
impl UnwindSafe for Synapse
Blanket Implementations§
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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more