Crates.io | modsecurity-rs |
lib.rs | modsecurity-rs |
version | 0.1.4 |
source | src |
created_at | 2024-01-13 10:29:42.078654 |
updated_at | 2024-01-25 06:42:39.076995 |
description | Safe wrapper around libmodsecurity |
homepage | |
repository | |
max_upload_size | |
id | 1098459 |
size | 41,895 |
This crate provides a high-level Rust wrapper around the C++ implementation of libmodsecurity.
Using the library required having libmodsecurity installed.
sudo apt install libmodsecurity
sudo dnf install libmodsecurity
sudo pacman -S libmodsecurity
fn main() -> anyhow::Result<()> {
let mut modsec = ModSecurity::new();
let mut rules = RulesSet::from_paths(&["resource/sample-ruleset.conf"])?;
let mut tx = Transaction::new(&mut modsec, &mut rules);
tx.process_connection("127.0.0.1".parse().unwrap(), 31337, "localhost", 80)?;
tx.process_uri("/test.pl?param1=test¶2=test2", "GET", "1.1")?;
tx.add_request_header("Host", "foo.bar")?;
tx.process_request_headers()?;
tx.process_request_body()?;
let it = tx.intervention()?;
assert_eq!(it.status, 403);
assert!(!it.pause);
assert!(it.disruptive);
assert!(it.log.len() > 0);
assert!(it.url.is_empty());
tx.process_logging()?;
Ok(())
}