[ Web Proxy ]
URL:
Viewing: https://developers.cloudflare.com/waf/custom-rules/use-cases/require-specific-headers/ [Back]  [Original]

Require specific HTTP headers Cloudflare Web Application Firewall (WAF) docsSkip to content
SearchCtrlKLog in
  1. Home
  2. /WAF
  3. /
  4. /Common use cases
  5. /Require specific HTTP headers

Require specific HTTP headers

Last updated May 5, 2026Copy as MarkdownView as MarkdownAgent setup
OverviewExample 1: Require presence of HTTP headerExample 2: Require HTTP header with a specific value

Many organizations qualify traffic based on the presence of specific HTTP request headers. Use the Rules language HTTP request header fields to target requests with specific headers.

Example 1: Require presence of HTTP header

This example custom rule uses the http.request.headers.names field to look for the presence of an X-CSRF-Token header. The lower() transformation function converts the header name to lowercase so that the expression is case-insensitive.

When the X-CSRF-Token header is missing, Cloudflare blocks the request.

  • When incoming requests match:

    Use the expression editor:
    not any(lower(http.request.headers.names[*])[*] eq "x-csrf-token") and (http.request.full_uri eq "https://www.example.com/somepath")

  • Then take action: Block

Example 2: Require HTTP header with a specific value

This example custom rule uses the http.request.headers field to look for the presence of the X-Example-Header header and to get its value (if any). When the X-Example-Header header is missing or it does not have the value example-value, Cloudflare blocks the request.

  • When incoming requests match:

    Use the expression editor:
    not any(http.request.headers["x-example-header"][*] eq "example-value") and (http.request.uri.path eq "/somepath")

  • Then take action: Block

The keys in the http.request.headers field, corresponding to HTTP header names, are in lowercase.

In this example the header name is case-insensitive, but the header value is case-sensitive.

PreviousRequire known IP addresses in site admin areaNextRequire specific HTTP ports

Was this helpful?

YesNo
Edit pageReport issue
[]

Web Proxy Viewer  |  New URL  |  Original Page