次のポリシーは、HTTP トラフィックの保護によく使われます。HTTP ポリシーは上から下の順に評価され、最初に一致したポリシーが適用されます。ただし Do Not Inspect ポリシーは例外で、常に最初に評価されます。
推奨する基本ポリシーは、インターネットトラフィックと SaaS アプリを保護する を参照してください。
その他のセレクター、演算子、アクションの一覧は、HTTP ポリシーのページ を参照してください。
ホスト名または URL パスで、サイトへの到達をブロックします。サイトの構成に応じて、方法を変える必要があります。
特定のホストを使うサブドメインをすべてブロックします。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Host | matches regex | .*example\.com |
Block |
次の API の例では、filters: ["http"] はこのポリシーが HTTP(レイヤー 7)であることを示します。
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block sites by hostname",
"description": "Block all subdomains that use a specific hostname",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "http.request.host matches \".*example.com\"",
"identity": "",
"device_posture": ""
}'サイト全体をブロックせず、一部だけをブロックします。たとえば reddit.com は残し、reddit.com/r/gaming のような特定のサブレディットだけをブロックできます。
| Selector | Operator | Value | Action |
|---|---|---|---|
| URL | matches regex | /r/gaming |
Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block sites by URL",
"description": "Block specific parts of a site without blocking the hostname",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "http.request.uri matches \"/r/gaming\"",
"identity": "",
"device_posture": ""
}'組織の利用ポリシーに反するコンテンツカテゴリをブロックします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Content Categories | in | Questionable Content, Security Risks, Miscellaneous, Adult Themes, Gambling | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-HTTP-ContentCategories-Blocklist",
"description": "Block access to questionable content and potential security risks",
"precedence": 40,
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(http.request.uri.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161 2 67 125 133 99})",
"identity": "",
"device_posture": ""
}'resource "cloudflare_zero_trust_gateway_policy" "block_unauthorized_apps" {
account_id = var.cloudflare_account_id
name = "All-HTTP-ContentCategories-Blocklist"
description = "Block access to questionable content and potential security risks"
precedence = 40
enabled = true
action = "block"
filters = ["http"]
traffic = "any(http.request.uri.content_category[*] in {17 85 87 102 157 135 138 180 162 32 169 177 128 15 115 119 124 141 161 2 67 125 133 99})"
identity = ""
device_posture = ""
}シャドーIT のリスクを抑えるため、一部の組織はユーザーが使えるウェブツールやアプリケーションを制限します。たとえば、次のポリシーは既知の AI ツールをブロックします。
| セレクター | 演算子 | 値 | アクション |
|---|---|---|---|
| Application | in | Artificial Intelligence | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "All-HTTP-Application-Blocklist",
"description": "Limit access to shadow IT by blocking web-based tools and applications",
"precedence": 60,
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(app.type.ids[*] in {25})",
"identity": "",
"device_posture": ""
}'resource "cloudflare_zero_trust_gateway_policy" "all_http_application_blocklist" {
account_id = var.cloudflare_account_id
name = "All-HTTP-Application-Blocklist"
description = "Limit access to shadow IT by blocking web-based tools and applications"
precedence = 60
enabled = true
action = "block"
filters = ["http"]
traffic = "any(app.type.ids[*] in {25})"
identity = ""
device_posture = ""
}ポリシーに ID ベースの条件 を追加して、ユーザーまたはグループ単位でアクセスを設定します。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Application | in | Salesforce | And | Block |
| User Group Names | in | Contractors |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Check user identity",
"description": "Block access to Salesforce by temporary employees and contractors",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(app.ids[] in {606})",
"identity": "any(identity.groups.name[] in {\"Contractors\"})",
"device_posture": ""
}'Zoom や Apple のサービスなど、一部のクライアントアプリケーションは証明書ピンニングに依存します。これらのアプリケーションは、自社サーバーへ直接接続していることを確認し、Gateway の TLS 検査用証明書を拒否します。接続エラーを防ぐには、これらのアプリケーション向けに Do Not Inspect の HTTP ポリシーを追加する必要があります。
Gateway は、ポリシー一覧の位置にかかわらず Do Not Inspect ポリシーを最初に評価 します。混乱を減らすため、Do Not Inspect ポリシーは一覧の先頭へ移すことを推奨します。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Application | in | Do Not Inspect | Do Not Inspect |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Bypass incompatible applications",
"description": "Skip TLS decryption for applications that are incompatible with Gateway",
"enabled": true,
"action": "off",
"filters": [
"http"
],
"traffic": "any(app.type.ids[*] in {16})",
"identity": "",
"device_posture": ""
}'特定のソフトウェアがインストールされていることや、その他の構成属性をデバイスに求めます。デバイスポスチャチェックの設定手順は、デバイスポスチャを強制する を参照してください。
OS バージョンチェック を行い、ユーザーが少なくとも最小バージョンを実行していることを確認します。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Passed Device Posture Checks | in | Minimum OS version | Allow |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Require OS version",
"description": "Perform an OS version check for minimum version",
"enabled": true,
"action": "allow",
"filters": [
"http"
],
"traffic": "",
"identity": "",
"device_posture": "any(device_posture.checks.passed[*] in {\"<POSTURE_CHECK_UUID>\"})"
}'デバイスポスチャチェックの UUID を取得するには、List device posture rules エンドポイントを使います。
ファイルチェック を行い、ユーザーのデバイスに特定のファイルがあることを確認します。
ファイルパスは OS ごとに異なるため、各システム向けにファイルチェックを設定し、Or 論理演算子でいずれか 1 つのチェック通過を条件にできます。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Passed Device Posture Checks | in | macOS File Check | Or | Allow |
| Passed Device Posture Checks | in | Linux File Check |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Check for specific file",
"description": "Ensure users have a specific file on their device regardless of operating system",
"enabled": true,
"action": "allow",
"filters": [
"http"
],
"traffic": "",
"identity": "",
"device_posture": "any(device_posture.checks.passed[] in {\"<POSTURE_CHECK_1_UUID>\"}) or any(device_posture.checks.passed[] in {\"<POSTURE_CHECK_2_UUID>\"})"
}'デバイスポスチャチェックの UUID を取得するには、List device posture rules エンドポイントを使います。
一定時間が経過したあと、ユーザーに再認証を求めます。
Browser Isolation アドオン を使っている場合は、よく使う Isolate ポリシー の一覧を参照してください。
公開の認証局が署名していない証明書を使うオリジンサーバーへアクセスする場合は、TLS 復号をバイパスする必要があります。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Domain | in | internal.example.com |
Do Not Inspect |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Bypass internal site inspection",
"description": "Bypass TLS decryption for internal sites with self-signed certificates",
"enabled": true,
"action": "off",
"filters": [
"http"
],
"traffic": "any(http.request.domains[*] in {\"internal.example.com\"})",
"identity": "",
"device_posture": ""
}'ファイルの種類に基づいて、アップロードまたはダウンロードをブロックします。
| セレクター | 演算子 | 値 | 論理 | アクション |
|---|---|---|---|---|
| Upload File Types | in | Microsoft Office Word Document (docx) | And | Block |
| Download File Types | in | PDF (pdf) |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block file types",
"description": "Block the upload or download of files based on their type",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(http.upload.file.types[*] in {\"docx\"}) and any(http.download.file.types[*] in {\"pdf\"})",
"identity": "",
"device_posture": ""
}'対応しているファイルタイプの詳細は、ダウンロードおよびアップロードのファイルタイプ を参照してください。
Application Library で見つかった、未レビューまたはレビュー中のシャドーIT アプリケーションを隔離し、組織が承認していないアプリケーションをブロックします。
シャドーIT アプリケーションのレビューについて詳しくは、アプリケーションをレビューする を参照してください。
承認ステータスが Unreviewed または In review のアプリケーションを隔離します。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Application Status | is | Unreviewed | Or | Isolate |
| Application Status | is | In review |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Isolate unreviewed or in review application status",
"description": "Isolate Shadow IT applications that have not been reviewed or are in review in the Application Library",
"enabled": true,
"action": "isolate",
"filters": [
"http"
],
"traffic": "any(app.statuses[*] == \"unreviewed\") or any(app.statuses[*] == \"in review\")",
"identity": "",
"device_posture": ""
}'承認ステータスが Unapproved のアプリケーションをブロックします。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Application Status | is | Unapproved | Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block unapproved application status",
"description": "Block Shadow IT applications that have been marked as unapproved in the Application Library",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(app.statuses[*] == \"unapproved\")",
"identity": "",
"device_posture": ""
}'Google Drive のトラフィックで Gateway 検査を有効にするには、Cloudflare 証明書を Google Drive に追加 する必要があります。
Google Drive からのファイルダウンロードをブロックします。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Application | in | Google Drive | And | Block |
| URL Path & Query | matches regex | .*(e=download|export).* |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block Google Drive downloads",
"description": "Block file downloads from Google Drive",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(app.ids[] in {554}) and http.request.uri.path_and_query matches \".(e=download|export).*\"",
"identity": "",
"device_posture": ""
}'Google Drive へのファイルアップロードをブロックします。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Application | in | Google Drive | And | Block |
| Upload Mime Type | matches regex | .* |
And | |
| Host | is not | drivefrontend-pa.clients6.google.com |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block Google Drive uploads",
"description": "Block file uploads to Google Drive",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(app.ids[] in {554}) and http.upload.mime matches \".\" and not(http.request.host == \"drivefrontend-pa.clients6.google.com\")",
"identity": "",
"device_posture": ""
}'Gmail からのファイルダウンロードをブロックします。
| Selector | Operator | Value | Logic | Action |
|---|---|---|---|---|
| Host | is | mail-attachment.googleusercontent.com |
And | Block |
| URL Path & Query | is | /attachment/u/0 |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block Gmail downloads",
"description": "Block file downloads from Gmail",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "http.request.host == \"mail-attachment.googleusercontent.com\" and http.request.uri.path_and_query matches \"/attachment/u/0\"",
"identity": "",
"device_posture": ""
}'Google 翻訳で Web ページ全体を翻訳する使い方をブロックします。
Web サイトを翻訳するとき、Google 翻訳は translate.goog ドメインで Web ページをプロキシします。ユーザーはこのサービスを使い、他の Gateway ポリシーを迂回できる場合があります。translate.goog をブロックしても、Google 翻訳の他の機能は使えます。
| Selector | Operator | Value | Action |
|---|---|---|---|
| Domain | matches regex | ^(.+\.)?translate\.goog$ |
Block |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Block Google Translate for websites",
"description": "Block use of Google Translate to translate entire webpages",
"enabled": true,
"action": "block",
"filters": [
"http"
],
"traffic": "any(http.request.domains[*] matches \"^(.+\\.)?translate\\.goog$\")",
"identity": "",
"device_posture": ""
}'Gateway は WebSocket ↗ トラフィックを検査もログ記録もしません。代わりに、WebSocket 接続に使った HTTP の詳細と、ネットワークセッション情報 だけを記録します。WebSocket トラフィックをフィルタリングするには、HTTP 応答コード 101 を使うポリシーを作成します。
| Selector | Operator | Value | Action |
|---|---|---|---|
| HTTP Response | is | 101 SWITCHING_PROTOCOLS | Allow |
curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rules" \
--request POST \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--json '{
"name": "Filter WebSocket",
"description": "Filter WebSocket traffic with HTTP response code 101",
"enabled": true,
"action": "allow",
"filters": [
"http"
],
"traffic": "http.response.status_code == 101",
"identity": "",
"device_posture": ""
}'