Tutorial
A web application firewall for Laravel, from brewless.yml
bunny.net Shield now guards every new Brewless environment. What its managed WAF, rate limits and bot rules do for a Laravel app, and how to set them.
In this post
Every public Laravel app sees the same requests in its access log: ?id=1' OR '1'='1, <script> in a search box, a hundred logins a minute from one address. Laravel handles most of it well. Eloquent binds its parameters, Blade escapes its output, and the throttle middleware slows down a login form. Your code still has to receive every one of those requests to refuse it.
Since this week, a new environment on Brewless has a web application firewall in front of it that refuses many of them first: bunny.net Shield, on the pull zone that already sits in front of your containers. This post explains what it does for a Laravel app, what it leaves to your code, and how to set it in brewless.yml.
Does a Laravel app need a web application firewall?
Not instead of secure code, but in front of it, yes. A web application firewall stops known attacks and automated guessing at the edge, before PHP runs. Laravel stays the first defence for anything specific to your application; the firewall takes the bulk that is the same on every site.
On a serverless container there is a second reason. A request that reaches the container wakes it, and a container that is awake is billed. A scanner trying SQL injection on your search page at three in the morning is not dangerous to a well-written app, but it keeps it awake. The edge already answers the most common scanner addresses with a 403, as described in why /wp-login.php wakes your Laravel container. Shield goes further: it looks at what a request carries, not only where it goes.
What a new environment gets
An environment made since Shield became the default gets a Shield zone at its first deploy with bunny.net in front of it. You do not need to write anything for it; a deploy from the console does it as well. The zone is on Shield Basic, which bunny.net gives for free up to 25 million clean requests a month per zone. Cache hits and requests Shield blocks do not count towards that.
| Layer | What it does | Set by |
|---|---|---|
| Managed WAF | Checks every request to the application against the OWASP core rules bunny.net includes in Basic | On by default, firewall.waf |
| Rate limits | Counts requests per address in ten seconds; over the limit gets a 429 for a minute |
firewall.rate_limit, firewall.rate_limit_sensitive |
| Bot policy | Lets verified crawlers past bot detection and challenges | bots |
| Bot control | Challenges visitors that look like bots | firewall.bot_control, paid plans only |
The full reference is on Firewall and Bots and AI crawlers.
The managed rules block from the first deploy
bunny.net starts every new Shield zone in a learning week: for seven days its firewall only records what it would have blocked. Brewless does not wait for that. Every deploy ends the learning week, so the managed rules block from the first one.
That sounds bold, but the default is mild. Shield Basic runs the OWASP core rules at their lowest sensitivity, the level that rarely catches a real visitor of a Laravel app. A single matching rule is enough to block a request; there is no score that adds up.
When you would rather watch first, say so:
brewless.ymlenvironments:
production:
firewall:
waf: log
waf: log keeps the learning week running and only records. waf: off switches the firewall off. Every deploy and brewless plan say until which day a zone is still learning.
When a rule blocks your own form
A form that sends HTML or code, such as a rich text editor or a code snippet in a comment, can look like an attack to a rule. When a real visitor is blocked, the Shield event logs of the pull zone in your bunny.net dashboard name the rule id. Put it under waf_log_only and deploy:
brewless.ymlenvironments:
production:
firewall:
waf_log_only: [942100]
The rule keeps recording, so you still see what it catches. waf_disabled switches a rule off entirely; keep that for a rule that catches nothing else, and write in a comment why. Before you choose, brewless plan names every rule in those lists with its description and how often bunny.net saw it match.
Rate limits next to Laravel's throttle
Shield Basic has room for two rate limit rules, and Brewless can fill both:
brewless.ymlenvironments:
production:
firewall:
rate_limit: 300
rate_limit_sensitive: 5
rate_limit_paths: [/checkout]
rate_limit counts requests from one address in ten seconds. rate_limit_sensitive does the same, stricter, and on its own paths: /login, /register, /forgot-password, /reset-password, /two-factor-challenge and /contact, plus whatever rate_limit_paths adds. The first five are the routes Fortify and Laravel's starter kits use, so for most apps the list fits without changes. An address over a limit gets a 429 from bunny.net for a minute; everybody else goes on.
This does not replace Laravel's throttle middleware on the login route. That one knows the account being tried and can count per e-mail address; the edge only knows the visitor's address. Keep both: Laravel for precision, the edge to stop the flood before PHP starts.
Two details make the edge limits kind to real visitors. A page the edge answers from its cache never counts, so someone browsing cached pages uses up nothing. And robots.txt, the sitemaps, llms.txt, /.well-known/ and Markdown for agents are never counted, because crawlers and AI assistants ask for them in bursts.
Tip
Many people behind one address, such as a school, an office or the wifi at an event, look like one heavy visitor. For an app used like that, the documentation suggests
rate_limit: 1000andrate_limit_sensitive: 20.
Crawlers stay welcome
A firewall that turns away Googlebot costs more than it saves. A Shield zone Brewless makes lets search engines, AI search, AI assistants, AI training crawlers, link previews and monitoring in. Shield checks that a request really comes from such a crawler, by the addresses its owner publishes and its DNS name, never by the user agent alone. A scanner that calls itself Googlebot is not treated as Googlebot.
You can change that per group under bots, or per crawler under bots.overrides. Your robots.txt still decides what a polite crawler reads; Brewless never changes it, and brewless plan points out when bots and robots.txt disagree.
Bot control, which challenges visitors that merely look like bots, is not part of Shield Basic. It takes Shield Advanced or higher, which bunny.net bills to your own bunny.net account. Brewless never changes the plan of a Shield zone: you choose it in the bunny.net dashboard and deploy again.
Environments that already existed
An environment made before Shield became the default keeps what it has. A deploy never gives it a Shield zone it did not ask for. brewless plan and the Security card in the console say it can turn Shield on, and nothing changes until you add firewall to brewless.yml.
The safe way over takes a week:
- Add
firewall: { waf: log }and deploy. Shield records but blocks nothing. - Watch the Security card. It shows what Shield acted on and which rules matched, with the paths. A rule that matched on a page real visitors use goes in
waf_log_only. - Change
waf: logtowaf: blockand deploy. - Turn on a private origin, so nobody reaches the container past the edge and Shield.
Start on a test environment, then production. A change to firewall needs brewless deploy; Deploy on push does not change the edge.
What Shield does not see
Shield covers what goes through the pull zone. The WebSocket connections of a realtime server go straight to their container at Scaleway, so Shield never sees them. The container's own Scaleway address is also a way past it, until a private origin closes it.
A few more things to know:
- Your settings in the bunny.net dashboard are respected. A setting you leave out of
brewless.ymlstays as it is at bunny.net. When you change one the file does name, the next deploy keeps the dashboard's value and tells you;--force-shieldsets what the file says. - Secrets stay out of the logs. Shield's event logs record the headers of requests it acted on. Every deploy adds the two headers that carry the private origin token and the edge secret to the list the zone leaves out.
- Brewless stores nothing of it. The Security card reads Shield live from bunny.net, shows paths only, never visitor addresses or query strings, and keeps the answer for a minute.
- A Shield zone cannot be removed. bunny.net offers no way to.
firewall: falsetakes away what Brewless set and leaves an empty zone, which costs nothing on Basic.
A web application firewall is one layer. It does not replace secure code, dependency updates, vulnerability scans or a penetration test. It does take a large share of the noise off your containers, in your own bunny.net account, set up from the same file as the rest of your environment.
Why we built it, and what it means for the cost of a serverless app, is in introducing Brewless Shield. The overview is on the Brewless Shield page.
Frequently asked questions
Does a Laravel app need a web application firewall?
It does not replace secure code, and Laravel already escapes output, binds query parameters and throttles logins. A WAF at the edge stops the bulk of known attacks and automated guessing before they reach the container, which on serverless also means before they wake it.
What does bunny.net Shield Basic cost?
Shield Basic costs nothing at bunny.net up to 25 million clean requests a month per Shield zone. Cache hits and requests Shield blocks do not count. Past that, bunny.net bills $0.70 per million to the owner of the bunny.net account. Brewless charges nothing for Shield.
What happens when the firewall blocks a real visitor?
Find the request in the Shield event logs of the pull zone, which name the rule id, add that id to waf_log_only in brewless.yml and deploy. The rule keeps recording, so you still see what it catches, but it no longer blocks.
Will Shield stop search engines or AI crawlers from reading my site?
It is set up not to. A Shield zone Brewless makes lets search engines, AI search, AI assistants, AI training crawlers, link previews and monitoring in, and robots.txt, the sitemaps, llms.txt and everything under /.well-known/ are never challenged or rate-limited.
Can I turn the firewall off?
Yes. firewall set to false in brewless.yml means no Shield zone is made for a new environment, and for an existing one it removes the rate limit rules Brewless set and switches bot control off.