coraza 0.1.0

Safe Rust bindings to OWASP Coraza WAF
/*
 * Copyright 2022 OWASP Coraza contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Allow naming convention violations from bindgen-generated constants
#![allow(non_upper_case_globals)]

//! # coraza
//!
//! Safe Rust bindings to [OWASP Coraza](https://coraza.io/) Web Application Firewall.
//!
//! Coraza is a Go-based WAF that can be embedded via FFI. This crate provides
//! a safe, idiomatic Rust API over the raw `coraza-sys` bindings.
//!
//! ## Quick Start
//!
//! ```no_run
//! use coraza::{WafConfig, Error};
//!
//! fn main() -> Result<(), Error> {
//!     let waf = WafConfig::new()?
//!         .with_directives("SecRuleEngine DetectionOnly")
//!         .build()?;
//!
//!     let mut tx = waf.new_transaction();
//!
//!     // Phase 0: Connection & URI
//!     tx.process_connection("127.0.0.1", 8080, "localhost", 80)?;
//!     tx.process_uri("/path", "GET", "HTTP/1.1")?;
//!
//!     // Phase 1: Request headers
//!     tx.add_request_header("Host", "localhost");
//!     tx.process_request_headers()?;
//!
//!     // Phase 5: Logging
//!     tx.process_logging();
//!
//!     // Check for interventions
//!     if let Some(intervention) = tx.intervention() {
//!         eprintln!("Blocked with status {}", intervention.status);
//!     }
//!
//!     Ok(())
//! }
//! ```
//!
//! ## Configuration
//!
//! Use [`WafConfig`] to build a WAF with SecLang directives:
//!
//! ```no_run
//! use coraza::{WafConfig, LogLevel};
//!
//! let waf = WafConfig::new()
//!     .unwrap()
//!     .with_directives("SecRuleEngine On")
//!     .with_directives("SecRequestBodyAccess On")
//!     .with_directives("SecResponseBodyAccess On")
//!     .with_debug_log_callback(|level, msg, fields| {
//!         eprintln!("[{level}] {msg} {fields}");
//!     })
//!     .with_error_callback(|rule| {
//!         eprintln!("Rule {} matched: {}", rule.rule_id, rule.message);
//!     })
//!     .build()
//!     .unwrap();
//! ```
//!
//! ## Error Handling
//!
//! All fallible operations return [`Result<T, Error>`](Result). The [`Error`]
//! enum provides specific variants for different failure modes:
//!
//! - [`Error::WafCreation`] — WAF compilation failed (bad rules)
//! - [`Error::Intervention`] — a rule matched and interrupted the request
//! - [`Error::InvalidTransaction`] — the transaction was closed or invalid
//! - [`Error::BodyOperation`] — body read/write failed
//! - [`Error::RuleEngineError`] — internal rule engine error
//!
//! ## Thread Safety
//!
//! - [`Waf`], [`WafConfig`], and [`Transaction`] are all `Send` — they can be sent between threads.
//! - [`Waf`] is `Sync` — it can be shared between threads.
//! - [`Transaction`] is `!Sync` — it must stay on the same thread.
//! - [`WafConfig`] is `!Sync` — configuration is single-threaded.

mod callbacks;
mod error;
mod intervention;
mod matched_rule;
mod transaction;
mod waf;

pub use error::Error;
pub use intervention::Intervention;
pub use matched_rule::{LogLevel, MatchedRule, Severity};
pub use transaction::Transaction;
pub use waf::{Waf, WafConfig};