Skip to content
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

Unable to remove Server header on Coraza module's response #144

Closed
to-kr opened this issue Apr 8, 2024 · 8 comments
Closed

Unable to remove Server header on Coraza module's response #144

to-kr opened this issue Apr 8, 2024 · 8 comments

Comments

@to-kr
Copy link

to-kr commented Apr 8, 2024

I'm currently using Caddy server with the coraza module for web application firewall (WAF) capabilities. I've configured Caddy to remove the Server header using the header directive, but it seems that the Server header persists when the coraza module returns a 403 Forbidden response.

image

Caddyfile:

{
    http_port 8080
    order coraza_waf first
}

:8080 {
    header {
        -Server
        -Alt-Svc
    }

    handle {
        respond 404
    }
        
    coraza_waf {
        load_owasp_crs
        directives `
            Include /etc/caddy/*.conf
            Include @coraza.conf-recommended
            Include @crs-setup.conf.example
            Include @owasp_crs/*.conf

            SecRuleEngine On
        `
    }
}

Steps to Reproduce:

  1. Start Caddy server with the provided Caddyfile configuration.
  2. Send a request that triggers a 403 Forbidden response from the coraza module.
curl -v "http://127.0.0.1:8080?id=1;DELETE%20FROM"
  1. Check the response headers and observe that the Server header is still present.

Expected Behavior:
The Server header should be removed from the response when the coraza module returns a 403 Forbidden response, as specified in the Caddyfile configuration.

Actual Behavior:
The Server header persists in the response even after configuring Caddy to remove it.

Additional Information:

  • Caddy version: 2.7.6
  • Coraza module version: v2.0.0-rc.3
@to-kr to-kr changed the title Unable to Remove Server Header on Coraza Module's Response Unable to remove Server header on Coraza module's response Apr 8, 2024
@jcchavezs
Copy link
Member

jcchavezs commented Apr 8, 2024 via email

@to-kr
Copy link
Author

to-kr commented Apr 9, 2024

It returns 404 without Server header.

image

@jcchavezs
Copy link
Member

Could it be the case that the middleware that removes server header happens after coraza does its job? cc @mholt

@mholt
Copy link

mholt commented Jul 10, 2024

Yeah. order coraza_waf first causes it to be executed before any other directives, which is probably not what you want. If coraza_waf terminates the handler chain (i.e. responds to the request), the header directive won't even be evaluated.

@zdeneksvarc
Copy link

We can configure WAF header from handle_errors 403 { … } like this:

{
        admin off
        auto_https off
        order coraza_waf first
}

:80 {
        coraza_waf {
                load_owasp_crs
                directives `
                Include @coraza.conf-recommended
                Include @crs-setup.conf.example
                Include @owasp_crs/*.conf
                SecRuleEngine On
                `
        }

        header {
                -Server
        }

        handle_errors 403 {
               header X-Blocked "true"
               header Server "WAF"
#              header -Server
        }

        reverse_proxy http://whoami:2001
}

Returns:

HTTP/1.1 403 Forbidden
Server: WAF
X-Blocked: true
Date: Mon, 30 Sep 2024 12:42:35 GMT

and

HTTP/1.1 200 OK
Content-Length: 269
Content-Type: text/plain; charset=utf-8
Date: Mon, 30 Sep 2024 12:42:36 GMT

@to-kr
Copy link
Author

to-kr commented Oct 2, 2024

Thank You. It works.

@jcchavezs
Copy link
Member

jcchavezs commented Oct 2, 2024 via email

@to-kr
Copy link
Author

to-kr commented Oct 2, 2024

Yes, handle_errors solves the problem

@to-kr to-kr closed this as completed Oct 2, 2024
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

No branches or pull requests

4 participants