|
8 | 8 | content: Common DNS policies |
9 | 9 | --- |
10 | 10 |
|
11 | | -import { Render, Tabs, TabItem } from "~/components"; |
| 11 | +import { Render, Tabs, TabItem, APIRequest } from "~/components"; |
12 | 12 |
|
13 | 13 | The following policies are commonly used to secure DNS traffic. |
14 | 14 |
|
@@ -68,6 +68,62 @@ The categories included in this policy are not always a security threat, but blo |
68 | 68 | product="cloudflare-one" |
69 | 69 | /> |
70 | 70 |
|
| 71 | +## Block a dynamic list of categories |
| 72 | + |
| 73 | +You can add a list of category IDs to the [EDNS header](https://datatracker.ietf.org/doc/html/rfc6891) of a request sent to Gateway as a JSON object using OPT code `65050`. For example: |
| 74 | + |
| 75 | +```json |
| 76 | +{ |
| 77 | + "categories": [2, 67, 125, 133] |
| 78 | +} |
| 79 | +``` |
| 80 | + |
| 81 | +With the [Request Context Categories](/cloudflare-one/policies/gateway/dns-policies/#request-context-categories) selector, you can block the category IDs sent with EDNS. This is useful to filter by categories not known at the time of creating a policy, or to enforce device-specific DNS content filtering without reaching your account limit. When Gateway uses this selector to block a DNS query, the request will return an Extended DNS Error (EDE) Code 15 - Blocked error, along with a field containing an array of the matched categories. |
| 82 | + |
| 83 | +<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard"> |
| 84 | + |
| 85 | +| Selector | Operator | Value | Action | |
| 86 | +| ------------------------ | -------- | ------- | ------ | |
| 87 | +| Request Context Category | is | _Present_ | Block | |
| 88 | + |
| 89 | +</TabItem> |
| 90 | +<TabItem label="API"> |
| 91 | + |
| 92 | +```bash |
| 93 | +curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/gateway/rule \ |
| 94 | +--header "Content-Type: application/json" \ |
| 95 | +--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ |
| 96 | +--data '{ |
| 97 | + "name": "All-DNS-Bock-Category-Matches-In-Request", |
| 98 | + "description": "Block all category matches in the request EDNS context", |
| 99 | + "enabled": true, |
| 100 | + "action": "block", |
| 101 | + "filters": [ |
| 102 | + "dns" |
| 103 | + ], |
| 104 | + "traffic": "dns.categories_in_request_context_matches", |
| 105 | + "identity": "" |
| 106 | +}' |
| 107 | +``` |
| 108 | + |
| 109 | +</TabItem> |
| 110 | +<TabItem label="Terraform"> |
| 111 | + |
| 112 | +```tf |
| 113 | +resource "cloudflare_zero_trust_gateway_policy" "block_content_categories" { |
| 114 | + account_id = var.cloudflare_account_id |
| 115 | + name = "All-DNS-Bock-Category-Matches-In-Request" |
| 116 | + description = "Block all category matches in the request EDNS context" |
| 117 | + enabled = true |
| 118 | + action = "block" |
| 119 | + filters = ["dns"] |
| 120 | + traffic = "dns.categories_in_request_context_matches" |
| 121 | + identity = "" |
| 122 | +} |
| 123 | +``` |
| 124 | + |
| 125 | +</TabItem> </Tabs> |
| 126 | + |
71 | 127 | ## Block unauthorized applications |
72 | 128 |
|
73 | 129 | <Render file="gateway/policies/block-applications" product="cloudflare-one" /> |
|
0 commit comments