Hardening Laravel Vapor with Managed Firewall Protection
Overview
Managing serverless environments requires more than just scaling code; it demands robust perimeter security. offers a managed firewall to shield applications from Distributed Denial of Service (DDoS) attacks and resource-draining automated traffic. By implementing these controls, you prevent unexpected costs and ensure high availability for legitimate users.
Prerequisites
To follow this guide, you should be familiar with the framework and have a basic understanding of configuration. You will also need a project already provisioned on the Vapor platform.
Key Libraries & Tools
- Laravel Vapor: A serverless deployment platform for Laravel.
- Vapor CLI: The command-line interface used to deploy and manage environments.
- Guzzle: A PHP HTTP client often used by bots or scripts to make requests.
Code Walkthrough
To enable the firewall, modify your vapor.yml file. This configuration acts as the blueprint for your environment's security rules.
Setting Rate Limits
Add a firewall section to your environment configuration to limit how many requests a single IP can make within a five-minute window.
id: 1
name: my-app
environments:
production:
firewall:
rate_limit: 100
When a source exceeds 100 requests in 5 minutes, Vapor automatically blocks subsequent attempts, protecting your database and compute resources from exhaustion.
Implementing Bot Control
You can further refine traffic by blocking specific categories of automated agents. This is particularly useful for internal APIs that shouldn't be indexed by search engines.
firewall:
bot_control:
- http_libraries
- search_engines
Syntax Notes
The firewall key must sit under the specific environment block (e.g., production or staging). The bot_control option accepts a list of predefined categories. Always ensure your indentation is correct, as malformed files will cause deployment failures.
Practical Examples
A common use case involves blocking http_libraries. If you run a script using or curl against an endpoint protected with this rule, the firewall will reject the traffic immediately. This effectively stops simple scraping scripts from impacting your app.
Tips & Gotchas
- Deployment Required: Changes to
vapor.ymldo not take effect until you runvapor deploy. - Monitoring: Check your environment metrics after enabling these rules. Vapor provides visual feedback on how many requests the firewall has successfully blocked.
- Cooldown: Rate-limited IPs are generally blocked for the remainder of the five-minute sliding window.
- 40%· products
- 20%· products
- 20%· products
- 20%· products

Learn Laravel Vapor #24: Firewall
WatchLaravel // 4:52
The official YouTube channel of Laravel, the clean stack for Artisans and agents. We will update you on what's new in the world of Laravel, from the framework to our products Cloud, Forge, and Nightwatch.