この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
レート制限ルールを使用することにより、特定の式に一致するリクエストのレート制限を指定し、そのレート制限に達したときにアクションを実行できます。レート制限ルールを使用して、特定のトラフィックパターンをターゲットにしてボットなどの脅威に対抗することで、ストアフロントの可用性を向上することができます。
このガイドでは、関連するさまざまなレート制限パラメーターの概要とともに、CDN-API を使用してこれらのルールをゾーンで有効にする方法について説明します。このページの下部にあるよくある質問 (FAQ) セクションも参照してください。
レート制限ルールの動作は、レート制限パラメーターの数によって異なります。
descriptionAPI での使用: expression
ルールをいつ適用するかを定義します。ルール式は、true または false のいずれかに評価されます。ルール式が true と評価された場合、ルールが実行されます。レート制限ルールの場合、ルールのアクションは、その時点でレート制限条件が満たされている場合にのみ適用されます。
比較演算子:
eq, ne, contains, matches, in, lt, le, gt, ge論理演算子:
not, and, or, xor関数:
| 関数 | 説明 | 式での使用法 | タイプ | 例 |
|---|---|---|---|---|
| any | 引数の比較演算子が、引数配列の値の いずれか に対して true を返す場合に true を返します。それ以外の場合は false を返します。 | any(Array<Boolean>) | Boolean | any(http.request.headers[\"content-type\"][*] eq \"application/x-www-form-urlencoded\") |
| all | 引数の比較演算子が、引数配列の すべて の値に対して true を返す場合に true を返します。それ以外の場合は false を返します。 | all(Array<Boolean>) | Boolean | all(http.request.headers[\"content-type\"][*] eq \"application/json\") |
| concat | コンマで区切られた値のリストを取ります。引数の値を 1 つの String (文字列) に連結します。 | concat( String | Integer | Bytes | Array elements) | String | concat(http.request.uri.path,\"String\") eq \"sampleString\" |
| ends_with | ソースが、指定された部分文字列で終わる場合に true を返します。それ以外の場合は false を返します。ソースをリテラル値 ("foo" など) にすることはできません。 | ends_with(sourceString, substringString) | Boolean | ends_with(http.request.uri.path, \".html\") |
| len | String (文字列) フィールドまたは Bytes (バイト) フィールドのバイト長を返します。 | len(String | Bytes) | Integer | len(http.host) lt 20 |
| lookup_json_integer | field に指定された key に関連付けられた整数値を返します。注: field は、有効な JSON ドキュメントの文字列表現である必要があります。key は、属性名、JSON 配列内の 0 から始まる位置番号、またはこれら 2 つのオプションの組み合わせ (追加の関数パラメーターとして) にすることができますが、JSON ドキュメントの階層に従って特定の整数値を取得します。この関数は、通常の整数に対してのみ機能します。たとえば、42.0 などの小数点以下がゼロの浮動小数点数では機能しません。 | lookup_json_integer(fieldString, keyString | Integer [, keyString | Integer , …]) | Integer | lookup_json_integer(http.cookie, \"sampleCookie\") eq 10 lookup_json_integer(http.cookie, 1) eq 10 lookup_json_integer(http.cookie, 1, \"sampleCookie \") eq 10 |
| lookup_json_string | field に指定された key に関連付けられた文字列の値を返します。注: field は、有効な JSON ドキュメントの文字列表現である必要があります。key は、属性名、JSON 配列内の 0 から始まる位置番号、またはこれら 2 つのオプションの組み合わせ (追加の関数パラメーターとして) にすることができますが、JSON ドキュメントの階層に従って特定の整数値を取得します。 | lookup_json_string(fieldString, keyString | Integer [, keyString | Integer, …]) | String | lookup_json_string(http.cookie, \"sampleCookie\") eq \"sampleString\" lookup_json_string(http.cookie, 1) eq \"sampleString\" lookup_json_string(http.cookie, 1, \"sampleCookie\") eq \"sampleString\" |
| lower | 文字列フィールドを小文字に変換します。大文字の ASCII バイトのみが変換されます。他のすべてのバイトは影響を受けません。 | lower(String) | String | lower(http.host) eq \"www.example.com\" |
| starts_with | ソースが、指定された部分文字列で始まる場合に true を返します。それ以外の場合は false を返します。ソースをリテラル値 ("foo" など) にすることはできません。 | starts_with(sourceString, substringString) | Boolean | starts_with(http.request.uri.path, \"/blog\") |
| substring | start バイトインデックスから end バイトインデックスまで (ただし、end バイトインデックスを除く) の field 値の一部 (文字列またはバイトフィールドの値) を返します。field の最初のバイトは、インデックス 0 です。オプションの end インデックスを指定しない場合、関数は start インデックスから文字列の末尾までの文字列の一部を返します。end インデックスは start インデックスより大きくなければなりません。start インデックスと end インデックスは負の整数値にすることができ、これにより、文字列の先頭ではなく末尾の文字にアクセスできます。 | substring(fieldString | Bytes, startInteger [, endInteger]) | String | substring(http.request.uri.path, 2, 5) eq \"sampleString\" substring(http.request.uri.path, 2) eq \"sampleString\" |
| upper | 文字列フィールドを大文字に変換します。小文字の ASCII バイトのみが変換されます。他のすべてのバイトは影響を受けません。 | upper(String) | String | upper(http.host) eq \"WWW.EXAMPLE.COM\" |
| url_decode | 次のように source で定義された URL 形式の文字列をデコードします。- %20 と + を空白文字 (“) にデコードします。options パラメーターはオプションです。すべてのオプションは、引用符で囲まれた単一の文字列として指定する必要があります (例: "r" や "ur")。使用可能なオプションは次のとおりです。- r: 再帰的デコードを適用します。たとえば、%2520 は空白文字に 2 回 (再帰的に) デコードされます。- u: Unicode パーセントのデコードを有効にします。たとえば、%E2%98%81%EF%B8%8F は雲の絵文字にデコードされます。 | url_decode(sourceString [, optionsString]) | String | url_decode(http.request.full_uri) contains \"sampleString\" url_decode(http.request.full_uri, \"ur\") contains \"sampleString\"g”’ |
フィールド:
廃止予定の値 ip.geoip.asnum、ip.geoip.country、ip.geoip.continent は、それぞれ ip.src.asnum、ip.src.country、ip.src.continent に置き換えられました。
Note
| フィールド | 説明 | 式での使用法 | タイプ | 例 |
|---|---|---|---|---|
| AS Number | クライアント IP アドレスに関連付けられた自律システム (AS) 番号。 | ip.src.asnum | Integer | ip.src.asnum eq 12345 |
| Cookie | Cookie 全体を文字列として表します。 | http.cookie | String | http.cookie eq \"session=8521F670545D7865F79C3D7BEDC29CCE;-background=light\" |
| Country | ISO 3166-1 Alpha 2 形式の 2 文字の国コードを表します。 | ip.src.country | String | not ip.src.country eq \"US\" |
| Host Name | 完全なリクエスト URI で使用されるホスト名を表します。 | http.host | String | http.host eq \"www.example.com\" |
| IP Address | クライアントの TCP IP アドレスを表します。 | ip.src | IP address | ip.src in {93.184.216.34 192.168.123.132} |
| HTTP Headers | HTTP リクエストヘッダーを Map (または連想配列) として表します。 | http.request.headers | Map\String\Array | any(http.request.headers[\"content-type\"][*] eq \"application/json\") |
| URI Full | Web サーバーが受信した完全な URI を表します。 | http.request.full_uri | String | http.request.full_uri eq \"https://www.example.com/path/index?section=123456&expand=comments\" |
| URI | リクエストの URI パスとクエリ文字列を表します。 | http.request.uri | String | http.request.uri eq \"/path/index?section=123456&expand=comments\" |
| URI Path | リクエストの URI パスを表します。 | http.request.uri.path | String | http.request.uri.path eq \"/path/index\" |
| URI Query String | ? 区切り文字を除いたクエリ文字列全体を表します。 | http.request.uri.query | String | http.request.uri.query eq \"section=123456&expand=comments\" |
| Raw URI Full | http.request.full_uri 非 raw フィールドと同様です。Web サーバーが受信した完全な URI を表します。URI フラグメント (存在する場合) は含まれず、変換も行われません。この raw フィールドには、HTTP サーバーによる基本的な正規化が含まれる場合があることに注意してください。 | raw.http.request.full_uri | String | raw.http.request.full_uri eq \"https://www.example.com/path/index?section=123456&expand=comments\" |
| Raw URI | http.request.uri 非 raw フィールドと同様です。リクエストの URI パスとクエリ文字列を変換せずに表します。この raw フィールドには、HTTP サーバーによる基本的な正規化が含まれる場合があることに注意してください。 | raw.http.request.uri | String | raw.http.request.uri eq \"/path/index?section=123456&expand=comments\" |
| Raw URI Path | http.request.uri.path 非 raw フィールドと同様です。リクエストの URI パスを変換せずに表します。この raw フィールドには、HTTP サーバーによる基本的な正規化が含まれる場合があることに注意してください。 | raw.http.request.uri.path | String | raw.http.request.uri.path eq \"/path/index\" |
| Raw URI Query String | http.request.uri.query 非 raw フィールドと同様です。? 区切り文字と変換を含まないクエリ文字列全体を表します。この raw フィールドには、HTTP サーバーによる基本的な正規化が含まれる場合があることに注意してください。 | raw.http.request.uri.query | String | raw.http.request.uri.query eq \"section=123456&expand=comments\" |
| HTTP Referer | 現在リクエストされているページにリンクされている Web ページのアドレスを含む HTTP Referer リクエストヘッダーを表します。 | http.referer | String | http.referer contains \"www.example.com\" |
| User Agent | HTTP ユーザーエージェントを表します。これはクライアントオペレーティングシステムと Web ブラウザーの識別を可能にする特性文字列を含むリクエストヘッダーです。 | http.user_agent | String | http.user_agent eq \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.61 Safari/537.36\" |
| Request Method | HTTP メソッドを表し、大文字の文字列として返されます。 | http.request.method | String | http.request.method eq \"GET\" |
| Continent | クライアント IP アドレスに関連付けられた大陸コードを表します。AF – アフリカAN – 南極大陸AS – アジアEU – ヨーロッパNA – 北アメリカOC – オセアニアSA – 南アメリカT1 – Tor ネットワーク | ip.src.continent | String | ip.src.continent in {\"NA\" \"EU\"} |
| Bot Score* | リクエストがボットから発信された可能性を 1 ~ 99 のスコアで表します。スコアが低い場合は、リクエストがボットまたは自動エージェントからのものであることを示します。 | cf.bot_management.score | Integer | cf.bot_management.score le 10 |
| Threat Score | 0 ~ 100 の脅威スコアを表します。0 はリスクが低いことを示します。10 を超える値はスパマーまたはボットを表している可能性があり、40 を超える値はインターネット上の悪意ある人物を識別します。 60 を超える値はまれです。一般的な推奨事項は、10 を超えるスコアのリクエストにチャレンジを提示し、50 を超えるリクエストをブロックすることです。 | cf.threat_score | Integer | cf.threat_score gt 50 |
| JA3 Fingerprint* | 潜在的なボットリクエストの識別に役立つ SSL/TLS フィンガープリントを提供します。 | cf.bot_management.ja3_hash | String | cf.bot_management.ja3_hash eq \"e7d705a3286e19ea42f587b344ee6865\" |
| Verified Bot* | true の場合、このフィールドはリクエストが既知の良好なボットまたはクローラーから発信されたことを示します。cf.client.bot と同じ情報を提供します。 | cf.bot_management.verified_bot | Boolean | cf.bot_management.verified_bot |
cf.bot.management.* フィールドを使用するには、ボット管理を有効にして独自の Cloudflare アカウント (o2o) を実装する必要があります。
Note
レート制限ルール式の長さは最大 4096 文字です。
Important
characteristics| 特性 | 説明 | 特性配列での使用法 |
|---|---|---|
| IP | クライアントの TCP IP アドレスに基づいてリクエストをグループ化します。 | ip.src |
| NAT サポート付き IP | 同じ IP アドレスを共有する NAT のもとでのリクエストなどの状況を含め、プライバシー保護技術を使用してユニーク訪問者数を識別します。 | cf.unique_visitor_id |
同じレート制限ルールの特性として「 NAT サポート付き IP 」と「 IP 」の両方を使用することはできないことに注意してください。したがって、API の使用例は次のとおりです。
"characteristics": ["ip.src"]
または
"characteristics": ["cf.unique_visitor_id"]
推奨事項は、NAT サポート付きの IP を使用することです。詳細については、よくある質問 (FAQ) を参照してください。
Note
actionblock、log、legacy_captcha、js_challenge、managed_challenge
period10、60、120、300、600、または 3600 (秒単位) です。requestsPerPeriodmitigationTimeout0、10、60、120、300、600、3600、または 86400 (秒単位) です。
mitigationTimeout の値も、定義された period 以上である必要があります。countingExpression| フィールド | 説明 | カウント式での使用法 | タイプ | 例 |
|---|---|---|---|---|
| HTTP Response Code | クライアントに返される HTTP ステータスコードを表します。 | http.response.code | Integer | “http.response.code eq 400 |
enabledtrue です。API での使用: position
このパラメーターを指定すると、ルールセット内の特定の相対位置にルールが挿入されます。このパラメータは、レート制限ルールを作成または更新するときに使用できます。
1# Places the rule before rule <RULE_ID>
2
3"position": {
4 "before": "<RULE_ID>"
5}
6
7or
8
9# Places the rule after rule <RULE_ID>
10
11"position": {
12 "after": "<RULE_ID>"
13}次のセクションでは、レート制限ルールの一般的なユースケースについて説明します。これらの例を使用し、必要に応じて組み合わせて、独自のビジネスニーズに合わせて調整してください。
http.user_agent eq "MobileApp"http.request.uri.path eq "/status" and http.request.method eq "GET" and not ip.src in { <defined IPs> }http.host eq "example.com" and http.request.uri.path eq "/login" and http.request.method eq "POST"http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403}http.host eq "example.com" and http.request.uri.path eq "/login"http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403}http.request.uri.path eq "/merchant" and http.request.uri.query contains "action=lookup_price"http.host eq "example.com"http.response.code in {401 403}bot_management フィールドの使用を検討します。
cf.bot_management.score lt 30 and http.request.uri.query contains "action=delete"次のセクションでは、一般的な使用例について説明します。
このエンドポイントは、指定されたゾーンのレート制限ルールを作成します。
新しく作成されたルールはデフォルトで有効になり、特に指定のない限り、ルールセットの最後に追加されます。1 つのゾーンで設定できるレート制限ルールは最大 50 件です。
Important
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/rate-limiting/rules" \
2--header "Authorization: Bearer $TOKEN" \
3--header 'Content-Type: application/json' \
4--data '{
5 "description": "Rate limit form traffic",
6 "expression": "http.request.uri.path eq \"/form\"",
7 "characteristics": ["cf.unique_visitor_id"],
8 "action": "block",
9 "period": 60,
10 "requestsPerPeriod": 10000,
11 "mitigationTimeout": 600,
12 "countingExpression": "http.request.uri.path eq \"/form\" and http.response.code eq 400",
13 "enabled": false,
14 "position": {
15 "before": "2c0fc9fa937b11eaa1b71c4d701ab86e"
16 }
17}'成功レスポンス - 201 HttpStatus コードの例 レスポンスボディには、作成されたレート制限ルールが含まれます。
1{
2 "data": {
3 "ruleId": "ffffe61cf25e4ec49c34b029ff3060f7",
4 "description": "Rate limit form traffic",
5 "expression": "http.request.uri.path eq \"/form\"",
6 "characteristics": ["cf.unique_visitor_id"],
7 "action": "block",
8 "period": 60,
9 "requestsPerPeriod": 10000,
10 "mitigationTimeout": 600,
11 "countingExpression": "http.request.uri.path eq \"/form\" and http.response.code eq 400",
12 "enabled": false,
13 "lastUpdated": "2022-12-14T21:25:22.329194Z"
14 }
15}このエンドポイントは、指定されたゾーンのすべてのレート制限ルールを優先順位に従って返します。レート制限ルールが存在しない場合は、404 (Not Found) レスポンスが返されます。
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/rate-limiting/rules" \
2--header "Authorization: Bearer $TOKEN" \
3--header 'Content-Type: application/json'成功レスポンス - 200 HttpStatus コードの例 レスポンスボディには、指定されたゾーンの現在のレート制限ルールがすべて含まれます。
1{
2 "data": [
3 {
4 "ruleId": "ffffe61cf25e4ec49c34b029ff3060f7",
5 "description": "Rate limit form traffic",
6 "expression": "http.request.uri.path eq \"/form\"",
7 "characteristics": ["cf.unique_visitor_id"],
8 "action": "block",
9 "period": 60,
10 "requestsPerPeriod": 10000,
11 "mitigationTimeout": 600,
12 "countingExpression": "http.request.uri.path eq \"/form\" and http.response.code eq 400",
13 "enabled": false,
14 "lastUpdated": "2022-12-14T21:25:22.329194Z"
15 },
16 {
17 "ruleId": "2c0fc9fa937b11eaa1b71c4d701ab86e",
18 "description": "Rate limit by AS num",
19 "expression": "ip.src.asnum eq 12345",
20 "characteristics": ["ip.src"],
21 "action": "managed_challenge",
22 "period": 600,
23 "requestsPerPeriod": 1000,
24 "enabled": true,
25 "lastUpdated": "2022-12-14T21:47:24.323223Z"
26 }
27 ]
28}このエンドポイントは、リクエストされたレート制限ルールを返します。リクエストされたルールが存在しない場合は、404 (Not Found) レスポンスが返されます。
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/rate-limiting/rules/$RULEID" \
2--header "Authorization: Bearer $TOKEN" \
3--header 'Content-Type: application/json'成功レスポンス - 200 HttpStatus コードの例 レスポンスボディには、リクエストされたレート制限ルールが含まれます。
1{
2 "data": {
3 "ruleId": "ffffe61cf25e4ec49c34b029ff3060f7",
4 "description": "Rate limit form traffic",
5 "expression": "http.request.uri.path eq \"/form\"",
6 "characteristics": ["cf.unique_visitor_id"],
7 "action": "block",
8 "period": 60,
9 "requestsPerPeriod": 10000,
10 "mitigationTimeout": 600,
11 "countingExpression": "http.request.uri.path eq \"/form\" and http.response.code eq 400",
12 "enabled": false,
13 "lastUpdated": "2022-12-14T21:25:22.329194Z"
14 }
15}このエンドポイントは、リクエストされたレート制限ルールを更新します。リクエストされたルールが存在しない場合は、404 (Not Found) レスポンスが返されます。
countingExpression を設定したが、それを削除したい (したがってルール式のデフォルトにしたい) というシナリオでは、リクエストボディに "countingExpression": "" を含めて値をリセットする必要があります。1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/rate-limiting/rules/$RULEID" \
2--request 'PATCH' \
3--header "Authorization: Bearer $TOKEN" \
4--header 'Content-Type: application/json' \
5--data '{
6 "description": "Log verified bot traffic to form",
7 "expression": "http.request.uri.path eq \"/form\" and cf.bot_management.verified_bot",
8 "characteristics": ["cf.unique_visitor_id"],
9 "action": "log",
10 "period": 10,
11 "requestsPerPeriod": 500,
12 "mitigationTimeout": 60,
13 "countingExpression": ""
14 "enabled": true,
15 "position": {
16 "after": "2c0fc9fa937b11eaa1b71c4d701ab86e"
17 }
18}'成功レスポンス - 200 HttpStatus コードの例 レスポンスボディには、リクエストされたレート制限ルールが含まれます。
1{
2 "data": {
3 "ruleId": "ffffe61cf25e4ec49c34b029ff3060f7",
4 "description": "Log verified bot traffic to form",
5 "expression": "http.request.uri.path eq \"/form\" and cf.bot_management.verified_bot",
6 "characteristics": ["cf.unique_visitor_id"],
7 "action": "block",
8 "period": 60,
9 "requestsPerPeriod": 10000,
10 "mitigationTimeout": 600,
11 "enabled": false,
12 "lastUpdated": "2022-12-14T21:25:22.329194Z"
13 }
14}このエンドポイントは、リクエストされたレート制限ルールを削除します。リクエストされたルールが存在しない場合は、404 (Not Found) レスポンスが返されます。
1curl "https://$CODE.api.commercecloud.salesforce.com/cdn/zones/v1/organizations/$ORG/zones/$ZONE/rate-limiting/rules/$RULEID" \
2--request 'DELETE' \
3--header "Authorization: Bearer $TOKEN" \
4--header 'Content-Type: application/json'成功レスポンス - 204 HttpStatus コード (コンテンツなし) の例
http.request.uri.path eq "/path"http.request.uri.path eq "/path"http.request.uri.path eq "/form"http.request.uri.path eq "/form" and http.response.code eq 400http.host eq "example.com"http.request.uri.path eq "/login" and http.request.method eq "POST" and http.response.code in {401 403}x-api-keyX-API-Key の値は同じですが、IP アドレスが 異なる 2 つの受信リクエストは、値の組み合わせが異なるため、別々にカウントされます。さらに、カウンターはデータセンター間で共有はされません。position パラメーターを指定します。