I’ve been reviewing a recent attack on a server and it has become clear that Cloudflare does not proxy every request, all of the time. This has behaviour has come unexpectedly to me and seems to defeat the purpose. Can anyone shed any light on this? I believe my settings are pretty standard.
Considering you had Cloudflare headers in both requests it would seem as if both requests came through Cloudflare (unless whoever sent that request added these headers manually).
Are you rewriting IP address? If so the second request would be to be expected and the question would be why isnt it being rewritten in the first one. Maybe a configuation glitch.
If you are not, the second request likely did come via a direct request and the headers were added manually. In this case some would be aware of your actual IP address. That would not be Cloudflare related however.
Doing this arbitrarily in a “random” sub routine is probably not really ideal, but generally it is a good idea to rewrite the IP address to the client one, otherwise you always end up with Cloudflare’s IP addresses. In case you are using Apache you can use mod_remoteip to do so.