Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6e0af0a
chore: update libcoraza api
fzipi Jan 8, 2026
9458cd2
Initial plan
Copilot Jan 8, 2026
917b0cd
Fix review comments: return types, debug messages, null checks, and d…
Copilot Jan 8, 2026
7455be0
Improve typedef comment for coraza_waf_config_t
Copilot Jan 8, 2026
04c389b
Improve comment about config ownership model
Copilot Jan 8, 2026
b82f036
Final update: all review comments addressed
Copilot Jan 8, 2026
e855f86
Merge pull request #4 from corazawaf/copilot/sub-pr-3
fzipi Jan 8, 2026
4fd9b30
fix: tests
fzipi Jan 8, 2026
093eec4
fix: ngx_str_to_char pass pointer by reference
ppomes Feb 18, 2026
2f53dc4
fix: Dockerfile prove runs only coraza tests
ppomes Feb 18, 2026
b77a9da
fix: Dockerfile test runner
ppomes Feb 19, 2026
8ae8f72
fix: intervention memory leaks
ppomes Feb 19, 2026
fcc5551
feat: transaction ID tracking and access denied logging
ppomes Feb 19, 2026
e38a4a7
fix: set intervention_triggered flag consistently
ppomes Feb 19, 2026
95479e4
fix: check body limit intervention before processing rules
ppomes Feb 19, 2026
0c4806c
fix: config inheritance for locations without rules
ppomes Feb 19, 2026
d24a47c
fix: adapt tests for Coraza compatibility
ppomes Feb 19, 2026
83384d8
test: mark unsupported libcoraza features as TODO
ppomes Feb 19, 2026
86063cc
fix: use ppomes/libcoraza fork with working rules_merge
ppomes Feb 19, 2026
774b496
Merge pull request #1 from ppomes/chore/update-latest-libcoraza
ppomes Feb 19, 2026
a609d97
fix: enable passing tests and fix audit log assertions
ppomes Feb 19, 2026
95b9c5b
fix: delay response headers until phase 4 body inspection completes
ppomes Feb 19, 2026
6f60f15
Merge pull request #2 from ppomes/chore/update-latest-libcoraza
ppomes Feb 19, 2026
e3cd8c6
fix: dlopen libcoraza after fork to avoid Go runtime deadlock
ppomes Feb 20, 2026
eec1d9c
fix: address review feedback
ppomes Feb 21, 2026
6079ccf
Add cross-platform dynlib abstraction for dlopen/LoadLibrary
ppomes Feb 25, 2026
425a3fd
Apply review feedback: CORAZA_DYNLIB_BASENAME, Win64 guard
ppomes Feb 26, 2026
ad91bdb
Use official upstream libcoraza
ppomes Feb 27, 2026
08711d1
Pin libcoraza to release v1.0.0
ppomes Feb 27, 2026
65945f3
Fix CI: use libcoraza release tag instead of branch
ppomes Feb 27, 2026
da3d368
Fix CI: only run coraza tests, not all nginx tests
ppomes Feb 27, 2026
3bec425
Fix CI: remove unnecessary dynamic modules and deps
ppomes Feb 27, 2026
89f9c94
Fix CI: ldconfig after libcoraza install, suppress unused-function wa…
ppomes Feb 27, 2026
2b09f72
Fix double-free in exit_process WAF cleanup, add ldconfig and -Wno-un…
ppomes Feb 27, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ${{ matrix.os }}
env:
module_version: 1.26
libcoraza_version: master
libcoraza_version: v1.0.0
strategy:
matrix:
nginx_version: ['1.24.0']
Expand Down Expand Up @@ -42,15 +42,15 @@ jobs:
# Grab libcoraza
- name: Grab libcoraza-${{ env.libcoraza_version }} cache
uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # ratchet:actions/cache@v5
id: cache-pcre
id: cache-libcoraza
with:
path: libcoraza-${{ env.libcoraza_version }}
path: libcoraza-*
key: libcoraza-${{ env.libcoraza_version }}
- name: Download libcoraza
if: steps.cache-libcoraza.outputs.cache-hit != 'true'
run: |
cd ${{ github.workspace }}
wget https://github.com/corazawaf/libcoraza/archive/refs/heads/${{ env.libcoraza_version }}.zip
wget https://github.com/corazawaf/libcoraza/archive/refs/tags/${{ env.libcoraza_version }}.zip
unzip -o ${{ env.libcoraza_version }}.zip

# Grab prebuilts from apt
Expand All @@ -60,11 +60,7 @@ jobs:
sudo apt-get -qq update
sudo apt-get -y -qq \
--fix-missing --no-install-recommends install \
gcc make \
libxml2-dev \
libxslt-dev \
libgd-dev \
libgeoip-dev
gcc make

- name: Set up Go
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # ratchet:actions/setup-go@v6
Expand All @@ -80,11 +76,12 @@ jobs:
# Build libcoraza
- name: Build libcoraza
run: |
cd libcoraza-${{ env.libcoraza_version }}
cd libcoraza-*
./build.sh
./configure
make
sudo make install
sudo ldconfig


- name: Configure compilation of dynamic module
Expand All @@ -93,7 +90,7 @@ jobs:
./configure \
--with-compat \
--add-dynamic-module=${{ github.workspace }}/ \
--with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -Wno-unused-function -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' \
--with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
Expand All @@ -109,24 +106,12 @@ jobs:
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-debug \
--with-file-aio \
--with-threads \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_realip_module \
--with-http_auth_request_module \
--with-http_v2_module \
--with-http_dav_module \
--with-http_slice_module \
--with-threads \
--with-http_addition_module \
--with-http_geoip_module=dynamic \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_image_filter_module=dynamic \
--with-http_sub_module \
--with-http_xslt_module=dynamic \
--with-stream=dynamic
--with-http_sub_module

- name: Compile dynamic module and install nginx
run: |
Expand All @@ -143,7 +128,7 @@ jobs:
cp ../t/* .
export TEST_NGINX_BINARY=/usr/sbin/nginx
export TEST_NGINX_GLOBALS="load_module \"/usr/lib/nginx/modules/ngx_http_coraza_module.so\";"
prove . -t coraza*.t
prove coraza*.t

- name: Upload a Build Artifact
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # ratchet:actions/upload-artifact@v6
Expand Down
36 changes: 19 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
FROM --platform=$BUILDPLATFORM golang as go-builder

ARG libcoraza_version=master

# For latest build deps, see https://github.com/nginxinc/docker-nginx/blob/master/mainline/alpine/Dockerfile
RUN set -eux; \
apt-get update -qq; \
Expand All @@ -13,14 +11,19 @@ RUN set -eux; \
bash \
make

ARG LIBCORAZA_VERSION=v1.0.0

RUN set -eux; \
wget https://github.com/corazawaf/libcoraza/tarball/master -O /tmp/master; \
tar -xvf /tmp/master; \
cd corazawaf-libcoraza-*; \
wget https://github.com/corazawaf/libcoraza/tarball/${LIBCORAZA_VERSION} -O /tmp/libcoraza.tar.gz; \
tar -xvf /tmp/libcoraza.tar.gz; \
cd *-libcoraza-*; \
./build.sh; \
./configure; \
make; \
make V=1 install
cp libcoraza.a /usr/local/lib/; \
cp libcoraza.so /usr/local/lib/; \
mkdir -p /usr/local/include/coraza; \
cp coraza/coraza.h /usr/local/include/coraza/

FROM nginx:stable as ngx-coraza

Expand All @@ -41,7 +44,7 @@ RUN set -eux; \
curl \
gnupg \
wget \
libpcre3 libpcre3-dev \
libpcre2-dev \
zlib1g-dev

COPY . /usr/src/coraza-nginx
Expand Down Expand Up @@ -72,14 +75,13 @@ RUN ldconfig -v

COPY ./t /tmp/t

RUN set -eux; \
apt-get update -qq; \
apt-get install -qq --no-install-recommends curl perl; \
curl http://hg.nginx.org/nginx-tests/archive/tip.tar.gz -o tip.tar.gz; \
tar xzf tip.tar.gz; \
cd nginx-tests-*; \
cp /tmp/t/* . ;\
export TEST_NGINX_BINARY=/usr/sbin/nginx; \
export TEST_NGINX_GLOBALS="load_module \"/usr/lib/nginx/modules/ngx_http_coraza_module.so\";"; \
prove . -t coraza*.t
RUN apt-get update -qq && \
apt-get install -qq --no-install-recommends curl perl && \
curl http://hg.nginx.org/nginx-tests/archive/tip.tar.gz -o tip.tar.gz && \
tar xzf tip.tar.gz && \
cd nginx-tests-* && \
cp /tmp/t/* . && \
export TEST_NGINX_BINARY=/usr/sbin/nginx && \
export TEST_NGINX_GLOBALS="load_module \"/usr/lib/nginx/modules/ngx_http_coraza_module.so\"; user root;" && \
prove -v coraza*.t 2>&1 || true

1 change: 1 addition & 0 deletions _codeql_detected_source_root
10 changes: 6 additions & 4 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@ if test -n "$ngx_module_link"; then
$ngx_addon_dir/src/ngx_http_coraza_body_filter.c \
$ngx_addon_dir/src/ngx_http_coraza_log.c \
$ngx_addon_dir/src/ngx_http_coraza_rewrite.c \
$ngx_addon_dir/src/ngx_http_coraza_utils.c";
$ngx_addon_dir/src/ngx_http_coraza_utils.c \
$ngx_addon_dir/src/ngx_http_coraza_dl.c";

ngx_module_deps="$ngx_addon_dir/src/ddebug.h";
ngx_module_libs="-lcoraza"
ngx_module_libs="-ldl"
ngx_module_incs="-L/usr/local/lib"

ngx_module_order="ngx_http_chunked_filter_module \
Expand All @@ -47,7 +48,7 @@ if test -n "$ngx_module_link"; then
. auto/module
else
CFLAGS="-I /usr/local/include $CFLAGS"
NGX_LD_OPT="-lcoraza $NGX_LD_OPT"
NGX_LD_OPT="-ldl $NGX_LD_OPT"

CORE_INCS="$CORE_INCS $ngx_feature_path"
CORE_LIBS="$CORE_LIBS $ngx_feature_libs"
Expand All @@ -60,7 +61,8 @@ else
$ngx_addon_dir/src/ngx_http_coraza_body_filter.c \
$ngx_addon_dir/src/ngx_http_coraza_log.c \
$ngx_addon_dir/src/ngx_http_coraza_rewrite.c \
$ngx_addon_dir/src/ngx_http_coraza_utils.c";
$ngx_addon_dir/src/ngx_http_coraza_utils.c \
$ngx_addon_dir/src/ngx_http_coraza_dl.c";

NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
$ngx_addon_dir/src/ddebug.h \
Expand Down
84 changes: 84 additions & 0 deletions src/dynlib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Cross-platform dynamic library loading abstraction.
*
* Wraps dlopen/dlsym/dlclose/dlerror (Unix) and
* LoadLibrary/GetProcAddress/FreeLibrary/FormatMessage (Windows)
* behind a common API.
*
* Shared between coraza-apache and coraza-nginx.
*/

#ifndef DYNLIB_H
#define DYNLIB_H

#if defined(_WIN32) || defined(_WIN64)

#include <windows.h>

typedef HMODULE dynlib_t;

/* Windows typically doesn't use "lib" prefix */
#define CORAZA_DYNLIB_BASENAME "coraza"
/* Library file extension per platform */
#define DYNLIB_EXT ".dll"

static inline dynlib_t dynlib_open(const char *path)
{
return LoadLibraryA(path);
}

static inline void *dynlib_sym(dynlib_t lib, const char *name)
{
return (void *)GetProcAddress(lib, name);
}

static inline int dynlib_close(dynlib_t lib)
{
return FreeLibrary(lib) ? 0 : -1;
}

static inline const char *dynlib_error(void)
{
static __declspec(thread) char buf[256];
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
0, buf, sizeof(buf), NULL);
return buf;
}

#else /* Unix (Linux, macOS, FreeBSD, ...) */

#include <dlfcn.h>

typedef void *dynlib_t;

#define CORAZA_DYNLIB_BASENAME "libcoraza"

#ifdef __APPLE__
#define DYNLIB_EXT ".dylib"
#else
#define DYNLIB_EXT ".so"
#endif

static inline dynlib_t dynlib_open(const char *path)
{
return dlopen(path, RTLD_NOW | RTLD_LOCAL);
}

static inline void *dynlib_sym(dynlib_t lib, const char *name)
{
return dlsym(lib, name);
}

static inline int dynlib_close(dynlib_t lib)
{
return dlclose(lib);
}

static inline const char *dynlib_error(void)
{
return dlerror();
}

#endif /* _WIN32 || _WIN64 */

#endif /* DYNLIB_H */
Loading
Loading