Cloudflare's Free WAF Rules That Won't Nuke Your Laravel App
Cloudflare's free WAF is genuinely useful, but the default managed rules will block your own Laravel endpoints if you're not careful. Here's what I actually run.
The Cloudflare free tier gets you a real WAF, not a toy. I've been running it in front of Laravel apps for years and it blocks actual malicious traffic daily - but out of the box, some of the managed rule sets will happily 404 your own form submissions and API endpoints if you let them. Here's exactly how I configure it.
What the Free WAF Actually Gives You
People underestimate what Cloudflare hands you for free. You get:
- Managed rulesets (Cloudflare's own, not just OWASP)
- Custom firewall rules (called "Custom Rules" now after the rebranding)
- Rate limiting (5 rules free, with some restrictions)
- Bot Fight Mode
- Security Events log so you can see what's being blocked
The managed rulesets on the free tier are a subset of the paid offering, but they cover the high-volume stuff - SQL injection, XSS, common scanner signatures, known bad user agents. For most of my clients, that's the attack surface that matters.
What I'm after is stopping the script-kiddie SQLi crawlers, the WordPress exploit scanners probing /wp-admin on a Laravel app, and the credential stuffing bots hammering /login. All of that is reachable on free.
The Footgun: Managed Rules vs. Laravel's Routing
Here's where people get burned. Laravel does things that look suspicious to a naive WAF:
_methodspoofing. Laravel uses_method=DELETEor_method=PUTin POST bodies because HTML forms only speak GET and POST. Some WAF rules flag this as method tampering.- Large JSON payloads to API endpoints. If you're accepting a batch of records, a 50kb POST body will trip content-length heuristics.
- The
X-CSRF-TOKENheader. It's a long opaque string in every AJAX request. Certain rules pattern-match on header values and get nervous. - Pagination and filter query strings. Something like
?filter[status]=active&filter[date_range][from]=2024-01-01looks like an array injection attempt to unsophisticated rules.
I learned this the hard way on a healthcare client's patient intake form. We launched, got paged at 11pm because form submissions were returning 403s. Cloudflare was blocking the POST because the body contained what it classified as a suspicious parameter pattern. The rule in question was 100016 from the Cloudflare Managed Ruleset - "Anomaly: HTTP Header - Cookie Header too Large". The session cookie combined with CSRF token pushed the header size over the threshold.
Fix took ten minutes once I found it in the Security Events log, but those ten minutes at 11pm were not my favorite.
What I Actually Enable
This is my standard starting config for a Laravel production app on Cloudflare free tier.
Managed Rulesets
I enable the Cloudflare Managed Ruleset at the category level, then override specific rules that cause false positives. I do NOT enable "Cloudflare OWASP Core Ruleset" on free unless the client has a specific compliance reason - it's more aggressive and generates more noise than it's worth on a well-structured Laravel app.
Categories I enable from the Cloudflare Managed Ruleset:
Drupal- off (we're not on Drupal)Joomla- offMagento- off (unless it's a Magento integration)PHP- on, BlockWordPress- offXSS- on, BlockSQLi- on, BlockBroken Access Control- on, Block
The CMS-specific rules are noise for a Laravel app. Turning off WordPress rules alone eliminates a huge chunk of false positives.
Custom Rules I Write
This is where I spend most of my time. Cloudflare's expression language is actually pretty readable.
Block known bad paths that don't exist in a Laravel app:
(http.request.uri.path contains "/wp-admin")
or (http.request.uri.path contains "/wp-login")
or (http.request.uri.path contains "/xmlrpc.php")
or (http.request.uri.path contains "/.env")
or (http.request.uri.path contains "/vendor/phpunit")
or (http.request.uri.path contains "/actuator")
or (http.request.uri.path contains "/.git")
Action: Block. No exceptions. A Laravel app has none of these paths. If something is hitting them, it's a scanner.
Block empty or missing User-Agents (bots that don't bother faking one):
(http.user_agent eq "")
or (not http.user_agent exists)
Action: Block.
Rate limit the login endpoint:
This one I set as a Rate Limiting rule, not a custom firewall rule. Free tier gives me 5 rate limiting rules.
- Path:
/login - Method: POST
- Threshold: 5 requests per 60 seconds per IP
- Action: Block for 10 minutes
For a client with a Laravel app that uses /api/auth/token or similar, I duplicate this rule for that path.
Skipping Rules for Specific Routes
This is the part most tutorials skip. You can create a rule that fires before the managed ruleset and tells Cloudflare to skip specific managed rules for specific paths. Free tier supports this.
For a Laravel API that accepts large JSON payloads:
(http.request.uri.path wildcard "/api/*" and http.request.method eq "POST")
Action: Skip - Cloudflare Managed Ruleset - then pick the specific rule IDs to skip. I usually skip the body size anomaly rules (look for anything tagged "Anomaly" in the Security Events log).
For the _method spoofing issue:
(http.request.uri.path wildcard "/admin/*" and http.request.method eq "POST")
Then skip rule 6179 (HTTP method override detection). Your admin panel's delete and update forms will work again.
Reading the Security Events Log
This is non-negotiable. Any time I turn on a new rule or a client reports weird 403s, the first thing I do is:
- Cloudflare dashboard - Security - Events
- Filter to the last hour
- Look for
Action: Blockentries - Click through to see which Rule ID fired and what the matched value was
The log shows you the exact rule ID, the matched field, and the matched value. From there you either skip that rule globally, skip it for a specific path, or - if it's catching something real - you've just found a vulnerability in your own app you didn't know about.
I've genuinely found misconfigured endpoints this way. One client's staging environment was accessible via a path that shouldn't have been public. Cloudflare blocked a probe, I looked at the event, and realized the route existed when it shouldn't. That's the WAF working correctly.
Tuning Over Time
I do a quick review of Security Events every week for the first month after enabling WAF on a new client. After that, I set up a Cloudflare notification (free) to email me if blocks spike above a threshold. Normal background noise for a mid-sized Laravel app is maybe 50-200 blocked requests a day. If that jumps to 2,000 overnight, something changed - either someone is actively probing the app, or I pushed a deploy that changed request patterns and I'm getting false positives.
When I Reach for the Free Tier vs. Upgrading
Free tier is right for:
- Laravel apps with standard routing (no exotic request patterns)
- Internal tools where you just need basic protection
- Small e-commerce with Stripe handling payments (PCI concerns are downstream)
- Any client not yet ready to spend $20/month on WAF
I push clients to Pro ($20/month) when:
- They're in healthcare and need better logging for audit purposes
- They're getting targeted attacks, not just scanner noise
- The app accepts file uploads and I want the content inspection rules
- I need more than 5 rate limiting rules
The OWASP ruleset on Pro is more tunable and I can set sensitivity levels. For a biotech client handling sensitive research data, free is not where I'd stay.
A Quick Laravel Middleware Note
One thing worth wiring up: log the CF-Connecting-IP header in Laravel instead of relying on REMOTE_ADDR once you're behind Cloudflare. Otherwise your application logs (and fail2ban, if you're using it) see Cloudflare's proxy IP, not the real client.
In config/trustedproxies.php (or the middleware directly in newer Laravel versions):
<?php
// In App\Http\Middleware\TrustProxies (Laravel 10 and earlier)
// or config/trustedproxies.php (Laravel 11+)
protected $proxies = '*'; // or list Cloudflare's IP ranges explicitly
protected $headers =
Request::HEADER_X_FORWARDED_FOR |
Request::HEADER_X_FORWARDED_HOST |
Request::HEADER_X_FORWARDED_PORT |
Request::HEADER_X_FORWARDED_PROTO;
With this set, request()->ip() in Laravel returns the real client IP, which Cloudflare sends in X-Forwarded-For. Your logs are accurate, your rate limiting in-app works correctly, and if you ever do any IP-based access control inside Laravel itself, it's based on reality.
Cloudflare publishes their IP ranges at https://www.cloudflare.com/ips/ if you want to lock it down rather than using '*'.
Closing
The free Cloudflare WAF is legitimately good - it's not a checkbox feature. The work is in the tuning: turn off CMS rules that don't apply to you, skip anomaly rules on your API paths, write a handful of custom rules for the paths that don't exist, and check the Security Events log until you're confident you're not generating false positives. That's maybe two hours of setup and a week of monitoring. After that it runs itself and stops a real volume of garbage before it ever reaches your server.
Need help shipping something like this? Get in touch.