Skip to content

Feature/hostname logging v5 #209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

stardothosting
Copy link

@stardothosting stardothosting commented Apr 14, 2025

Add unique_id and improve hostname logging in WAF violation logs

Background

This PR addresses part of issue #75 where hostname information is missing or empty in WAF logs. While the core issue of empty [hostname ""] in Coraza logs remains to be solved at a deeper level, this PR improves log correlation by:

  1. Adding the hostname from the request to our custom WAF violation logs
  2. Including the unique_id to link these logs with the detailed Coraza logs

This allows operators to correlate WAF events across multiple domains/hostnames until the core hostname logging issue is resolved in Coraza.

Changes

  • Added hostname extraction from request to WAF violation logs
  • Added unique_id extraction from matched rules
  • Improved log correlation between detailed Coraza logs and summary logs

Example Log Output

{
"level": "error",
"logger": "http.handlers.waf",
"msg": "WAF rule violation detected",
"hostname": "example.com",
"uri": "/?s=../../etc/passwd",
"client_ip": "10.0.0.1:12345",
"unique_id": "TJDwCHtXQPLaaQFhqry"
}

Testing Done

  • Tested with path traversal attacks
  • Verified unique_id correlation with detailed Coraza logs
  • Confirmed hostname logging works correctly
  • Verified logs can be correlated across multiple domains

Related Issues

Copy link

tx.ProcessLogging()
_ = tx.Close()
}()
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
repl.Set("http.transaction_id", id)
repl.Set("http.transaction_id", "")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this needed?

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