多くの組織では、特定の HTTP リクエストヘッダーの有無でトラフィックを判定します。Rules 言語の HTTP リクエストヘッダーフィールド を使い、特定ヘッダーを持つリクエストを対象にします。
このカスタムルールの例では、http.request.headers.names フィールドで X-CSRF-Token ヘッダーの有無を調べます。lower() 変換関数でヘッダー名を小文字にし、式を大文字小文字を区別しないようにします。
X-CSRF-Token ヘッダーがない場合、Cloudflare はリクエストをブロックします。
-
When incoming requests match:
式エディターを使います。
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
このカスタムルールの例では、http.request.headers フィールドで X-Example-Header ヘッダーの有無と値(ある場合)を調べます。X-Example-Header ヘッダーがない、または値が example-value でない場合、Cloudflare はリクエストをブロックします。
-
When incoming requests match:
式エディターを使います。
not any(http.request.headers["x-example-header"][*] eq "example-value") and (http.request.uri.path eq "/somepath") -
Then take action: Block
http.request.headers フィールドのキー(HTTP ヘッダー名に対応)は小文字です。
この例では、ヘッダー名は大文字小文字を区別しませんが、ヘッダー値は区別します。