许多组织根据特定 HTTP 请求标头的存在来验证流量。使用规则语言 HTTP 请求标头字段定位具有特定标头的请求。
此示例自定义规则使用 http.request.headers.names 字段查找是否存在 X-CSRF-Token 标头。lower() 转换函数将标头名称转换为小写,以使表达式不区分大小写。
当缺少 X-CSRF-Token 标头时,Cloudflare 会阻止请求。
-
当传入请求匹配时:
使用表达式编辑器:
not any(lower(http.request.headers.names[*])[*] eq "x-csrf-token") and (http.request.full_uri eq "https://www.example.com/somepath") -
然后采取操作:阻止
此示例自定义规则使用 http.request.headers 字段查找是否存在 X-Example-Header 标头并获取其值(如果有)。当缺少 X-Example-Header 标头或其值不为 example-value 时,Cloudflare 会阻止请求。
-
当传入请求匹配时:
使用表达式编辑器:
not any(http.request.headers["x-example-header"][*] eq "example-value") and (http.request.uri.path eq "/somepath") -
然后采取操作:阻止
与 HTTP 标头名称相对应的 http.request.headers 字段中的键采用小写。
在此示例中,标头名称不区分大小写,但标头值区分大小写。