Skip to content

fix: log resolved client_ip in WAF violation log (supersedes #306, adds tests) - #321

Open
boecks wants to merge 2 commits into
corazawaf:mainfrom
boecks:fix/violation-log-client-ip
Open

fix: log resolved client_ip in WAF violation log (supersedes #306, adds tests)#321
boecks wants to merge 2 commits into
corazawaf:mainfrom
boecks:fix/violation-log-client-ip

Conversation

@boecks

@boecks boecks commented Jul 13, 2026

Copy link
Copy Markdown

This carries the one-line fix from #306 unchanged — original commit by @thelogh, authorship preserved via cherry-pick — rebased onto current main, plus the end-to-end regression test requested in the #306 review: a request arriving through a trusted proxy with X-Forwarded-For triggers a deny rule, and the test asserts the WAF rule violation detected log entry reports the forwarded client IP rather than the proxy's RemoteAddr. The test fails without the fix and passes with it.

Context: @thelogh did write tests in response to the review, but they were opened as thelogh#1 against his own fork's main rather than the patch-1 branch backing #306, so they never surfaced there and #306 has been stalled since early June. Not trying to take anything over — if @thelogh updates patch-1 instead, happy to close this one.

Field report: we've been running this exact fix in production since mid-June (fork pin in an xcaddy build) on a public-facing Caddy edge with Coraza + OWASP CRS in front of ~14 vhosts, alongside CrowdSec log ingestion that consumes these violation logs — the corrected client_ip is what makes those logs actionable for banning. No regressions observed; we'd love to retire the fork.

Summary by CodeRabbit

  • Bug Fixes

    • Corrected WAF violation logs to record the originating client IP from forwarded request headers when trusted proxies are configured.
    • Improved accuracy of logged client and request details for denied requests.
  • Tests

    • Added regression coverage verifying client IP and request URI values in violation logs.

thelogh and others added 2 commits July 13, 2026 16:35
In addition to the pull request https://github.com/corazawaf/coraza-caddy/pull/184/changes for setting the correct client_ip IP via getClientAddress, the generation of the error log with the correct IP has been left out of the change.
End-to-end regression test for the client_ip fix: a request through a
trusted proxy with X-Forwarded-For triggers a deny rule; the emitted
'WAF rule violation detected' log entry must report the forwarded
client IP, not the proxy's RemoteAddr. Fails without the fix.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Changes

Client IP violation logging

Layer / File(s) Summary
Violation logging and regression test
coraza.go, coraza_test.go
Violation logs use getClientAddress(r) for client_ip; an integration test verifies the X-Forwarded-For address and /denyme URI in the JSON log.
Estimated code review effort: 2 (Simple) ~10 minutes
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: logging the resolved client_ip in WAF violation logs and adding tests.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants