以下示例介绍了使用 Cloudflare API 管理和配置 WAF 内容扫描的常用方案。
如果您使用的是 Terraform,请参阅 Terraform 配置示例。
以下 API 示例涵盖了启用和禁用 WAF 内容扫描等基本操作。
要启用内容扫描,请使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/enable" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"要禁用内容扫描,请使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/disable" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"要获取内容扫描功能的当前状态,请使用类似于以下的 GET 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/settings" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"以下 API 示例涵盖了针对内容扫描自定义扫描表达式的操作。
要获取现有自定义扫描表达式的列表,请使用类似于以下的 GET 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": [
{
"id": "<EXPRESSION_ID>",
"payload": "lookup_json_string(http.request.body.raw, \"file\")"
}
],
"success": true,
"errors": [],
"messages": []
}使用类似于以下的 POST 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '[
{
"payload": "lookup_json_string(http.request.body.raw, \"file\")"
}
]'使用类似于以下的 DELETE 请求:
Required API token permissions
At least one of the following token permissions is required:Zone WAF WriteAccount WAF Write
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/content-upload-scan/payloads/$EXPRESSION_ID" \
--request DELETE \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"