spatie/laravel-honeypot
Protect Laravel forms from spam bots with a simple honeypot field and submit-time check. Add the x-honeypot Blade component (or pass values manually for Inertia) and automatically discard suspicious submissions with filled traps or too-fast posts.
config/honeypot.php, allowing customization of field names, validation thresholds, and response behaviors (e.g., blank page or custom spam responder).<x-honeypot /> to forms and applying the ProtectAgainstSpam middleware to routes is straightforward for most Laravel applications.app/Http/Kernel.php for enterprise-wide protection, though this requires discipline to include honeypot fields in all forms.honeypot data to frontend components), adding slight complexity but maintaining flexibility.spatie/laravel-csp).amount_of_seconds (default: 1s) may block legitimate users with slow connections. Requires tuning based on user demographics.ProtectAgainstSpam is global, missing honeypot fields in forms will trigger spam exceptions. Risk mitigated by setting honeypot_fields_required_for_all_forms: false.encryptedValidFrom) may introduce bugs if not synced correctly between backend and frontend.amount_of_seconds? Should it be dynamic (e.g., per-region)?SpamResponder (e.g., redirect to CAPTCHA) be implemented?with_csp be enabled to avoid inline style issues?<x-honeypot /> or @honeypot.Honeypot object) and Vue/React component adjustments.UsesSpamProtection trait and HoneypotData property, with Blade component support.guessHoneypotDataProperty.composer require spatie/laravel-honeypot
php artisan vendor:publish --provider="Spatie\Honeypot\HoneypotServiceProvider" --tag="honeypot-config"
config/honeypot.php (e.g., adjust amount_of_seconds, disable randomize_name_field_name if needed).spatie/laravel-csp.<x-honeypot /> to each form.ProtectAgainstSpam to routes or globally.amount_of_seconds based on real-world data.config/honeypot.php for changes (e.g., field name collisions with new form fields).with_csp is enabled, coordinate with the CSP package’s maintenance cycle.Spatie\Honeypot\Exceptions\SpamException. Log these to identify false positives or misconfigured forms.amount_of_seconds per region if latency varies significantly (e.g., 2s for high-latency areas).| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Missing honeypot field in form | Spam exception for legitimate users | Set honeypot_fields_required_for_all_forms: false or enforce pre-submission checks. |
amount_of_seconds too aggressive |
False positives (blocked users) | Monitor error logs; adjust threshold dynamically. |
| CSP misconfiguration | Honeypot fields blocked | Test CSP rules in staging; disable with_csp if issues arise. |
| Global middleware misconfiguration | All forms broken | Use feature flags or route-specific middleware during rollout. |
| Package update breaks compatibility | Spam bypass or errors | Test updates in staging; roll back if needed. |
<x-honeypot />").display: none or equivalent).How can I help you explore Laravel packages today?