Protection
Security
Read and change the bot protection, bot policy, browser coverage, security headers, manipulation detection and mitigation of a domain.
Everything here works on one domain at a time. The paths start with /v2/cdn/security/{domain_public_id}/, where the id is the public id of the domain, taken from the domains list.
The examples on this page use these shell variables:
export DIAMWALL_API_KEY="your key"export SECURITY="https://api.diamwall.com/v2/cdn/security/your-domain-public-id"How the settings work
Section titled “How the settings work”There are six settings groups. Each one has a GET to read it and a PATCH to change it, on the same path.
| Group | Path | What a PATCH takes |
|---|---|---|
| Bot protection | settings/bot/ |
good_bots, bad_bots or both |
| Bot management | settings/bot-management/ |
Any part of the bot policy |
| Browser coverage | settings/browser-coverage/ |
One or more browser families |
| Security headers | settings/headers/ |
One or more of the four headers |
| Manipulation | settings/manipulation/ |
Exactly enabled |
| Mitigation | settings/mitigation/ |
Exactly one of its three fields |
Reading a group
Section titled “Reading a group”Every answer has the same envelope:
{ "revision": "sha256:3f8704ec8bea...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "sameorigin": { "state": "resolved", "value": true }, "hotlinking": { "state": "unknown" } }}- In the bot, headers, manipulation and mitigation groups, each field comes back as
{ "state": "resolved", "value": ... }. Astateofunknownhas novalue. Treat it as unavailable, never asfalse,0or a default. - When the whole group could not be read, the answer has
state: "unknown"at the top, arevisionofnull, nodataand noETag. There is nothing to write against until a read succeeds. publication.rolloutis alwaysunknown. The answer says what is configured. It does not confirm that every point of presence applies it yet.
Writes need the latest revision
Section titled “Writes need the latest revision”A read answers an ETag header, which is the revision of the group. Every PATCH sends it back in If-Match, exactly as it came, with its quotes:
ETAG=$(curl -s -o /dev/null -D - "$SECURITY/settings/headers/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')- Without
If-Matchthe write answers428. If the group changed since your read, it answers412 REVISION_MISMATCHand writes nothing. Read again and retry. - Send only the fields that change. A field you leave out keeps its value. It is never read as
false. - Values are strict JSON. A boolean sent as
"true",1ornullis refused, and so is any field the group does not know. - The answer of a write is the group after the change, with a new
ETagfor your next write.
Read the bot protection
Section titled “Read the bot protection”curl "$SECURITY/settings/bot/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:421b67c6bc2d...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "realtime_protection": { "state": "resolved", "value": true }, "good_bots": { "state": "resolved", "value": true }, "bad_bots": { "state": "resolved", "value": false }, "runtime_wired": { "state": "resolved", "value": false } }}Only good_bots and bad_bots can be changed. realtime_protection and runtime_wired are read-only.
Change the bot protection
Section titled “Change the bot protection”Send good_bots, bad_bots or both, each true or false:
curl -X PATCH "$SECURITY/settings/bot/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "good_bots": true, "bad_bots": true }'An empty body ({}) answers 400 NO_CHANGES. Any other field, realtime_protection included, answers 400 INVALID_REQUEST.
Read the bot policy
Section titled “Read the bot policy”Bot management is a finer policy: an action, a rate, a time window and path rules per bot or per operator.
curl "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:f80b585938cb...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "schema": 1, "configured": true, "publication": "declared", "rollout": "unknown", "policy": { "enabled": true, "bots": { "gptbot": { "enabled": false, "action": "skip" } }, "groups": { "ai:google": { "enabled": true, "action": "allow", "rate": { "enabled": false } } } } }}data.policy holds only what was saved for the domain. Defaults that come from the catalog are not shown here. A domain with nothing saved answers "configured": false and an empty policy.
Field of policy |
What it is |
|---|---|
enabled |
Switches the whole policy on or off. |
default_action |
skip, allow, block, challenge or rate_limit. |
default_rate |
The rate that goes with default_action: rate_limit. Its scope is always ip. |
fake_action |
skip, allow, block or challenge. |
honeypot |
enabled, action (skip, challenge or block) and block_seconds (60 to 604800). |
bots |
A map from bot id to its policy. |
groups |
A map from operator group id, such as ai:google or verified:google, to a policy for all its bots. |
A bot or a group takes these controls:
| Control | Values |
|---|---|
enabled |
false disables the policy. It does not allow the bot. |
action |
skip, allow, block or challenge. |
rate |
See Rates. |
window |
enabled, start and end as HH:MM in UTC. end is exclusive, a window may run past midnight, and equal hours mean all day. Outside the window the bot is blocked. |
paths |
Up to 32 objects with pattern and action (allow or block), in order. The first match wins. A pattern starts with / and may use * and ?. |
crawl_tax |
enabled and delay_ms (0 to 3000). The delay is required when enabled. |
stale_only |
A boolean. Turning it on may answer 409 when the domain cannot support it. |
Change the bot policy
Section titled “Change the bot policy”Read the policy to get its ETag, then send only what changes. Never send the whole GET back.
curl -X PATCH "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "bots": { "gptbot": { "enabled": true, "action": "block" } } }'curl -X PATCH "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "groups": { "ai:google": { "enabled": true, "action": "allow", "rate": { "enabled": true, "rpm": 120, "scope": "bot", "on_exceed": "respond" } } } }'curl -X PATCH "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "bots": { "custom_partner": { "name": "Partner crawler", "enabled": true, "action": "allow", "match": { "user_agents": ["PartnerCrawler/"], "ip_ranges": ["192.0.2.0/24"] } } } }'curl -X PATCH "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "default_action": "rate_limit", "default_rate": { "enabled": true, "rpm": 60, "daily": 1000, "burst": 10, "scope": "ip", "on_exceed": "ban", "ban_seconds": 1800 } }'curl -X PATCH "$SECURITY/settings/bot-management/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "groups": { "ai:google": null }, "bots": { "google_agent": { "action": "block" } } }'Rules for bots:
- Known ids come from the bot catalog. They cannot carry
nameormatch. - A custom id starts with
custom_and needs anameand amatchthat is not empty. matchtakesuser_agents,ip_ranges(CIDR with a prefix),ja4,rdns_suffixesandasns, each a list of at most 64 values. Values are literal, with no regular expressions. A request matches when it matches any value of every list you set.- A request holds at most 128 bots.
nullremoves a bot. - A catalog entry that only configures robots directives takes only
enabled,action(skip,alloworblock) andpaths. It never identifies or authorizes HTTP traffic.
Rules for groups:
- A group replaces the policy of each of its bots as a whole. Fields are not merged, even when the group is disabled.
- While a group applies to a bot, an edit of that bot alone is refused. Removing the group and editing the bot can go in one request, as in the “Remove” example.
- Group rates take only
"scope": "bot". - A request holds at most 64 groups, and a domain at most 64 configured groups.
nullremoves a group.
rate (on a bot or group) and default_rate have the same fields:
| Field | Values |
|---|---|
enabled |
false keeps the saved limits and stops applying them. On a known bot or group, leaving it out keeps the catalog default. |
rpm, daily |
1 to 1000000000, or null to remove that quota. An enabled rate needs at least one. |
burst |
0 to 10000. Adds a ceiling per second of ceil(rpm/60) + burst. |
scope |
bot or ip. |
on_exceed |
respond, challenge, skip or ban. |
ban_seconds |
Needed with ban: 1800, 3600, 10800, 21600, 43200 or 86400. |
response |
Used with respond: a status of 403, 429 or 503, and a plain text message of at most 2048 bytes. |
- The
rpmanddailyperiods are fixed UTC windows. - Quotas are counted per point of presence, never globally.
skipstill counts the requests over the quota.- A ban answers
403with aRetry-Afterheader. More requests during the ban do not extend it. - Claiming a different user agent does not reset the allowance of
default_rate.
List the known bots
Section titled “List the known bots”The catalog lists the bot ids and operator groups you can use in the bot policy.
curl "$SECURITY/references/bot-catalog/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "data": { "state": "resolved", "items": [ { "id": "adsbot", "operator_id": "google", "section": "verified_bots", "policy_group_id": "verified:google", "name": "AdsBot-Google" } ], "page": { "limit": 50, "next_cursor": "example_next_page", "total": 2 }, "groups": [ { "configurable": true, "id": "ai:google", "name": "Google", "section": "ai_crawlers", "membership_complete": true, "bot_ids": ["google_agent", "google_cloudvertex", "google_gemini_notebook"], "advisory_ids": ["google_extended"], "default_rate": { "enabled": true, "rpm": 6000, "burst": 100, "scope": "bot", "on_exceed": "respond", "response": { "status": 429 } } } ], "group_membership_complete": true }}limitgoes from 1 to 100. Without it a page holds 50 items. To read the next page, senddata.page.next_cursorback ascursor, until it isnull.itemsis paged.groupsis not: it comes whole, apart from the page. Take the members of a group from itsbot_ids, never from the items of the current page.sectionisai_crawlersorverified_bots.bot_idsare the bots of the group that send HTTP traffic.advisory_idsare robots tokens only.- A group with
"configurable": falsecannot take a policy. default_rateis the catalog default, not something saved for your domain."state": "unknown"underdatameans the catalog is unavailable. It is not an empty catalog.
Browser coverage
Section titled “Browser coverage”Browser coverage sets, per browser family, a minimum version and what happens to older versions.
Read the browser coverage
Section titled “Read the browser coverage”curl "$SECURITY/settings/browser-coverage/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"data can hold three maps, each from family id to a profile of enabled, min_version and action:
| Map | What it holds |
|---|---|
policy |
The profiles you saved. It may be empty. |
defaults |
The product defaults, when the CDN supplies them. |
effective_policy |
What applies to each family once both are combined, when the CDN supplies it. |
Each profile in effective_policy adds three fields:
{ "chrome": { "enabled": false, "min_version": 120, "action": "skip", "source": "explicit", "scope": "all_requests", "enforcing": false }, "firefox": { "enabled": true, "min_version": 115, "action": "challenge", "source": "default", "scope": "document_navigation", "enforcing": true }}- A family you never saved has
"source": "default"and"scope": "document_navigation". A family you saved has"source": "explicit"and"scope": "all_requests". enforcingsays the family has an active action and version threshold. It does not mean every request is challenged.
Change a browser family
Section titled “Change a browser family”The body is a map of the families that change. action is skip, challenge or block, and min_version goes from 1 to 9999.
curl -X PATCH "$SECURITY/settings/browser-coverage/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "chrome": { "enabled": true, "min_version": 120, "action": "challenge" } }'curl -X PATCH "$SECURITY/settings/browser-coverage/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "safari": { "enabled": false, "min_version": 15, "action": "challenge" } }'curl -X PATCH "$SECURITY/settings/browser-coverage/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "opera": null }'- The first time you edit a family that is still on its default, send all three fields. Missing fields are not filled in from the default, and a profile without an
actiondoes nothing. - To stop a family from being checked, send
"enabled": falseor"action": "skip". Both keep the version threshold. nullputs the family back on its default.- Never send
defaults,effective_policy,source,scopeorenforcing.
List the browser families
Section titled “List the browser families”curl "$SECURITY/references/browser-families/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"Each item is a family you can use as a key in browser coverage: its id, the actions it supports, the bounds of min_version under minimum_version, and its default_policy. The list is paged with limit and cursor, like the bot catalog.
Security headers
Section titled “Security headers”Read the headers
Section titled “Read the headers”curl "$SECURITY/settings/headers/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"The group has four booleans:
| Field | What it switches |
|---|---|
sameorigin |
The same origin policy header |
nosniff |
The content type no-sniff header |
xss_protection |
The XSS protection header |
hotlinking |
The image hotlinking protection |
Change the headers
Section titled “Change the headers”Send at least one of the four. The others keep their value.
curl -X PATCH "$SECURITY/settings/headers/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "sameorigin": true, "xss_protection": true }'An empty body ({}) answers 400 NO_CHANGES.
Mitigation
Section titled “Mitigation”Read the mitigation
Section titled “Read the mitigation”curl "$SECURITY/settings/mitigation/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "data": { "mode": { "state": "resolved", "value": "sensor" }, "notification_email": { "state": "resolved", "value": "operations@example.net" }, "max_connections": { "state": "resolved", "value": 1000 } }}| Field | Values on a write |
|---|---|
mode |
sensor, permanent or off, in lower case |
notification_email |
One line of 1 to 254 bytes, with an @ that is neither first nor last |
max_connections |
A whole number from 100 to 50000 |
A read can answer a mode of other, for a mode this API does not know, and a max_connections above 50000. Show them as they are. You cannot write either of them back.
Change the mitigation
Section titled “Change the mitigation”The body holds exactly one of the three fields. Two fields in one body answer 400 INVALID_REQUEST.
curl -X PATCH "$SECURITY/settings/mitigation/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "mode": "permanent" }'To change two fields, send two requests. The second one takes the ETag that the first one answered.
An email address the CDN does not accept answers 400 INVALID_REQUEST with notification_email in fields.
Read the manipulation detection
Section titled “Read the manipulation detection”This group has one field, enabled: whether the detection of request manipulation is on.
curl "$SECURITY/settings/manipulation/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"On some domains the CDN cannot tell. enabled then comes back with "state": "unknown" and "reason": "legacy_feature_not_wired". Show the setting as unavailable, not as off.
Switch the manipulation detection
Section titled “Switch the manipulation detection”The body is exactly enabled, true or false:
curl -X PATCH "$SECURITY/settings/manipulation/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "enabled": true }'Unlike the other groups, an empty body ({}) answers 400 INVALID_REQUEST here. On a domain where the setting is unavailable, the write answers 409 LEGACY_FEATURE_NOT_WIRED and changes nothing. Sending it again does not help.
Limits and permissions
Section titled “Limits and permissions”- Credits. Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. Every call on this page costs 8 credits.
- Refused early. A write refused with
400or428before it reaches the CDN spends no credits. - Out of credits. The call answers
429 TOO_MANY_REQUESTS, with the wait indetails.retry_after_seconds. - Permissions. Reads need
waf.viewon the domain. Writes needwaf.edit.
Errors you are likely to see
Section titled “Errors you are likely to see”| Status | Code | What happened |
|---|---|---|
400 |
INVALID_REQUEST |
A field is wrong, unknown or missing. The answer names it in fields when it can. |
400 |
NO_CHANGES |
An edit was sent with an empty body. |
400 |
INVALID_PRECONDITION |
If-Match is not one ETag exactly as a read answered it, with its quotes. |
404 |
SETTINGS_GROUP_NOT_FOUND |
The CDN does not have this settings group for the domain. |
404 |
REFERENCE_NOT_FOUND |
The CDN does not have this catalog. This is not an empty catalog. |
409 |
CURSOR_STALE |
The catalog changed while you were paging. Start from the first page. |
409 |
INVALID_STATE |
The CDN refused the change for the state it found. Nothing was written. Read the group again. |
409 |
LEGACY_FEATURE_NOT_WIRED |
Manipulation detection cannot be changed on this domain. |
409 |
DOMAIN_BUSY |
Something else is changing the domain. Wait and retry with the same If-Match. |
412 |
REVISION_MISMATCH |
The group changed since your read. Read again and retry. |
428 |
PRECONDITION_REQUIRED |
The If-Match header is missing. |
429 |
TOO_MANY_REQUESTS |
The domain is out of credits for now. |
502 |
FILE_SERVER_OUTCOME_UNKNOWN |
The answer of the write was lost. The change may have been applied. Read again before repeating. |
503 |
PUBLICATION_FAILED |
The CDN could not publish and verify the change. Read the group again to see what is published. |
400, 409, 502, 503 |
FILE_SERVER_V2_ERROR |
The CDN answered something this API has no code for. The outcome is unconfirmed. Read the group again before any retry. |
The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.
All Security endpoints
Section titled “All Security endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...