Validating Ray ID
Am working on a PR to forward the Cf-Ray value for a logging context, but would like to be able to validate the value I receive first. Any assistance would be appreciated.
9 Replies
For example if Cf-Ray is
230b030023ae2822-SJC
will it consistently be structured like this and contain as many characters as this?No, the structure isn't guaranteed to that degree and if you rely on it then your application may break years down the line
OK. Do you potentially have a suggestion as to how I can verify that the value is indeed a valid Ray ID provided by CF?
I dont believe you can, unless you have an Enterprise product like http logpush setup on the zone to do a rayid lookup in (but even then you'd hardly be able to do it for every single request)
Is your code going to be running in the request/response flow of some website, like a web server or such?
OK, that's informative.
SaaS application, yes
If the request comes from a Cloudflare IP address then it's probably reasonable to assume the ray id is correct
Specifically one of these https://www.cloudflare.com/en-gb/ips/
IP Ranges | Cloudflare
This page is intended to be the definitive source of Cloudflare’s current IP ranges.
Ah, that could be a good combination. Thank you Erisa!
The above is correct, but I'll add - there isn't really such a thing as an "invalid" ray ID, it's more or less just an integer. It has no real meaning beyond being something you can find in logs, if any logs exist.