Require specific HTTP headers

Last updated May 5, 2026 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.

Was this helpful?

YesNo

On this page

Require specific HTTP headers - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/waf/custom-rules/use-cases/require-specific-headers/#page","headline":"Require specific HTTP headers","description":"Require specific HTTP headers in incoming requests.","url":"https://developers.cloudflare.com/waf/custom-rules/use-cases/require-specific-headers/","inLanguage":"en","image":"https://developers.cloudflare.com/waf/custom-rules/use-cases/require-specific-headers/og.png?v=989b04b8e103a6c2","dateModified":"2026-05-05","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["Headers"]}


description: Restrict traffic to specific HTTP ports. title: Require specific HTTP ports image: https://developers.cloudflare.com/waf/custom-rules/use-cases/require-specific-http-ports/og.png?v=954d004f0c893fdc


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/waf/llms.txt
Use this file to discover all available pages before exploring further.