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

how to tell coraza not to buffer responses? #148

Open
dkhokhlov opened this issue May 12, 2024 · 7 comments
Open

how to tell coraza not to buffer responses? #148

dkhokhlov opened this issue May 12, 2024 · 7 comments

Comments

@dkhokhlov
Copy link

dkhokhlov commented May 12, 2024

I am using caddy as https reverse proxy with coraza. my app streams response. w/o coraza I see page rendered gradually. with coraza I get whole page after delay. Even with empty coraza config it is still buffering.

how to tell coraza not to buffer responses?

myhost:1443 {
    tls /etc/caddy/my.crt /etc/caddy/my.key
    reverse_proxy localhost:8080
    header Access-Control-Allow-Methods "POST, GET, OPTIONS"
    header Access-Control-Allow-Headers "*"
    encode zstd gzip
    log {
        level  DEBUG
    }
  coraza_waf {
    directives `
      Include /etc/caddy/coraza-coreruleset/rules/@coraza.conf-recommended
      Include /etc/caddy/coraza-coreruleset/rules/@crs-setup.conf.example
      Include /etc/caddy/coraza-coreruleset/rules/@owasp_crs/*.conf
      SecRuleEngine On
      SecDebugLog /dev/stdout
      SecDebugLogLevel 9
      SecRule REQUEST_URI "@streq /admin" "id:101,phase:1,t:lowercase,deny,status:403"
      SecRule REQUEST_BODY "@rx maliciouspayload" "id:102,phase:2,t:lowercase,deny,status:403"
    `
  }
}
@dkhokhlov dkhokhlov changed the title how to tell coraza not buffer response? how to tell coraza not to buffer responses? May 12, 2024
@jptosso
Copy link
Member

jptosso commented May 12, 2024

Unfortunately it's impossible to process the request with blocking capabilities without buffering.
Modsecurity tried a streaming mode but it never really worked, the same applies for coraza.
Also CRS breaks if we stops processing request body phase

@dkhokhlov
Copy link
Author

dkhokhlov commented May 12, 2024

double checking - you are talking about response? buffering a request and then processing its body etc is ok. but buffering corresponding response from the server is the problem.

@jptosso
Copy link
Member

jptosso commented May 12, 2024

Same applies for responses, but it might not affect CRS unless you enable anomaly scoring mode. I think it wouldn't damage to allow users to stream the response body. We could even use an action to tell the connector to stream

@jcchavezs @fzipi

@jcchavezs
Copy link
Member

jcchavezs commented May 12, 2024 via email

@agclark27
Copy link

We're finding that even if we include the directive SecResponseBodyAccess Off the response is still buffered. We're fine with buffering the requests, but we'd prefer not to buffer the responses if we're disabling response body access anyway. Is there another way to disable response buffering while keeping Coraza in the pipeline?

@jcchavezs
Copy link
Member

If that is the case then that might be a bug. According to https://github.com/corazawaf/coraza-caddy/blob/main/interceptor.go#L118-L120 it should not be buffered. Any chance caddy does the buffering? cc @mholt

@mholt
Copy link

mholt commented Oct 3, 2024

Caddy does not buffer responses unless there is special processing required -- this usually requires explicit configuration (for example, the templates middleware requires a buffered response body so it can evaluate the template).

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

5 participants