You enable ModSecurity in front of WordPress on a Friday afternoon — the OWASP Core Rule Set at paranoia level 2, default settings, because the install guide implied it was production-ready. By Monday morning the editorial team has filed seven tickets: the block editor refuses to save anything containing a colon, Gravity Forms returns 403 on every submission with a phone number, and the Yoast meta description for a post about SQL training has triggered a SQLi rule. You roll the engine to DetectionOnly and start reading audit logs.
What’s happening
The Core Rule Set is generic by design — it knows nothing about WordPress’s request shapes, nothing about WooCommerce checkout payloads, nothing about the block editor sending wp.editor JSON that looks structurally similar to script injection. CRS works in paranoia levels: PL1 catches obvious attacks with few false positives, PL2 adds aggressive pattern matching, PL3 turns on rules that assume your application never legitimately sends quotes or angle brackets, PL4 is for static sites only. WordPress dashboards live somewhere between PL1 and PL2 — fine for the public site, hostile to /wp-admin/.
The other axis is anomaly scoring. Each matching rule contributes points to an inbound/outbound anomaly score. The default threshold is 5 inbound / 4 outbound. A single PL2 rule can score 5 on its own. That means one false positive on a single request blocks it — there’s no “fires a few times and we look at it later” mode by default. The result: WordPress requests that legitimately contain SQL keywords (meta descriptions, post bodies, the SQL fixer plugin’s settings page) score above threshold and get a 403 with id "942100" in the audit log.
The fix is not to disable CRS. It’s to scope CRS to where it actually helps (the public surface), exempt the authenticated admin surface from the most aggressive families, and version-control a small set of plugin-specific exclusions per environment.
How to verify
Look at the audit log first — every CRS block writes a line you can correlate with the user’s report:
# Last hour of ModSecurity audit events
tail -10000 /var/log/modsec_audit.log \
| grep -E "(Message|Section A|Section B)" \
| grep -E "Matched|REQUEST_URI|wp-admin|wp-json"
# Rule IDs that fired most often last 24h
zcat /var/log/modsec_audit.log.1.gz /var/log/modsec_audit.log \
| grep -oE 'id "[0-9]+"' | sort | uniq -c | sort -rn | head -20
The high-frequency rule IDs are your false-positive candidates. For each one, look up its description in /etc/modsecurity.d/owasp-crs/rules/:
grep -r "id:942100" /etc/modsecurity.d/owasp-crs/rules/
# REQUEST-942-APPLICATION-ATTACK-SQLI.conf:SecRule ...
Confirm the current paranoia level and anomaly threshold:
grep -E "tx.paranoia_level|tx.inbound_anomaly_score_threshold" \
/etc/modsecurity.d/owasp-crs/crs-setup.conf
If those values are unchanged from the CRS distribution defaults, you’re running PL1 with threshold 5 — which is correct for a starting point. The work is the per-plugin exclusions, not raising paranoia.
The fix
We treat ModSecurity tuning as code: crs-setup.conf carries the framework decisions, a single wordpress-exclusions.conf carries the per-environment exclusions, and both live in the operator’s config repo, not on the box.
nginx + ModSecurity load order
# /etc/nginx/conf.d/modsec.conf
load_module modules/ngx_http_modsecurity_module.so;
http {
modsecurity on;
modsecurity_rules_file /etc/modsecurity.d/main.conf;
}
# /etc/modsecurity.d/main.conf
Include /etc/modsecurity.d/modsecurity.conf
Include /etc/modsecurity.d/owasp-crs/crs-setup.conf
# WordPress-specific exclusions MUST load before the CRS rule files
Include /etc/modsecurity.d/wordpress-exclusions.conf
Include /etc/modsecurity.d/owasp-crs/rules/*.conf
The exclusion file must precede the rules — SecRuleRemoveByID directives only suppress rules ModSecurity hasn’t loaded yet for the current configuration phase, so order matters.
Framework decisions in crs-setup.conf
# Paranoia: PL1 globally, raise to PL2 only for unauthenticated request paths
SecAction "id:900000,phase:1,nolog,pass,t:none,\
setvar:tx.blocking_paranoia_level=1,\
setvar:tx.detection_paranoia_level=2"
# Anomaly thresholds — leave defaults
SecAction "id:900110,phase:1,nolog,pass,t:none,\
setvar:tx.inbound_anomaly_score_threshold=5,\
setvar:tx.outbound_anomaly_score_threshold=4"
# Initial setup, blocking mode for non-admin paths
SecDefaultAction "phase:1,log,auditlog,deny,status:403"
SecDefaultAction "phase:2,log,auditlog,deny,status:403"
Detection paranoia higher than blocking paranoia gives the audit log a preview of what PL2 would do without enforcing it. After a week the false-positive log tells you whether PL2 is safe to roll into blocking — usually it is, for the public surface only.
WordPress exclusions
# /etc/modsecurity.d/wordpress-exclusions.conf
# wp-admin: trusted, authenticated, full of payloads that look like attacks
SecRule REQUEST_URI "@beginsWith /wp-admin/" \
"id:1000010,phase:1,pass,nolog,\
ctl:ruleRemoveTargetByTag=attack-sqli;ARGS:content,\
ctl:ruleRemoveTargetByTag=attack-sqli;ARGS:excerpt,\
ctl:ruleRemoveTargetByTag=attack-xss;ARGS:content,\
ctl:ruleRemoveTargetByTag=attack-rce;ARGS:content"
# Block editor / Gutenberg / REST writes
SecRule REQUEST_URI "@beginsWith /wp-json/wp/v2/" \
"id:1000020,phase:1,pass,nolog,\
ctl:ruleRemoveTargetByTag=attack-xss;REQUEST_BODY,\
ctl:ruleRemoveTargetByTag=attack-sqli;REQUEST_BODY"
# admin-ajax.php — too many plugins to enumerate; scope by referer instead
SecRule REQUEST_URI "@streq /wp-admin/admin-ajax.php" \
"id:1000030,phase:1,pass,nolog,chain"
SecRule REQUEST_HEADERS:Referer "@contains /wp-admin/" \
"ctl:ruleRemoveById=941100-941999,\
ctl:ruleRemoveById=942100-942999"
# Gravity Forms / Contact Form 7 / WPForms — frontend submissions
SecRule REQUEST_URI "@rx ^/wp-json/(gf|contact-form-7|wpforms)/" \
"id:1000040,phase:1,pass,nolog,\
ctl:ruleRemoveTargetByTag=attack-xss;ARGS,\
ctl:ruleRemoveTargetByTag=attack-injection-php;ARGS"
# WooCommerce checkout — billing/shipping fields trip address validators
SecRule REQUEST_URI "@rx ^/(\?wc-ajax=checkout|checkout/|wp-json/wc/)" \
"id:1000050,phase:1,pass,nolog,\
ctl:ruleRemoveTargetByTag=attack-rfi;ARGS,\
ctl:ruleRemoveTargetByTag=attack-lfi;ARGS"
# Yoast SEO meta editor — descriptions about SQL/PHP topics
SecRule REQUEST_URI "@rx ^/wp-json/yoast/v1/" \
"id:1000060,phase:1,pass,nolog,\
ctl:ruleRemoveTargetByTag=attack-sqli;REQUEST_BODY"
# Elementor / Divi / Bricks — page builder save endpoints
SecRule REQUEST_URI "@rx ^/wp-admin/admin-ajax\.php" \
"id:1000070,phase:1,pass,nolog,chain"
SecRule ARGS:action "@rx ^(elementor_|et_pb_|bricks_)" \
"ctl:ruleRemoveById=920000-999999"
The pattern is: identify the family, identify the request shape, narrow the exclusion to specific tags or rule ID ranges rather than blanket-disabling. ctl:ruleRemoveTargetByTag is preferable to ctl:ruleRemoveById because new CRS releases keep tags stable while renumbering rules.
Validation after each change
# Reload nginx and tail the audit log live
nginx -t && systemctl reload nginx
tail -F /var/log/modsec_audit.log | grep -E "Matched|Action"
# Replay yesterday's traffic against staging with the new rules
goreplay --input-file requests.gor --output-http http://staging:80
Run a weekly review of the top 10 firing rule IDs. The pattern that keeps the audit log clean is small, scoped exclusions per plugin family — never global paranoia downgrades.
Stack Harbor maintains ModSecurity tuning as code under Enterprise WordPress, with paranoia escalation tracked across releases. For the broader edge-protection layer including rate limiting and origin lockdown, Managed Cloud Ops covers the full stack — or tell us what’s firing and we’ll review your audit log.