跳转到内容
搜索文档

常见策略

最后更新 查看 MarkdownAgent 设置

以下策略通常用于保护 HTTP 流量。HTTP 策略按从上到下的顺序进行评估,并应用第一个匹配的策略 —— 始终首先评估的 Do Not Inspect(不检测)策略除外。

有关推荐的基本策略集,请参阅保护您的互联网流量和 SaaS 应用程序

有关其他选择器、运算符和操作的完整列表,请参阅 HTTP 策略页面

阻止网站

阻止通过主机名或 URL 路径访问网站的尝试。根据网站的组织方式,可能需要不同的方法。

按主机名阻止网站

阻止使用某一主机的所有子域名。

选择器 运算符 操作
Host(主机) matches regex(匹配正则) .*example\.com Block(阻止)

在以下 API 示例中,filters: ["http"] 表示这是一个 HTTP(第 7 层)策略。

Create a Zero Trust Gateway rulebash
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": ""
	}'

按 URL 阻止网站

阻止网站的某个部分而不阻止整个网站。例如,您可以阻止特定的 subreddit(例如 reddit.com/r/gaming),而不阻止 reddit.com

选择器 运算符 操作
URL matches regex(匹配正则) /r/gaming Block(阻止)
Create a Zero Trust Gateway rulebash
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)
Create a Zero Trust Gateway rulebash
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 = ""
}

阻止未授权的应用程序

为了将 shadow IT 的风险降至最低,一些组织选择限制其用户对某些基于 Web 的工具和应用程序的访问。例如,以下策略会阻止已知的 AI 工具:

选择器 运算符 操作
应用程序 (Application) in(属于) 人工智能 (Artificial Intelligence) 阻止 (Block)
Create a Zero Trust Gateway rulebash
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 = ""
}

检查用户身份

通过在策略中添加 基于身份的条件,按每个用户或组配置访问权限。

选择器 运算符 逻辑 操作
Application(应用程序) in(属于) Salesforce And(且) Block(阻止)
User Group Names(用户组名称) in(属于) Contractors
Create a Zero Trust Gateway rulebash
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 服务)依赖证书固定(certificate pinning)。这些应用程序验证它们是否直接连接到自己的服务器,并将拒绝 Gateway 的 TLS 检测证书。为了避免连接错误,您必须为这些应用程序添加一条 Do Not Inspect(不检测)HTTP 策略。

Gateway 始终首先评估 Do Not Inspect(不检测) 策略,而不考虑它们在策略列表中的位置。Cloudflare 建议将您的 Do Not Inspect(不检测) 策略移动到列表顶部,以减少混淆。

选择器 运算符 操作
Application(应用程序) in(属于) Do Not Inspect Do Not Inspect(不检测)
Create a Zero Trust Gateway rulebash
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": ""
	}'

检查设备姿态

要求设备安装某些软件或具有其他配置属性。有关设置设备姿态检查的说明,请参阅强制执行设备姿态

强制执行最低操作系统版本

执行操作系统版本检查以确保用户至少运行最低版本。

选择器 运算符 操作
Passed Device Posture Checks(已通过设备姿态检查) in(属于) Minimum OS version Allow(允许)
Create a Zero Trust Gateway rulebash
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,请使用列出设备姿态规则端点。

检查特定文件

执行文件检查以确保用户设备上存在特定文件。

由于每个操作系统的文件路径会有所不同,因此您可以为每个系统配置一个文件检查,并使用 Or 逻辑运算符,仅要求其中一个检查通过即可。

选择器 运算符 逻辑 操作
Passed Device Posture Checks(已通过设备姿态检查) in(属于) macOS File Check Or(或) Allow(允许)
Passed Device Posture Checks(已通过设备姿态检查) in(属于) Linux File Check
Create a Zero Trust Gateway rulebash
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,请使用列出设备姿态规则端点。

强制执行会话持续时间

要求用户在经过一定时间后重新进行身份验证

在远程浏览器中隔离高风险网站

如果您使用的是 浏览器隔离 (Browser Isolation) 附加组件,请参阅我们的常用隔离 (Isolate) 策略列表。

绕过对自签名证书的检测

访问未由公共证书颁发机构签名的证书的源站服务器时,您必须绕过 TLS 解密。

选择器 运算符 操作
Domain(域名) in(属于) internal.example.com Do Not Inspect(不检测)
Create a Zero Trust Gateway rulebash
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 文档 (docx) 且 (And) 阻止 (Block)
下载文件类型 (Download File Types) in(属于) PDF (pdf)
Create a Zero Trust Gateway rulebash
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": ""
	}'

有关受支持文件类型的更多信息,请参阅下载和上传文件类型

隔离或阻止影子 IT 应用程序

隔离由应用程序库发现的尚未审查或目前正在审查的影子 IT (shadow IT) 应用程序,并阻止未获得您组织批准的应用程序。

有关审查影子 IT 应用程序的更多信息,请参阅审查应用程序

1. 隔离未审查或正在审查的应用程序

如果应用程序的批准状态为 UnreviewedIn review,则对其进行隔离。

选择器 运算符 逻辑 操作
Application Status(应用程序状态) is(是) Unreviewed Or(或) Isolate(隔离)
Application Status(应用程序状态) is(是) In review
Create a Zero Trust Gateway rulebash
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": ""
	}'

2. 阻止未批准的应用程序

如果应用程序的批准状态为 Unapproved(未批准),则阻止该应用程序。

选择器 运算符 操作
Application Status(应用程序状态) is(是) Unapproved Block(阻止)
Create a Zero Trust Gateway rulebash
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 服务

要为 Google Drive 流量启用 Gateway 检测,您必须向 Google Drive 添加 Cloudflare 证书

阻止 Google Drive 下载

阻止从 Google Drive 下载文件。

选择器 运算符 逻辑 操作
Application(应用程序) in(属于) Google Drive And(且) Block(阻止)
URL Path & Query(URL 路径与查询) matches regex(匹配正则) .*(e=download|export).*
Create a Zero Trust Gateway rulebash
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 上传

阻止向 Google Drive 上传文件。

选择器 运算符 逻辑 操作
Application(应用程序) in(属于) Google Drive And(且) Block(阻止)
Upload Mime Type(上传 MIME 类型) matches regex(匹配正则) .* And(且)
Host(主机) is not(不是) drivefrontend-pa.clients6.google.com
Create a Zero Trust Gateway rulebash
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 下载

阻止从 Gmail 下载文件。

选择器 运算符 逻辑 操作
Host(主机) is(是) mail-attachment.googleusercontent.com And(且) Block(阻止)
URL Path & Query(URL 路径与查询) is(是) /attachment/u/0
Create a Zero Trust Gateway rulebash
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 翻译代理

阻止使用 Google 翻译来翻译整个网页。

翻译网站时,Google 翻译会使用 translate.goog 域名代理网页。您的用户可能会利用此服务来绕过其他 Gateway 策略。如果您阻止了 translate.goog,用户仍将能够访问 Google 翻译的其他功能。

选择器 运算符 操作
Domain(域名) matches regex(匹配正则) ^(.+\.)?translate\.goog$ Block(阻止)
Create a Zero Trust Gateway rulebash
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": ""
	}'

过滤 WebSocket 流量

Gateway 不会检测或记录 WebSocket 流量。相反,Gateway 仅记录用于建立 WebSocket 连接的 HTTP 详细信息以及网络会话信息。要过滤您的 WebSocket 流量,请创建一条具有 101 HTTP 响应代码的策略。

选择器 运算符 操作
HTTP Response(HTTP 响应) is(是) 101 SWITCHING_PROTOCOLS Allow(允许)
Create a Zero Trust Gateway rulebash
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": ""
	}'

这篇文档对您有帮助吗?