Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
coraza-rs
Safe Rust bindings to OWASP Coraza Web Application Firewall, based on the official C bindings.
Coraza is a Go-based WAF compatible with ModSecurity's SecLang. This repository provides Rust crates to embed Coraza into Rust applications.
Crates
| Crate | Description |
|---|---|
coraza |
Safe, idiomatic Rust API |
coraza-sys |
Raw FFI bindings (auto-generated from C header) |
examples |
Usage examples |
Quick Start
use WafConfig;
Build Requirements
- Rust 1.75+ (edition 2021)
- Go 1.21+ (for compiling the Coraza WAF engine)
- C compiler (gcc/clang on Unix, MSVC on Windows)
- libclang (for bindgen)
On Ubuntu/Debian:
On macOS:
Building
The first build compiles the Go WAF engine into a static library and generates Rust FFI bindings. Subsequent builds are fast.
Examples
simple_get
Minimal WAF usage with DetectionOnly mode — processes a GET request and checks for interventions.
deny_rule
WAF with a deny rule that blocks requests from specific IPs — demonstrates handling a 403 intervention.
with_callbacks
Registers debug log and error callbacks — shows how to capture matched rule details.
API Overview
Configuration
use ;
let waf = new?
.with_directives
.with_directives
.with_debug_log_callback
.with_error_callback
.build?;
Transaction Processing
Transactions follow Coraza's phase-based lifecycle:
let mut tx = waf.new_transaction;
// Phase 0: Connection & URI
tx.process_connection?;
tx.process_uri?;
// Phase 1: Request headers
tx.add_request_header;
tx.process_request_headers?; // may return Err(Intervention)
// Phase 2: Request body (if SecRequestBodyAccess On)
tx.append_request_body?;
tx.process_request_body?;
// Phase 3: Response headers
tx.process_response_headers?;
// Phase 4: Response body (if SecResponseBodyAccess On)
tx.append_response_body?;
tx.process_response_body?;
// Phase 5: Logging (always run, even on interruption)
tx.process_logging;
// Check for rule matches
if let Some = tx.intervention
Thread Safety
| Type | Send |
Sync |
Notes |
|---|---|---|---|
Waf |
Yes | Yes | Immutable after creation; safe to share for concurrent transaction creation |
WafConfig |
Yes | No | Builder consumed by build() |
Transaction |
Yes | No | Mutable state; must not be shared across threads |
License
Licensed under the Apache License, Version 2.0.