Skip to content

ModSecurity performance cost on cPanel — rules vs response time

ModSecurity inspects every request. With the wrong rule set or no exclusions, it adds measurable latency to every PHP page render. Here is how to measure and trim it.

ModSecurity is the open-source WAF that cPanel integrates with Apache and LiteSpeed. It is a real security tool — well-configured ModSec blocks SQL injection, XSS, path traversal, and many bot attacks. It is also a real performance tax — every request goes through dozens to thousands of rule evaluations before the application sees it. On a busy cPanel host with the OWASP Core Rule Set fully enabled and no exclusions, ModSec can add 50-200 ms to every PHP page render. The trade-off is real, and most teams have not measured their side of it.

What’s happening

ModSec evaluates rules in phases: request headers, request body, response headers, response body, and logging. Each rule is a regex (often heavy) or a Lua script. The OWASP CRS ships with 500+ rules. Each rule runs against the relevant phase data. With paranoia level 1 (default), most are short-circuit checks. At paranoia level 2 or 3, dozens of rules run per request, and some scan the full request body.

The classic offender: a SecRule REQUEST_BODY that scans the entire POST payload with a regex. For a WordPress form submission with a 50 KB body, this can be 5-20 ms by itself. For an API endpoint accepting larger payloads, it can be hundreds of ms.

The other angle: ModSec audit logging. Every flagged request writes the full request and response to modsec_audit.log. On a host with many alerts, the audit log writes alone can saturate disk IO.

How to verify

Check what is loaded and at what paranoia level:

grep -r 'SecRuleEngine\|paranoia_level\|tx.detection_paranoia_level' /etc/apache2/conf.d/modsec*
ls /etc/apache2/conf.d/modsec_vendor_configs/

Time a request with and without ModSec, to a representative endpoint:

# With ModSec
time curl -s https://example.com/ -o /dev/null

# Temporarily disable for the test
curl -s "http://127.0.0.1/server-status?auto" | head
# (Disable via WHM > ModSecurity > Off, time the same request, re-enable)

For a real measurement, A/B over many requests with wrk:

wrk -t4 -c10 -d30s https://example.com/api/endpoint

Run with ModSec enabled and disabled, compare 99th percentile.

Audit log size and rotation:

ls -lh /usr/local/apache/logs/modsec_audit.log
du -sh /usr/local/apache/logs/modsec_audit*

A multi-GB audit log indicates either many true attacks or rampant false positives consuming disk.

The fix

  1. Run with the OWASP CRS at paranoia level 1. This is the default and is sensibly tuned for false positives. Going higher (2 or 3) requires substantial per-app tuning.

  2. Exclude obvious false positives by URL. WP admin endpoints, WooCommerce REST API, page builder editors — all trigger many rules legitimately. Per-vhost exclusions in /etc/apache2/conf.d/userdata/<user>/<domain>/modsec.conf:

    SecRuleRemoveById 949110 980170  # example rule IDs
    <LocationMatch "/wp-admin/">
      SecRuleRemoveById 200000-200099
    </LocationMatch>
  3. Trim audit logging. SecAuditEngine RelevantOnly and SecAuditLogRelevantStatus "^(?:5|4(?!04))" log only 5xx and non-404 4xx responses — far fewer entries.

  4. Skip body inspection for trusted endpoints. If a customer uploads large files at a specific URL, body-rule scanning is expensive:

    <LocationMatch "/upload/">
      SecRequestBodyAccess Off
    </LocationMatch>
  5. Use a CDN WAF for the heavy lifting (Cloudflare’s WAF or AWS WAF). When the CDN is enforcing rules, the origin ModSec can be lighter. Avoid double-filtering.

  6. Measure after each change. The wrk comparison above tells you whether the change is actually helping.

The trade-off is real: ModSec is doing meaningful work. The goal is not to disable it, but to spend the CPU on rules that catch real attacks, not on regexes that flag legitimate WordPress traffic. Stack Harbor tunes ModSec as part of cPanel/WHM management.