You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
modsecurity "failing open" with a large number of requests #3
Looks like if an SPOP request to modsecurity exceeds the timeout processing, the request will be allowed to proceed. Is there some way of configuring HAProxy to "fail closed" when it encounters a timeout?
Here's an example of the behavior. I sent 300 requests, 100 at a time to an haproxy server. This server is using spoa-modsecurity with timeout processing 1s set:
Note how 17 requests took slightly longer than 1 second to process, but instead of being denied (403) by modsecurity for trying to access /etc/passwd, the requests went through (200).
This might be a separate issue, but the request distribution also looks suspicious. I'd expect to have a long tail of requests between 0.2 and 1.0 seconds, but instead it's a sharp cliff. Maybe there's some other limit being hit here which causes modsecurity to lock up? I'm running modsecurity with "-n 16" worker threads on a VM with 4 CPUs, for context.
http-request deny if { var(txn.modsec.code) -m int gt 0 }
When a timeout is hit, txn.modsec.code stays uninitialized as -1, which mean the request is NOT denied.
It's debatable whether the readme should be changed to change the "fail open" to "fail closed", but if you do want to do that, use this conditional instead:
http-request deny unless { var(txn.modsec.code) -m int eq 0 }
EDIT: See comment below, don't use the above workaround since it doesn't work
This seems to be related to this issue because I'm not sure what the value of txn.modsec.code should be on success. In my testing it appears that txn.modsec.code is 403 when modsec denies the request and on success, it's -1, but does -1 always imply success? Seems there are some code paths where -1 also implies an error with spoa-modsecurity like here.
So I'm having trouble constructing a conditional that fails-closed for all error states, but allows the request for all other cases.
Activity
mac-chaffee commentedon Oct 24, 2022
The issue appears to be the conditional which is mentioned in the readme:
spoa-modsecurity/README
Line 97 in 3c895f3
When a timeout is hit,
txn.modsec.codestays uninitialized as-1, which mean the request is NOT denied.It's debatable whether the readme should be changed to change the "fail open" to "fail closed", but if you do want to do that, use this conditional instead:
EDIT: See comment below, don't use the above workaround since it doesn't work
mac-chaffee commentedon Nov 16, 2022
It seems that the return code from modsecurity is a signed integer:
spoa-modsecurity/spoa.c
Line 93 in 3c895f3
But when encoded via SPOP, it's treated as a uint64_t:
spoa-modsecurity/include/haproxy/intops.h
Line 399 in 3c895f3
This seems to be related to this issue because I'm not sure what the value of
txn.modsec.codeshould be on success. In my testing it appears thattxn.modsec.codeis 403 when modsec denies the request and on success, it's-1, but does -1 always imply success? Seems there are some code paths where -1 also implies an error with spoa-modsecurity like here.So I'm having trouble constructing a conditional that fails-closed for all error states, but allows the request for all other cases.