このページには、次の API 操作の例があります。
ゾーンまたはアカウントで利用できるルールセットを一覧できます。
API エンドポイントの一覧は ルールセットの一覧と表示 を参照してください。
ゾーンレベルでルールセット一覧を取得する GET リクエスト のレスポンスには、次のルールセットが含まれます。
- デプロイできるマネージドルールセット。
"kind": "managed"で示されます。 - ゾーンレベルのフェーズエントリポイントルールセット(設定済みの場合)。
"kind": "zone"で示されます。 - カスタムルールセット(設定済みの場合)。
"kind": "custom"で示されます。
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteResponse Compression ReadConfig Settings WriteConfig Settings ReadDynamic URL Redirects WriteDynamic URL Redirects ReadCache Settings WriteCache Settings ReadCustom Errors WriteCustom Errors ReadOrigin WriteOrigin ReadManaged headers WriteManaged headers ReadZone Transform Rules WriteZone Transform Rules ReadMass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadHTTP DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset ReadSanitize WriteSanitize ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadBot Management WriteBot Management ReadZone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs ReadLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": [
{
"id": "<ZONE_PHASE_RULESET_ID>",
"name": "Zone-level Ruleset 1",
"description": "Ruleset for http_request_firewall_managed phase at the zone level",
"kind": "zone",
"version": "2",
"last_updated": "2021-03-12T14:11:59.754817Z",
"phase": "http_request_firewall_managed"
},
{
"id": "<CLOUDFLARE_MANAGED_RULESET_ID>",
"name": "Cloudflare Managed Ruleset",
"description": "Created by the Cloudflare security team, this ruleset is designed to provide fast and effective protection for all your applications. It is frequently updated to cover new vulnerabilities and reduce false positives",
"kind": "managed",
"version": "2",
"last_updated": "2021-03-18T14:42:40.972022Z",
"phase": "http_request_firewall_managed"
},
{
"id": "<CLOUDFLARE_OWASP_CORE_RULESET_ID>",
"name": "Cloudflare OWASP Core Ruleset",
"description": "Cloudflare's implementation of the Open Web Application Security Project (OWASP) ModSecurity Core Rule Set. We routinely monitor for updates from OWASP based on the latest version available from the official code repository",
"kind": "managed",
"version": "3",
"last_updated": "2021-03-18T14:42:42.993211Z",
"phase": "http_request_firewall_managed"
}
],
"success": true,
"errors": [],
"messages": []
}アカウントレベルでルールセット一覧を取得する GET リクエスト のレスポンスには、次のルールセットが含まれます。
- デプロイできるマネージドルールセット。
"kind": "managed"で示されます。 - アカウントレベルのフェーズエントリポイントルールセット(設定済みの場合)。
"kind": "root"で示されます。 - カスタムルールセット(設定済みの場合)。
"kind": "custom"で示されます。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": [
{
"id": "<CUSTOM_RULESET_ID>",
"name": "Custom Ruleset 1",
"description": "My custom ruleset",
"kind": "custom",
"version": "10",
"last_updated": "2020-11-23T11:36:24.192361Z",
"phase": "http_request_firewall_custom"
},
{
"id": "<ACCOUNT_PHASE_RULESET_ID>",
"name": "Account-level ruleset for http_request_firewall_managed phase",
"description": "Account-level ruleset for executing one or more Managed Rulesets",
"kind": "root",
"version": "2",
"last_updated": "2021-03-12T14:06:41.323932Z",
"phase": "http_request_firewall_managed"
},
{
"id": "<CLOUDFLARE_MANAGED_RULESET_ID>",
"name": "Cloudflare Managed Ruleset",
"description": "Created by the Cloudflare security team, this ruleset is designed to provide fast and effective protection for all your applications. It is frequently updated to cover new vulnerabilities and reduce false positives",
"kind": "managed",
"version": "5",
"last_updated": "2021-03-18T14:42:40.972022Z",
"phase": "http_request_firewall_managed"
},
{
"id": "<CLOUDFLARE_OWASP_CORE_RULESET_ID>",
"name": "Cloudflare OWASP Core Ruleset",
"description": "Cloudflare's implementation of the Open Web Application Security Project (OWASP) ModSecurity Core Rule Set. We routinely monitor for updates from OWASP based on the latest version available from the official code repository",
"kind": "managed",
"version": "3",
"last_updated": "2021-03-18T14:42:42.993211Z",
"phase": "http_request_firewall_managed"
}
],
"success": true,
"errors": [],
"messages": []
}ゾーンまたはアカウントレベルで、指定 フェーズ の エントリポイントルールセット の定義を取得できます。
エントリポイントルールセットがある場合、API は 200 OK HTTP ステータスコードと、ルールセット定義を返します。
エントリポイントルールセットがない場合、API は 404 Not Found HTTP ステータスコードを返します。
次の GET リクエスト は、ゾーンレベルで http_request_firewall_managed フェーズのエントリポイントルールセット定義を取得します。この場合、エントリポイントルールセットは存在し、ルールを 1 件含みます。
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteResponse Compression ReadConfig Settings WriteConfig Settings ReadDynamic URL Redirects WriteDynamic URL Redirects ReadCache Settings WriteCache Settings ReadCustom Errors WriteCustom Errors ReadOrigin WriteOrigin ReadManaged headers WriteManaged headers ReadZone Transform Rules WriteZone Transform Rules ReadMass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadHTTP DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset ReadSanitize WriteSanitize ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadBot Management WriteBot Management ReadZone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs ReadLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/phases/http_request_firewall_managed/entrypoint" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": {
"id": "<RULESET_ID>",
"name": "Zone-level phase entry point ruleset",
"description": "This ruleset executes a managed ruleset.",
"kind": "zone",
"version": "2",
"rules": [
{
"id": "<RULE_ID>",
"version": "1",
"action": "execute",
"expression": "true",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"last_updated": "2021-03-17T15:42:37.917815Z"
}
],
"last_updated": "2021-03-17T15:42:37.917815Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}次の GET リクエスト は、アカウントレベルで http_request_firewall_managed フェーズのエントリポイントルールセット定義を取得します。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets/phases/http_request_firewall_managed/entrypoint" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"フェーズのエントリポイントルールセット(アカウントおよびゾーンレベル)とカスタムルールセットは、すべてのバージョンを表示できます。マネージドルールセットは、最新バージョンのみ表示できます。
次の GET リクエスト は、ゾーンレベルで http_request_firewall_managed フェーズのエントリポイントルールセットのバージョン 2 に含まれるルールを一覧します。
Required API token permissions
At least one of the following token permissions is required:Response Compression WriteResponse Compression ReadConfig Settings WriteConfig Settings ReadDynamic URL Redirects WriteDynamic URL Redirects ReadCache Settings WriteCache Settings ReadCustom Errors WriteCustom Errors ReadOrigin WriteOrigin ReadManaged headers WriteManaged headers ReadZone Transform Rules WriteZone Transform Rules ReadMass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadHTTP DDoS Managed Ruleset WriteHTTP DDoS Managed Ruleset ReadSanitize WriteSanitize ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadBot Management WriteBot Management ReadZone WAF WriteZone WAF ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs ReadLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/rulesets/phases/http_request_firewall_managed/entrypoint/versions/2" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": {
"id": "<RULESET_ID>",
"name": "Zone-level phase entry point ruleset",
"description": "This ruleset executes a managed ruleset.",
"kind": "zone",
"version": "2",
"rules": [
{
"id": "<RULE_ID>",
"version": "1",
"action": "execute",
"expression": "true",
"action_parameters": {
"id": "<MANAGED_RULESET_ID>"
},
"last_updated": "2021-03-17T15:42:37.917815Z"
}
],
"last_updated": "2021-03-17T15:42:37.917815Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}次の GET リクエスト は、マネージドルールセットのバージョン 2(そのルールセットの最新バージョン)に含まれるルールを一覧します。
マネージドルールセット内の各ルールは、関連するタグまたはカテゴリを持てます。categories フィールドに一覧されます。
Required API token permissions
At least one of the following token permissions is required:Mass URL Redirects WriteMass URL Redirects ReadMagic Firewall WriteMagic Firewall ReadL4 DDoS Managed Ruleset WriteL4 DDoS Managed Ruleset ReadTransform Rules WriteTransform Rules ReadSelect Configuration WriteSelect Configuration ReadAccount WAF WriteAccount WAF ReadAccount Rulesets ReadAccount Rulesets WriteLogs WriteLogs Read
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/rulesets/$MANAGED_RULESET_ID/versions/2" \
--request GET \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"{
"result": {
"id": "<MANAGED_RULESET_ID>",
"name": "Cloudflare Managed Ruleset",
"description": "Created by the Cloudflare security team, this ruleset is designed to provide fast and effective protection for all your applications. It is frequently updated to cover new vulnerabilities and reduce false positives",
"kind": "managed",
"version": "2",
"rules": [
{
"id": "<RULE_1_ID>",
"version": "1",
"action": "log",
"categories": [
"cve-2014-5265",
"cve-2014-5266",
"cve-2014-5267",
"dos",
"drupal",
"wordpress"
],
"description": "Drupal, Wordpress - DoS - XMLRPC - CVE:CVE-2014-5265, CVE:CVE-2014-5266, CVE:CVE-2014-5267",
"last_updated": "2021-03-18T14:42:40.972022Z",
"ref": "<RULE_1_REF>",
"enabled": true
},
{
"id": "<RULE_2_ID>",
"version": "1",
"action": "block",
"categories": ["broken-access-control", "cve-2018-12895", "wordpress"],
"description": "Wordpress - Broken Access Control - CVE:CVE-2018-12895",
"last_updated": "2021-03-18T14:42:40.972022Z",
"ref": "<RULE_2_REF>",
"enabled": true
}
// (...)
],
"last_updated": "2021-03-18T14:42:40.972022Z",
"phase": "http_request_firewall_managed"
},
"success": true,
"errors": [],
"messages": []
}ルールセット表示向けの API メソッドの詳細は ルールセットの一覧と表示 を参照してください。