Welcome to libcoraza, the C library for OWASP Coraza Web Application Firewall. Because Coraza was made in Go, if you want to embed it in any kind of C application, you will need this library.
- A C compiler:
- gcc or
- clang
- Go compiler v1.25+
- libtool
- autotools
- make
Download the library source:
git clone https://github.com/corazawaf/libcoraza libcoraza
Build the source:
cd libcoraza
./build.sh
./configure
make
sudo make install
Run the full test suite (Go tests with race detection + C test validation):
make check
If you want to compile the library from a different branch/commit than main or HEAD, or want to make a package offline, get the code and use it as vendor:
go get -u github.com/corazawaf/coraza/v3@HASH-ID
go mod vendor
go mod tidy
./build.sh
./configure
make
If you didn't install the built library (skipped the sudo make install step), set the library path before running your application:
# Linux
export LD_LIBRARY_PATH=../:$LD_LIBRARY_PATH
# macOS
export DYLD_LIBRARY_PATH=../:$DYLD_LIBRARY_PATH
libcoraza ships a SWIG interface file (coraza.i) that allows
generating bindings for a wide range of languages including Python, Ruby, Java, PHP,
Perl, and many others.
- SWIG 4.0 or later
Install on Debian/Ubuntu:
sudo apt install swig
Install on macOS (Homebrew):
brew install swig
The examples/ directory contains fully working examples with their own Makefiles:
# Python
make -C examples/python # build
make -C examples/python run # build and run
# Java (requires JAVA_HOME to be set)
make -C examples/java # build
make -C examples/java run # build and run
Each example exercises the full API including error and debug log callbacks.
First build the library:
./build.sh
./configure
make
Then invoke SWIG directly against coraza.i:
# Ruby example
swig -ruby -o coraza_wrap.c coraza.i
gcc -shared -fPIC coraza_wrap.c $(ruby -rrbconfig -e 'puts RbConfig::CONFIG["CFLAGS"]') \
-L. -lcoraza -o coraza.so
- Callbacks —
coraza_set_error_callbackandcoraza_set_debug_log_callbackare provided as language-specific trampolines for Python and Java (seecoraza.iand the example directories). For other languages, refer to the SWIG documentation on%callbackor director classes. coraza_matched_rule_get_error_logreturns a string owned by the caller. The generated wrapper takes ownership automatically so the target language runtime frees it when the object is garbage collected.