corazawaf / coraza-spoa

EXPERIMENTAL: A wrapper around the OWASP Coraza WAF for HAProxy's SPOE filters
Apache License 2.0
74 stars 16 forks source link

Multiple domains - backend #92

Closed thelogh closed 9 months ago

thelogh commented 10 months ago

I have multiple virtuals host on haproxy. I wanted to know which is the right way to configure coraza-spoa with different configurations based on the backend or domain. To activate or deactivate the waf or activate only some rules. I created multiple apps in the configuration file /etc/coraza-spoa/config.yaml, and tested the app name in /etc/haproxy/coraza.cfg args app=str(appname). What is the right procedure? Do you have a configuration example that can help me?

zc-devs commented 10 months ago

If you process only requests, then it's easy:

# /etc/haproxy/coraza.conf
spoe-message coraza-req
    args app=req.hdr(host) id=unique-id ...
# /etc/coraza-spoa/spoa.yaml
applications:
  dom1.example.com:
    rules:
      ...
  dom2.example.com:
    rules:
      ...

If you would like to process responses as well, then you have to save host in transaction variable:

# /etc/haproxy/haproxy.cfg
frontend https_front
    ...
    http-request   set-var(txn.app_name) req.hdr(host)
    ...

and use it in response processing:

# /etc/haproxy/coraza.conf
spoe-message coraza-res
    args app=var(txn.app_name) id=unique-id ...
thelogh commented 9 months ago

Thanks, everything works fine

thelogh commented 9 months ago

If it's helpful, I've written a short guide https://www.alldiscoveries.com/multidomain-installation-and-configuration-of-haproxy-with-waf-coraza-spoa-and-owasp-modsecurity-core-rule-set-4-0-wordpress-rule-exclusions-on-ubuntu-server-22-04-lts/