For folks who want a very simplistic block for AI crawlers, I recently added one...

@monkeyninja@10base2.dev

For folks who want a very simplistic block for AI crawlers, I recently added one to the 10base2.dev Mastodon instance that seems to be working reasonably well.

This is still going to be a relatively technical guide but I'll try to simplify it best I can. Note, this is for nginx but could be adapted for Apache pretty easily too.

In your nginx conf.d folder (generally /etc/nginx/conf.d) create a file called "ai-block.conf"). Copy and paste the following into it:

map $http_user_agent $ai {
default 0;
~*GPTBot 1;
~*ChatGPT-User 1;
~*OAI-SearchBot 1;
~*ClaudeBot 1;
~*Claude-Web 1;
~*anthropic-ai 1;
~*PerplexityBot 1;
~*Bytespider 1;
~*CCBot 1;
~*Google-Extended 1;
~*Applebot-Extended 1;
~*Meta-ExternalAgent 1;
~*Amazonbot 1;
~*Diffbot 1;
~*omgili 1;
~*cohere-ai 1;
"~^$" 1;
}

In your site configuration (generally under /etc/nginx/sites-enabled), add the following somewhere in the server block before your first "location" entry:

if ($ai) {
return 403;
}

That's pretty much it. Confirm your config by running sudo nginx -t and assuming everything is copacetic then run sudo systemctl reload nginx to load the new config. Note that this is SUPER basic and only provides protection when the user-agent isn't pretending to be something else, which obviously an AI tool easily could.

That being said, it'll likely block a decent chunk of automated AI crawlers without needing to add a proof-of-work system like Nepenthes or Anubis to your site.

I haven't decided if I want to take this a step further and link this into fail2ban to add IP addresses to a block list. I'd probably have to do it using the real_ip module to avoid blocking edge traffic but...hrmm....might be worth it. I'll add that in here if I decide to do it.

Anyway there you go, super simple setup with no real server impact. You can test if it works by running a curl -A command against your site with one of the blocked user agents. e.g. curl -A "GPTBot" -I fu.bar/ should give you a 403 but curl -A "Mozilla/5.0" -I fu.bar/ should give you a 200.