WPSurfer.com

How to Block User Agents in WordPress using CloudFlare

Published on January 28, 2023 | Updated on June 29, 2023

A user agent is a string of text that a web browser or other client software sends to a web server along with each request to identify itself and provide information about its capabilities.

The user agent string can contain information such as the browser name and version, the operating system, and other details.

Site owners can block user agents easily using CloudFlare Firewall Rules known to be associated with malicious activity, such as bots and scrapers

In this post, you will learn all you need to know about blocking user agents for security purposes.


What User Agents to Block?

Some examples of user agents that may be associated with malicious activity and should be blocked for security purposes include:

pythonGo-http-client
curlgithub
ApacheScrapy
rubywp_is_mobile

I check my Firewall logs regularly and I don’t see that many malicious user agents since most malicious automated traffic identify itself as legitimate traffic:

These are some examples of user agents used by bad bots:

Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Firefox/102.0

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0 Safari/537.36

Where to get a List of User Agents to Block?

I know I recommended 8 user agents to block but I don’t really believe in copying someone’s huge list of malicious user agents and building a firewall with it.

Automated traffic with a specific user agent that might be bothering someone’s website and never come close to your site.

So it is a better idea to check your Firewall logs and spot the ones that are trying to attack your site.

Blocking SEO Tools and the Other Guys

Blocking certain types of scrapers or SEO tools can be done by blocking their user agent.

You can block non-malicious bots like Ahrefs, Moz or Search Engines like Yandex

The good thing about blocking these types of services is that these types of bots identify themselves as bots.

Blocking User Agents is not the Ultimate Security Measure

Blocking certain user agents can improve the security of a WordPress site by preventing certain types of bots or automated scripts from accessing the site.

It is also important to note that blocking user agents is not a complete solution to securing a WordPress site.

User agents can be easily faked by malicious actors in order to bypass security measures that are in place to block certain types of user agents. This can be done by modifying the user agent string that is sent with HTTP requests to make it appear as if the request is coming from a different type of device or browser.

For example, a hacker could change their user agent to that of a search engine crawler in order to gain access to parts of a website that are otherwise blocked to regular users.

is Google using OVH servers now?

Bot from OVH servers pretends to be google

When it comes to user agents, you can be any big organization you want.

It is important to note that, while blocking specific user agents can be an effective security measure, it is not foolproof, as malicious actors can easily change or spoof their user agent to bypass these restrictions. Therefore, it’s recommended to use a combination of security measures to protect your website, such as using a web application firewall and monitoring traffic for unusual behavior.

How to Block User Agents with Cloudflare Firewall Rules

Blocking user agents with Cloudflare is a simple process that can help protect your website from unwanted traffic or bots. Here’s how to do it:

  1. Log into your Cloudflare account and select the website that you want to block user agents for.
  2. Click on the “Security” tab, then click on the “WAF” button.
  3. Click on the “create firewall rule” button
  4. Name the rule
  5. Choose “user agent” from the field dropdown menu
  6. Choose “contains” from the field dropdown menu
  7. Add a keyword in the “value” field
  8. use “or” to target other user agents
  9. Choose “block
  10. Click the “Deploy Firewall Rule” button
Block User Agents with CloudFlare Firewall Rules

As you can see, the process is really simple.

You can update remove or add more keyword as you consider necessary

More about WordPress Security

These are other posts that you might want to check

Manuel Campos

Manuel Campos

I am José Manuel. I am writing about things I know and things that I am learning about WordPress. I hope you find the content of this blog useful.