Skip to main content

How to block Google API

Operated by Google. APIs-Google is the user agent used by Google APIs to deliver push notification messages. Application developers can request these notifications to avoid the need for continually polling Google's servers to find out if the resources they are interested in have changed. To make sure nobody abuses this service, Google requires developers to prove that they own the domain before allowing them to register a URL with a domain as the location where they want to receive messages.

How it identifies itself

APIs-Google (+https://developers.google.com/webmasters/APIs-Google.html)

robots.txt

What the agent asks to be told. It obeys this or it does not — nothing enforces it.

robots.txt
User-agent: APIs-Google
Disallow: /

nginx

In the server block, then reload.

nginx
# In the server block. 403 rather than 444: a closed connection tells the
# operator nothing, and an agent that gets a status code can log it.
if ($http_user_agent ~* "(APIs-Google)") {
    return 403;
}

Apache

In .htaccess or the vhost.

Apache
BrowserMatchNoCase "APIs-Google" bad_bot

<RequireAll>
    Require all granted
    Require not env bad_bot
</RequireAll>

Cloudflare

Security → WAF → Custom rules.

Cloudflare
# Security → WAF → Custom rules, action: Block
(http.user_agent contains "APIs-Google")

WordPress

A child theme's functions.php, or a small plugin.

WordPress
// functions.php of a child theme, or a small plugin. Runs before WordPress
// builds the page, so a blocked agent costs one PHP process and no queries.
add_action('init', function () {
    $agent = $_SERVER['HTTP_USER_AGENT'] ?? '';

    foreach (['APIs-Google'] as $needle) {
        if (stripos($agent, $needle) !== false) {
            status_header(403);
            exit('Blocked: Google API');
        }
    }
});

robots.txt is a request. The rules below it are the wall.

Google API publishes a token, so the directive above will work for as long as it keeps honouring it — and nothing except its own good manners makes it. The server rules match on a header the requester sets, which stops the agent that says who it is and not the one that copies somebody else's name. Botscope verifies identity against DNS and published address ranges, records which check decided each request, and shows you the ones that lied.

Others like it

Everything we know about Google API