Protection
WAF
Switch the WAF of a domain on or off, browse its rules and create exceptions that turn one rule off.
This part of the API controls the WAF of one domain: whether it is on, which rules it has, and the exceptions that switch a rule off. The paths start with /v2/cdn/waf/{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 WAF="https://api.diamwall.com/v2/cdn/waf/your-domain-public-id"WAF status
Section titled “WAF status”Read whether the WAF is on
Section titled “Read whether the WAF is on”curl "$WAF/settings/waf/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:aea6d4e65b77...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "status": { "state": "resolved", "value": { "enabled": true } } }}data.status.value.enabledis the answer, and it is only there whendata.status.stateisresolved. Afalseunderresolvedis a WAF that is off.- A
stateofunknownmeans the status is unavailable. Show it as unavailable, never asfalse. - When the whole group could not be read, the answer has a top-level
stateofunknown, arevisionofnull, nodataand noETag. There is nothing to write against until a later read succeeds. - Keep the
ETagheader of the answer. The switch below takes it inIf-Match.
Switch the WAF on or off
Section titled “Switch the WAF on or off”Read the status first to get its ETag, then send it in If-Match:
ETAG=$(curl -s -o /dev/null -D - "$WAF/settings/waf/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')curl -X PATCH "$WAF/settings/waf/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "enabled": false }'The body is exactly { "enabled": true } or { "enabled": false }. enabled must be a JSON boolean: "true", 1, null, an empty body and any other field answer 400 INVALID_REQUEST.
The answer is the status as it is after the change, in the same form as the read, with a new ETag header for your next write.
The rules reference is the catalog of the WAF. It is read-only, and it is where you take the rule_id of an exception from.
curl "$WAF/references/waf-rules/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:b39a2d0c9ab7...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "state": "resolved", "items": [ { "id": "10001", "description": "Illustrative WAF rule", "tag": "SQL" }, { "id": "10002", "description": "Another illustrative WAF rule", "tag": "XSS" } ], "page": { "limit": 50, "next_cursor": null, "total": 2 } }}idis a string of 1 to 10 digits. Send it back as a string, never as a number.descriptionandtagare text to show.limitgoes from 1 to 100. Without it a page holds 50 rules.- To read the next page, send
data.page.next_cursorback ascursor, until it isnull. If the catalog changes between two pages, the next page answers409 CURSOR_STALE. Start again from the first page. data.stateis always there. Only underresolveddoes the answer holditemsandpage. Under any other state the catalog is unavailable: show it as unavailable, never as a catalog with no rules.- The answer has no
ETag, andlimitandcursorare the only query parameters accepted.
Rule exceptions
Section titled “Rule exceptions”An exception switches one rule of the WAF off. It has two fields:
| Field | Value |
|---|---|
rule_id |
The id of a rule from the rules reference, as a string. |
scope |
null for the whole domain, or an object that holds the exception to one path and one part of the request. |
A scope object looks like this:
target |
url |
variable |
|---|---|---|
body |
Required. The path, starting with /. |
Required. The name of the body field. |
args |
Required. The path, starting with /. |
Required. The name of the argument. |
cookie |
Required. The path, starting with /. |
Not accepted. |
url is one line of at most 2048 characters. variable is one line of 1 to 2048 characters. Neither may hold a control character.
An exception cannot be edited. To change one, delete it and create another.
Writes need the latest revision
Section titled “Writes need the latest revision”A create and a delete each have to prove they saw the latest state of the exceptions. The ETag header of a read is the revision of the whole collection, not of one exception. Send it back in If-Match, exactly as it came, with its quotes.
- Without
If-Matchthe write answers428 PRECONDITION_REQUIRED. - If the exceptions changed since your read, it answers
412 REVISION_MISMATCH. Read again and retry with the newETag. - Every successful write returns a new
ETagto use on the next one.
List the exceptions
Section titled “List the exceptions”curl "$WAF/waf-rule-exceptions/?limit=50" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"{ "revision": "sha256:b21425ed5c35...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "items": [ { "id": "j2-Z9dZNCvV0qchtvGSZir0T", "rule_id": "10001", "scope": { "target": "args", "url": "/search", "variable": "q" }, "scoped": true }, { "id": "Qm4-xT7pLk2NwE9sVb1cHy3R", "rule_id": "10002", "scope": null, "scoped": false } ], "page": { "limit": 50, "next_cursor": null, "total": 2 } }}limitgoes from 1 to 100. Without it a page holds 50 exceptions.- Paging works as for the rules: send
data.page.next_cursorback ascursor, and start again from the first page on409 CURSOR_STALE. data.page.totalis the number of exceptions of the domain, on every page together.- An empty list still has an
ETag. It is the one you send to create the first exception. data.stateis not always there. When it is there and is notresolved, the answer has noitems, nopageand noETag: the exceptions are unavailable, which is not the same as a domain with none.
Create an exception
Section titled “Create an exception”Read the list first to get the ETag:
ETAG=$(curl -s -o /dev/null -D - "$WAF/waf-rule-exceptions/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ | tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')curl -X POST "$WAF/waf-rule-exceptions/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "rule_id": "10001", "scope": { "target": "args", "url": "/search", "variable": "q" } }'curl -X POST "$WAF/waf-rule-exceptions/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "rule_id": "10001", "scope": { "target": "cookie", "url": "/account" } }'curl -X POST "$WAF/waf-rule-exceptions/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "Content-Type: application/json" \ -H "If-Match: $ETAG" \ -d '{ "rule_id": "10002", "scope": null }'The answer is 201 with the new exception under data, its id in operation.id as well, and a new ETag header.
{ "revision": "sha256:c0afaf4f272d...", "consistency": "verified", "publication": { "status": "verified", "rollout": "unknown" }, "data": { "id": "j2-Z9dZNCvV0qchtvGSZir0T", "rule_id": "10001", "scope": { "target": "args", "url": "/search", "variable": "q" }, "scoped": true }, "operation": { "type": "create", "warning_count": 0, "id": "j2-Z9dZNCvV0qchtvGSZir0T" }}Things to know:
- The body is exactly
rule_idandscope. Thescopekey is always required: for the whole domain send"scope": null, do not leave it out. - Nothing is trimmed or converted. A field in the wrong form answers
400 INVALID_REQUESTand names it infields, with an inner field as a path such asscope.variable. - The API does not check
rule_idagainst the rules reference. A rule id that no rule has is refused when the exception is published, and nothing is written. - An exception that already exists answers
409 RESOURCE_CONFLICT. - Another change to the domain running at the same time can answer
409 DOMAIN_BUSY. Try again shortly.
Read one exception
Section titled “Read one exception”curl "$WAF/waf-rule-exceptions/j2-Z9dZNCvV0qchtvGSZir0T/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY"The exception comes back under data, in the same form as an item of the list. The ETag header is again the revision of the whole collection, so it also works in If-Match.
An id that no exception has answers 404 RESOURCE_ITEM_NOT_FOUND. The exception may have been deleted, so read the list again.
Delete an exception
Section titled “Delete an exception”The rule applies again where the exception held it off. The request takes no body. If-Match is the ETag of a read of the list or of the exception.
curl -X DELETE "$WAF/waf-rule-exceptions/j2-Z9dZNCvV0qchtvGSZir0T/" \ -H "Authorization: Api-Key $DIAMWALL_API_KEY" \ -H "If-Match: $ETAG"The answer has no data. operation.id is the id the exception had, and the ETag header is the new revision of the collection.
Limits and permissions
Section titled “Limits and permissions”- Credits. Each domain has a budget of credits per minute, shared by everyone who calls the API for that domain. A WAF call costs 8 credits. Listing the rules costs 15.
- Creating an exception costs 38. Besides the 8 of the write, the API spends 30 on reading the counts that go into the plan limit. A create that is refused after those reads, for example with
400 PLAN_LIMIT_EXCEEDEDor412 REVISION_MISMATCH, keeps the credits it spent. - Out of credits. The call answers
429 TOO_MANY_REQUESTS, with the wait indetails.retry_after_secondsand in theRetry-Afterheader. - Plan limit. Pro 25, Business 100, Enterprise 200. The limit counts four things together: the firewall rules of the domain, its access rules, the WAF rule exceptions on this page, and the exceptions of the root of its DWAF. A create at or above the limit answers
400 PLAN_LIMIT_EXCEEDED, withdetails.limit,details.current,details.plananddetails.feature.details.currentcan be abovedetails.limitafter a move to a lower plan. - Hard ceiling. A domain holds at most 4096 exceptions, whatever its plan. One more answers
400 INVALID_REQUEST. - Permissions. Each action has its own permission on the domain, and
waf.editalone does not let you create or delete an exception.
| Action | Permission |
|---|---|
| Read the status, the rules or the exceptions | waf.view |
| Switch the WAF on or off | waf.edit |
| Create an exception | waf.create |
| Delete an exception | waf.delete |
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, or the body has a field that is not accepted. The answer names the field in fields when it can. |
400 |
INVALID_PRECONDITION |
The If-Match header is not one quoted ETag as a read returned it. |
400 |
PLAN_LIMIT_EXCEEDED |
The domain is at the rule limit of its plan. Nothing was created. |
404 |
RESOURCE_ITEM_NOT_FOUND |
No exception has that id. |
404 |
REFERENCE_NOT_FOUND |
The rules reference is not available for this domain. Asking again answers the same. |
404 |
SETTINGS_GROUP_NOT_FOUND |
The WAF settings are not available for this domain. |
409 |
RESOURCE_CONFLICT |
That exception already exists. |
409 |
CURSOR_STALE |
The list changed while you were paging. Start from the first page. |
409 |
DOMAIN_BUSY |
Another change to the domain is running. Try again shortly. |
409 |
INVALID_STATE |
The switch was refused for the state the domain is in. Nothing changed. |
412 |
REVISION_MISMATCH |
What you are writing 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. |
503 |
PUBLICATION_FAILED |
The switch could not be published and verified. Read the status before trying again. |
503 |
ROLLBACK_FAILED |
An exception write failed and could not be undone. Read the list before trying again. |
503 |
UNSAFE_PATH |
The rules could not be read safely. The catalog is unavailable, not empty. |
The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.
All WAF endpoints
Section titled “All WAF endpoints”Each row opens the endpoint in the API reference, with every parameter, rule and response.
Loading the endpoints...