fix(waf): fail closed when Coraza inspection fails - #168
Merged
Conversation
bihius
force-pushed
the
fix/coraza-degraded-mode
branch
from
April 26, 2026 08:47
4f9feeb to
71f272f
Compare
bihius
marked this pull request as ready for review
April 26, 2026 08:49
There was a problem hiding this comment.
Pull request overview
Implements an explicit degraded-mode strategy in the HAProxy ↔ Coraza SPOE reference config: when SPOE/WAF inspection errors occur, HAProxy now fails closed with a 503 and adds operator-facing response signals, with accompanying documentation and regression tests.
Changes:
- Update HAProxy reference config to fail closed (
503) whentxn.coraza.erroris present, addX-WAF-Degraded/X-WAF-Error, and raise log level toerr. - Update SPOE agent config comments and HAProxy README to document degraded-mode behaviour and troubleshooting expectations.
- Extend unit regression tests to assert the degraded-mode behaviour is present in the reference config/docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/backend/tests/unit/test_waf_debug_reference_config.py |
Adds regression assertions for fail-closed degraded mode and documents expectations in tests. |
configs/haproxy/haproxy.cfg |
Adds fail-closed handling for txn.coraza.error, including response headers and err log level. |
configs/haproxy/coraza.cfg |
Updates comments to reflect the new fail-closed behaviour when SPOE errors occur. |
configs/haproxy/README.md |
Documents degraded-mode semantics, observability signals, and troubleshooting guidance. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
7 tasks
Copilot AI
added a commit
that referenced
this pull request
Apr 26, 2026
The test `test_reference_haproxy_config_fails_closed_on_spoe_errors` was asserting an exact full-line string including quoted header names/values. The reference `configs/haproxy/haproxy.cfg` uses unquoted header tokens and also includes `content-type text/plain string` which caused the assertion to fail. Apply PR #168 changes (haproxy.cfg fail-closed SPOE error handling, coraza.cfg comment update, README degraded-mode section) and replace the brittle exact-line assertion with semantic checks: - locate the `http-request return status 503` line - verify both X-WAF-Degraded and X-WAF-Error headers appear on that line (tolerating quoted or unquoted forms) - verify the `if { var(txn.coraza.error) -m found }` condition is present Closes the CI failure in PR #168. Agent-Logs-Url: https://github.com/bihius/guard-proxy/sessions/cfcb5738-a176-45f4-b37c-8c9207680170 Co-authored-by: bihius <119067436+bihius@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
503 Service Unavailablewhen HAProxy sees a Coraza/SPOE processing error.X-WAF-DegradedandX-WAF-Error.errlog level before backend routing.Closes #80
Validation
uv run pytest --cov=appuv run mypy app/uv run ruff check app/ tests/unit/test_waf_debug_reference_config.pypnpm run type-checkpnpm run lintdocker run --rm -v "$PWD/configs/haproxy:/usr/local/etc/haproxy:ro" haproxy:3.0-alpine haproxy -c -f /usr/local/etc/haproxy/haproxy.cfgNotes
fix/spoe-debugging. After feat(debug): make HAProxy and Coraza SPOE troubleshooting more verbose #167 merges, this branch should be retargeted tomain.