Skip to main content

bulwark_security/security/
inspector_method.rs

1use crate::request::context::{Method, RequestContext};
2use crate::security::inspector::{Inspector, InspectorFinding};
3use crate::security::FindingSeverity;
4use crate::BulwarkError;
5
6pub struct InspectorMethod {
7    allowed_methods: Vec<Method>,
8}
9
10impl InspectorMethod {
11    pub fn new(allowed_methods: Vec<Method>) -> Self {
12        Self { allowed_methods }
13    }
14}
15
16impl Inspector for InspectorMethod {
17    fn inspect(&self, ctx: &RequestContext) -> Result<Option<InspectorFinding>, BulwarkError> {
18        if !self.allowed_methods.contains(&ctx.method) {
19            return Ok(Some(InspectorFinding::new(
20                "inspector_method",
21                FindingSeverity::High,
22                format!("method {:?} is not allowed", ctx.method),
23            )));
24        }
25
26        Ok(None)
27    }
28}