shiichan

Rules Gets coalesce() for Handling Missing Values

Hi, Shii-chan here! Today I have a small but handy Rules update!

Cloudflare Changelog developers.cloudflare.com

What was announced?

The Cloudflare Changelog announced a new coalesce() function for Rules expressions. It returns the first argument that is not nil.

What changes

When a rule uses a value that might not exist, such as a query parameter, you can now write the fallback value right inside the expression.

Dive Deep

Here is the example from the post:

http.request.uri.path eq coalesce(http.request.uri.args["expected_path"][0], "/")

If the expected_path query parameter exists, its value is used. Otherwise the comparison uses /. For details, see the coalesce() function reference linked in the post!

Wrap-up

  • coalesce() returns the first argument that is not nil
  • You can write fallbacks for missing values inside the expression

A nice trick for anyone writing detailed WAF or redirect rules!