From 04785d70a24baff53f3fded19e8847fabf646046 Mon Sep 17 00:00:00 2001 From: Grant Slater Date: Mon, 14 Sep 2026 21:19:51 +0100 Subject: [PATCH] Add some AI scraper blocks --- cookbooks/dev/templates/default/apache.user.erb | 1 + cookbooks/mediawiki/templates/default/apache.erb | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/cookbooks/dev/templates/default/apache.user.erb b/cookbooks/dev/templates/default/apache.user.erb index b3e9e92a2..f7223b115 100644 --- a/cookbooks/dev/templates/default/apache.user.erb +++ b/cookbooks/dev/templates/default/apache.user.erb @@ -32,6 +32,7 @@ WSGIDaemonProcess <%= @user %>.dev.openstreetmap.org user=<%= @user %> processes # Prevent abuse by an anonymous AI bot RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$ + RewriteCond %{SERVER_PROTOCOL} =HTTP/1.1 RewriteCond %{HTTP_REFERER} ^-?$ RewriteCond %{HTTP_USER_AGENT} ((CriOS|Chrome)/[1-9][0-9]?\.0\.|Chrome/1[0-4][0-9]\.0\.|(Firefox|FxiOS)/[1-6]?[0-9]\.|MSIE\ [5-9]\.0|Opera/[8-9]\.|Windows\ NT\ [3-5]\.|Version/[3-5]\.[0-1]) [NC] RewriteRule ^ - [R=429,L] diff --git a/cookbooks/mediawiki/templates/default/apache.erb b/cookbooks/mediawiki/templates/default/apache.erb index 4c8654588..3631da8fa 100644 --- a/cookbooks/mediawiki/templates/default/apache.erb +++ b/cookbooks/mediawiki/templates/default/apache.erb @@ -11,6 +11,12 @@ CustomLog /var/log/apache2/<%= @name %>-access.log combined_extended ErrorLog /var/log/apache2/<%= @name %>-error.log + RewriteCond %{HTTP_REFERER} ^https://<%= @name.gsub('.', '\.') %> [NC] + RewriteCond %{HTTPS} !=on + RewriteCond %{REQUEST_METHOD} =GET + RewriteCond %{REQUEST_URI} ^/w/ + RewriteRule ^ - [R=429,L] + RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/ RedirectPermanent / https://<%= @name %>/ @@ -49,10 +55,19 @@ RewriteCond %{HTTP_USER_AGENT} "^Mozilla/5\.0 \(Windows NT 10\.0; Win64; x64\) AppleWebKit/537\.36 \(KHTML, like Gecko\) Chrome/105\.0\.0\.0 Safari/537\.3$" [NC] RewriteRule ^ - [R=429,L] + # Prevent abuse by an anonymous AI bot RewriteCond %{REQUEST_METHOD} ^(GET|HEAD)$ RewriteCond %{HTTP_REFERER} =https://<%= @name %> RewriteRule ^ - [R=429,L] + # Temporary measure to prevent abuse by an anonymous AI bot + RewriteCond %{HTTP_USER_AGENT} "Chrome/1[0-4][0-9]\." + RewriteCond %{QUERY_STRING} "(^|&)title=Special(?::|%3A)RecentChanges(&|$)" [NC,OR] + RewriteCond %{QUERY_STRING} "(^|&)returnto=Special(?::|%3A|%253A)RecentChanges(&|$)" [NC,OR] + RewriteCond %{QUERY_STRING} "feedrecentchanges" [NC] + RewriteCond %{REQUEST_URI} ^/w/ + RewriteRule ^ - [R=429,L] + # Historical Compatibility Links RedirectMatch 301 ^/index\.php$ /w/index.php RedirectMatch 301 ^/index\.php/(.*)$ /wiki/$1 -- 2.47.3