1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*
* 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
//! # 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.
pub use Error;
pub use Intervention;
pub use ;
pub use Transaction;
pub use ;