Configuring ModSecurity in cPanel
ModSecurity is a Web Application Firewall (WAF) that protects your website from common attacks including SQL injection, cross-site scripting (XSS), and other OWASP Top 10 vulnerabilities.
What Is ModSecurity?
ModSecurity inspects incoming HTTP requests and blocks those that match known attack patterns. It runs at the server level and protects all websites on the server automatically.
Accessing ModSecurity Settings
- Log in to cPanel
- Go to Security section
- Click ModSecurity
ModSecurity Status
You can toggle ModSecurity for individual domains:
| Status | Meaning |
|---|---|
| On | ModSecurity is actively protecting this domain (recommended) |
| Off | ModSecurity is disabled for this domain |
Warning: Only disable ModSecurity if a specific rule is causing a false positive. Re-enable it as soon as the issue is resolved.
Handling False Positives
Sometimes ModSecurity blocks legitimate requests. Common scenarios:
- Saving content in a CMS editor that contains HTML or code
- Uploading files with certain content patterns
- Using admin features that trigger security rules
How to Identify a False Positive
- You see a 403 Forbidden or 406 Not Acceptable error
- The error occurs when performing a specific action
- The action worked before or works on other sites
- Check the error log in cPanel for ModSecurity entries:
ModSecurity: Access denied with code 403 (phase 2). [id "12345"] ...Resolving False Positives
Option 1: Temporarily disable for your domain
- Go to ModSecurity in cPanel
- Click Off next to the affected domain
- Perform the blocked action
- Re-enable ModSecurity immediately after
Option 2: Contact support
Provide the error log entry with the rule ID (e.g., id "12345"). Our team can whitelist specific rules for your domain.
What ModSecurity Protects Against
SQL Injection
Blocks requests that attempt to inject malicious SQL queries through form inputs or URLs.
Cross-Site Scripting (XSS)
Prevents attackers from injecting malicious JavaScript into your web pages.
Remote File Inclusion
Blocks attempts to include malicious files from external servers.
Directory Traversal
Prevents attempts to access files outside your web root using ../ patterns.
Command Injection
Blocks attempts to execute system commands through web inputs.
Best Practices
- Keep ModSecurity enabled — It is your first line of defense
- Update your CMS and plugins — ModSecurity catches known vulnerabilities, but updating prevents them entirely
- Report false positives — Contact support so we can fine-tune rules without reducing security
- Do not disable permanently — If you must disable ModSecurity, always re-enable it after completing the blocked task
- Monitor your error logs — Regularly check for blocked requests that might indicate attack attempts
ModSecurity and WordPress
WordPress users may encounter ModSecurity blocks when:
- Saving posts with HTML or JavaScript content
- Using page builders that generate complex markup
- Running security plugins that perform their own scanning
Solutions:
- Use the WordPress editor in Visual mode instead of Code mode
- Temporarily disable ModSecurity for bulk content updates
- Contact support to whitelist specific rules
Troubleshooting
403 Error When Saving Content
- Check the error log for the ModSecurity rule ID
- Temporarily disable ModSecurity for the domain
- Save your content
- Re-enable ModSecurity
- Contact support with the rule ID for a permanent fix
406 Error on File Upload
- The file content may match a malware signature
- Try renaming the file
- If legitimate, contact support with details
Slow Page Loading
ModSecurity adds minimal overhead. If pages are slow:
- The cause is likely elsewhere (database, PHP, resources)
- Check CloudLinux resource usage
- ModSecurity does not significantly impact performance
Related Articles
Need help? Contact our support team at {{SUPPORT_EMAIL}} or open a ticket at {{SUPPORT_URL}}.