Security 6 min read

ModSecurity 403 on cPanel? Fix the False Positive Safely

When one form on one site returns 403 and everything else works, a single WAF rule is almost always the cause. Fix that rule, not the firewall.

By BashPilot Team
BashEdge WAF & DDoS protection Stop Layer 7 floods and malicious requests before they reach the app. Explore BashEdge

A ModSecurity false positive on a cPanel server looks like a website that works for everyone except one action: saving a post, submitting a checkout form, uploading an image. That one request returns 403 Forbidden, the application log shows nothing, and the temptation is to switch the web application firewall off. You almost never need to. One rule fired on one input, and you can exclude exactly that.

Confirm it is ModSecurity and get the rule ID

The quickest route on cPanel is the interface. In WHM open Security Center, then ModSecurity Tools, and look at the Hits List. It shows the server's recent rule events, though only the most relevant hit for each request, and clicking the Rule ID opens that rule so you can edit or disable it. Reproduce the failing action once, reload the list, and the newest entry for your domain is the one you want.

To see the full detail, read the log. The location depends on how the server was set up, so ask the configuration instead of guessing a path.

find the ModSecurity and Apache error log locations
grep -rEi '^\s*(SecAuditLog|SecDebugLog)\b' /etc/apache2/conf.d/ 2>/dev/null
grep -E '^ErrorLog' /etc/apache2/conf/httpd.conf

A real log entry carries several bracketed fields. The ones that matter are [id "941320"], the rule ID, [msg ...], the rule's description, and [data "Matched Data: ..."], which shows the exact text that triggered it. Together they answer the two questions you need: which rule, and which input.

Choose the narrowest exclusion that works

ApproachScopeUse it when
Disable the rule in WHMEvery site on the server, every URLA quick temporary relief while you investigate
SecRuleUpdateTargetByIdOne rule, one parameter, all URLsThe same field trips the rule everywhere
ctl:ruleRemoveTargetById on a pathOne rule, one parameter, one URLThe normal answer for a single form on a single site
ctl:ruleRemoveById on a pathOne whole rule on one URLThe rule makes no sense for that URL at all

Here is the runtime exclusion for the common WordPress case, where the post editor's content field trips an XSS rule because it legitimately contains HTML. It removes one parameter from one rule, and only for requests to one path.

exclude one parameter from one rule on one URL
SecRule REQUEST_URI "@beginsWith /wp-admin/post.php" \
    "id:1000010,\
    phase:1,\
    pass,\
    t:none,\
    nolog,\
    ctl:ruleRemoveTargetById=941320;ARGS:content"

Pick a rule ID for your own rule that no installed rule set uses, and check before you save it with grep -rn 'id:1000010' /etc/apache2/conf.d/modsec*. Replace the 941320 and content with the values from your own log entry. The t:none is recommended for exclusions of this kind in the Core Rule Set documentation.

Where you put the rule matters, and this is the step people get wrong. A runtime exclusion that uses ctl: has to be processed before the rule it modifies, because it changes that rule before it runs. A configure-time directive such as SecRuleRemoveById or SecRuleUpdateTargetById has to come after the rule it refers to has been defined. On EasyApache 4, cPanel's custom rules file is /etc/apache2/conf.d/modsec/modsec2.user.conf. If your exclusion does not seem to work, order is the first thing to suspect, and the test in the next section will tell you.

Deploy and test

If you used WHM's editor, the staged change takes effect only after you click Deploy and Restart Apache. If you edited the file by hand, check the syntax and restart Apache yourself.

check the configuration, then restart Apache
apachectl configtest
/scripts/restartsrv_httpd

Now repeat the original action, for example saving the post that failed. It should succeed, and the Hits List should show no new entry for that rule and URL. Then prove that you have not blinded the firewall, by sending something it should still refuse.

a crude attack string should still be blocked
curl -s -o /dev/null -w '%{http_code}\n' 'https://example.com/?q=<script>alert(1)</script>'

A 403 here means the engine is still doing its job. This is a coarse check, because what gets blocked depends on the rule set and its sensitivity setting, so treat a pass as reassurance rather than proof.

Where an edge layer helps

Hand-tuning exclusions for every site gets old on a server with many accounts. BashEdge manages a server-wide WAF with more than 50 maintained rules and starts in monitor mode, so you review what each rule would have done to real traffic before it blocks anything. You choose per rule whether to monitor, challenge or block, and it connects each action to the detection rule, the reason, the source and the targeted host. For the buying criteria behind that kind of tool, see What Is the Best Web Application Firewall for cPanel?.

Keep false positives from coming back

  • Run a new or updated rule set in DetectionOnly mode first and read the Hits List for a few days before you let it block.
  • Comment every exclusion with the site, the rule ID, the date and the reason, so that nobody removes or copies one without understanding it.
  • Review the Hits List after each plugin or theme update, because a new feature that posts HTML or JSON is the usual trigger.
  • Report persistent false positives from a vendor's rule set to the vendor when the interface offers the option, since fixing the rule helps every user.
Share LinkedIn X
Questions

Frequently asked questions

How do I find which ModSecurity rule blocked my request on cPanel?

Open WHM, go to Security Center, then ModSecurity Tools, and check the Hits List after repeating the failing request. Click the Rule ID to open the rule. In a raw log entry the same number appears as `[id "941320"]` next to a message and the matched data that triggered it.

Is it safe to disable a ModSecurity rule in WHM?

It is safe as a short, deliberate step, but it turns the rule off for every site on the server. If one parameter on one URL caused the problem, a path-scoped exclusion removes the false positive while keeping the rule protecting everything else. Disabling the engine entirely should be a last resort.

Why did my ModSecurity exclusion not work?

Usually ordering. A runtime `ctl:` exclusion must be processed before the rule it changes, and a configure-time directive such as `SecRuleRemoveById` must come after that rule is defined. The second common cause is a chained rule, where a target exclusion only applies to the first rule in the chain. Test with a repeat request after every change.

Where do custom ModSecurity rules go on cPanel?

On EasyApache 4 the custom rules file is `/etc/apache2/conf.d/modsec/modsec2.user.conf`, and cPanel's documentation tells you to check it when you see many false positives. Staged changes made in WHM take effect only after you deploy them with Deploy and Restart Apache.

Should I turn ModSecurity off if it keeps breaking a plugin?

No. Turning it off removes a layer of protection from every hosted site to fix one form. Identify the rule from the log, exclude the specific parameter or URL, and keep the rest enforcing. If a rule set is too strict across many sites, run it in detection-only mode while you tune it.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.