Add custom header if the request IP is a known bot?

Is it possible to add custom header if the request IP is a known bot?

I’m not looking to block requests or use Bot management or anything like that. I just want our app to know if the request is coming from a known bot like Google Bot for example.

e.g: If known bot → allow and add a custom header to request (X-KNOWN-BOT = 1).

Is that possible?

You can try to use a Transform Rule

The example here is close to what you are looking to do. The field cf.bot_management.score is an Enterprise only field, but cf.client.bot is the field you are looking for.

(I have not tested this myself, but I think it should work)

2 Likes

Thanks Michael!

I did check it out and i didn’t find “Known bots” in the dropdown (unlike the firewall menu) so i thought it wouldn’t be supported even if i wrote the expression manually.

You have to run the transform against all requests, and add the value of cf.client.bot to everything. It should say true/false, rather than only being present for known bots. The end result is (roughly) the same. (Again, I have not checked the resulting request headers on my origin)

3 Likes

Just confirmed now. That does work Michael! it adds the header with either “true” or “false” as the value, i even checked by simulating a request using google search console. you rock!

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.