linups / linups-firewall
Laravel middleware that bans web crawlers by URL keyword and syncs banned IPs to a Cloudflare IP list
Requires
- php: ^8.1
- illuminate/console: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/database: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/http: ^9.0|^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^9.0|^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Laravel package that blocks web crawlers. Every request URL is matched against the
keywords table; a match returns 403, stores the client IP in banned_ips and adds it
to a Cloudflare IP list (which you reference from a Cloudflare WAF rule). Cloudflare lists
do not accept single IPv6 addresses, so an IPv6 client is banned as its whole /64.
A banned IP is also blocked in the app on every URL for ban_duration_days, so it stays out
while the Cloudflare list update is pending. This uses the cache: deleting a banned_ips row
does not unban an IP in the app. Also run
php artisan cache:forget linups-firewall.banned.<ip> (IPv6: <prefix>::/64) or clear the cache.
Installation
composer require linups/linups-firewall php artisan migrate php artisan vendor:publish --tag=linups-config # optional php artisan firewall:update-crawler-ips # first download; then daily via the scheduler
The middleware is registered globally by the service provider. It is also available as the
linups-firewall route middleware alias.
Configuration (.env)
| Key | Purpose |
|---|---|
cloudflare_api_token |
Scoped API token (Account Filter Lists: Edit). Recommended. |
cloudflare_auth_email, cloudflare_auth_key |
Legacy Global API Key auth, used only when no token is set. |
cloudflare_account_id, cloudflare_list_id |
Target IP list. |
cloudflare_endpoint |
Defaults to https://api.cloudflare.com/client/v4/accounts. |
notification_email |
Receives the 404 notifications. Empty = off. Banned crawlers are not mailed. |
not_found_notification |
true to mail notification_email about every 404 (URL, time, request details) with an Add url to ban list link. Default off. |
not_found_throttle_minutes |
Report the same URL at most once per this many minutes, default 60. 0 = every hit. |
ban_link_expires_days |
Validity of the signed Add url to ban list link, default 7. |
ban_duration_days |
Local ban retention, default 30. |
whitelist_ips |
Comma-separated IPs / CIDRs that are never banned (office, home), e.g. whitelist_ips="203.0.113.7,198.51.100.0/24,2001:db8::/48". An old ban of a whitelisted IP is removed on its next request. |
sync_with_main_project |
enabled to download keywords from another installation. |
sync_project_endpoint |
Base URL of that installation. |
keyword_list_token |
Shared secret protecting /linups-firewall/v1/get-keyword-list. Set the same value on both sides. |
These two are arrays in config/linups-config.php (publish the config to change them):
| Key | Purpose |
|---|---|
verified_crawler_ip_lists |
name => URL of the IP-range lists published by crawler operators (JSON with prefixes[].ipv4Prefix / ipv6Prefix). Defaults: Googlebot, Bingbot, OpenAI (OAI-SearchBot, ChatGPT-User, GPTBot), PerplexityBot, Applebot. |
verified_crawler_rdns_suffixes |
Allowed reverse-DNS suffixes for the fallback check. Defaults: .googlebot.com, .google.com, .search.msn.com, .applebot.apple.com. Never add cloud-hosting domains such as .googleusercontent.com or .amazonaws.com: anyone can rent a server there. |
Verified search and AI crawlers
Search crawlers follow old or spam backlinks (/wp-login.php, /.env), so they hit ban
keywords just like scanners. Banning them removes the site from Bing, and with it from
ChatGPT search, Copilot and DuckDuckGo. Verified crawlers are therefore never banned:
- On a keyword URL they get a plain
404 Not Found(not the403), so they drop the URL. Nobanned_ipsrow is written, nothing is pushed to Cloudflare and no 404 mail is sent. The hit is logged aslinups-firewall: verified crawler hit keywordwith the IP, keyword, URI, user agent and verification method. - A crawler that was banned before is unbanned on its next request (cache key and
banned_ipsrow removed). The hourlyupdate:banned-ips-on-cloudflarethen removes it from the Cloudflare list. To clean up all at once, runfirewall:unban-verified-crawlers.
An IP counts as verified when:
- it is inside a range from
verified_crawler_ip_lists(downloaded daily byfirewall:update-crawler-ips, kept instorage/app/linups-firewall/verified-crawler-ips.jsonand the cache; a failed download keeps the last good copy), or - its reverse DNS (PTR) hostname ends with a
verified_crawler_rdns_suffixesentry and that hostname resolves (A/AAAA) back to the same IP.
The verifier is asked only for requests that would otherwise be blocked (already banned, or a keyword matched), so normal page loads are not affected. Each IP's result, verified or not, is cached for 24 hours. The first blocked request from a new IP that is not on a list waits for one PTR lookup.
Also exclude Cloudflare's own verified bots in the WAF custom rule that blocks the IP list,
so they pass even if they are on the list:
(ip.src in $your_list) and not cf.client.bot.
404 notifications
With not_found_notification=true, each 404 sends a mail containing a link to
/linups-firewall/ban-url. The page needs no login: the link is a signed URL that expires
after ban_link_expires_days, so it cannot be forged or edited. The form is pre-filled with
the requested path, which you can shorten before saving it to the keywords table.
Signed links rely on APP_KEY. Only the path and query are signed, so the link keeps
working behind Cloudflare or a load balancer even without trusted proxies.
The form rejects keywords that would ban real visitors or crawlers:
- keywords shorter than 4 characters;
- keywords that occur in the site's own base URL (e.g. the domain), because the keyword is matched against the full URL including the host;
- keywords that match the site's own URLs: the paths of named
GETroutes (for routes with parameters, everything below the static prefix, e.g./products/123),/robots.txt,/sitemap.xml,/llms.txt,/favicon.icoand anything under/.well-known/.
Existing keywords are not checked again.
Commands
| Command | Action |
|---|---|
firewall:update-crawler-ips |
Download verified_crawler_ip_lists. A failed list keeps its last good copy (the command then exits with a failure code). |
firewall:unban-verified-crawlers |
One-off cleanup: remove every banned_ips entry the verifier confirms (fresh check, no cache), forget their ban cache keys, then run update:banned-ips-on-cloudflare. Add --dry-run to only list them. |
Scheduled commands
| Command | Time | Action |
|---|---|---|
clear:old-banned-ip |
03:03 | Delete bans older than ban_duration_days. |
update:banned-ips-on-cloudflare |
hourly (:06) | Replace the Cloudflare list with the local bans (IPv6 as /64). Catches IPs whose instant push was rate limited by Cloudflare. When banned_ips is empty it empties the list (an empty PUT; if Cloudflare rejects that, the remaining items are deleted). |
firewall:update-crawler-ips |
04:21 | Refresh the verified crawler IP ranges. |
sync:Keywords |
05:09 | Import keywords from the main project. |
Testing
composer install
composer test