Skip to content
Dashboard

Protection

View as Markdown

DWAF

Switch DWAF on or off for a domain, pick its profile, turn rules off and add exceptions, for the domain or for one subdomain.

/api/admin/strictstrictbase

DWAF is the DiamWall Application Firewall. These endpoints control it for one domain at a time: the switch of the domain, and the configuration of the domain and of each subdomain that has its own. The paths start with /v2/cdn/dwaf/{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 DWAF="https://api.diamwall.com/v2/cdn/dwaf/your-domain-public-id"

One read gives you everything needed to draw a DWAF page: the switch of the domain, its profile and the two catalogs.

curl "$DWAF/settings/dwaf/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"revision": "sha256:a58bca68a8f7...",
"consistency": "verified",
"data": {
"enabled": { "state": "resolved", "value": true },
"profile": { "state": "resolved", "value": "balanced" },
"available_profiles": {
"state": "resolved",
"value": [{ "id": "balanced", "name": "Balanced", "description": "Illustrative balanced profile" }]
},
"core_rules": {
"state": "resolved",
"value": {
"categories": ["sqli", "xss"],
"rules_count": 2,
"rules": [
{
"id": "sqli-001",
"name": "Example SQL injection rule",
"description": "Illustrative public rule metadata",
"category": "sqli",
"tags": ["sqli", "request"],
"targets": ["uri", "args"]
}
]
}
}
}
}
Field What its value holds
enabled A boolean: whether DWAF is on for the domain itself
profile The id of the profile of the domain, or null when it has none
available_profiles The whole catalog of profiles
core_rules The whole catalog of rules, with categories, rules_count and rules
  • Each field has a state, and a value only when the state is resolved. A state of unknown means the value is unavailable. Never treat it as true, false, a default or an empty catalog.
  • When the whole group could not be read, the answer is still 200, with state: "unknown", a revision of null, no data and no ETag. There is nothing to write with then.
  • The ETag header is the revision of the group. Keep it for the switch below.
  • The profile, the disabled rules and the exceptions are not here. They are in the scopes.

This switches DWAF for the domain itself. Read the settings first to get the ETag, then send it in If-Match:

ETAG=$(curl -s -o /dev/null -D - "$DWAF/settings/dwaf/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
| tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')
curl -X PATCH "$DWAF/settings/dwaf/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $ETAG" \
-d '{ "enabled": true }'
  • The body is exactly {"enabled": true} or {"enabled": false}. No body, {}, a string, a number or any other field answers 400 INVALID_REQUEST.
  • The answer is the group after the change, with a new ETag for the next edit.
  • To switch DWAF for one subdomain, edit its scope instead.

A scope is the DWAF configuration of one host. Every domain has a root scope, for the domain itself. A subdomain has a scope only when you create one. A subdomain without a scope uses the configuration of the domain.

Field Meaning
id The id of the scope. Use it in the path. It is not a hostname.
scope root or subdomain
hostname The full host, such as api.example.com
subdomain The label of the host, such as api. Only on a subdomain scope.
directive The enabled and profile of the domain, each with a state. Only on the root scope.
config The configuration: enabled, profile, disabled_rules, exceptions and a few read-only fields
mutable false means changes to this scope are refused with 409 INVALID_STATE. A missing field does not mean true.

A key that is missing from config is unavailable. It is never false, null or an empty list.

curl "$DWAF/dwaf-scopes/?limit=50" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"revision": "sha256:da8af4d25e6c...",
"data": {
"items": [
{
"id": "Rt5kQ8wZ2nB7vX4cM1pL9sJ6",
"scope": "root",
"hostname": "example.com",
"directive": {
"enabled": { "state": "resolved", "value": true },
"profile": { "state": "resolved", "value": "balanced" }
},
"config": {
"client_id": "example.com",
"name": "Example tenant",
"enabled": true,
"profile": "balanced",
"disabled_rules": ["xss-001"],
"exceptions": [],
"whitelist_ip_count": 1,
"block_page_configured": true
},
"mutable": true
},
{
"id": "Sb3hG6dF9aK2jL5_P8oI1uY4",
"scope": "subdomain",
"hostname": "api.example.com",
"subdomain": "api",
"config": {
"client_id": "api.example.com",
"name": "API",
"enabled": true,
"disabled_rules": [],
"exceptions": []
},
"mutable": true
}
],
"page": { "limit": 50, "next_cursor": null, "total": 2 }
}
}
  • limit goes from 1 to 100. Without it a page holds 50 scopes.
  • To read the next page, send data.page.next_cursor back as cursor, until it is null.
  • If the scopes change between two pages, the next page answers 409 CURSOR_STALE. Start again from the first page.
  • Only hosts that have a scope are listed. To see every name of the domain, read its DNS records.
curl "$DWAF/dwaf-scopes/Sb3hG6dF9aK2jL5_P8oI1uY4/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"

The scope comes back under data, in the same form as an item of the list. An id that no scope has answers 404 RESOURCE_ITEM_NOT_FOUND. The scope may have been deleted, so read the list again.

Every create, edit and delete of a scope takes an If-Match header. Its value is the ETag of a read of the scopes. The list and a single scope both work, because each carries the revision of the whole collection.

ETAG=$(curl -s -o /dev/null -D - "$DWAF/dwaf-scopes/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
| tr -d '\r' | awk 'tolower($1) == "etag:" { print $2 }')

Without the header the write answers 428. If the scopes changed since your read it answers 412 REVISION_MISMATCH. Every successful write returns a new ETag to use on the next one.

scope is always the word subdomain, and subdomain is the label of the host: 1 to 63 lower-case letters, digits, _ and -, with no dot. The root scope is never created. It is always there.

curl -X POST "$DWAF/dwaf-scopes/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $ETAG" \
-d '{ "scope": "subdomain", "subdomain": "api" }'

The answer is 201 with the new scope under data, its id under operation, and a new ETag header. A subdomain that already has a scope answers 409 RESOURCE_CONFLICT.

The body holds exactly one of four fields. Two fields in one body answer 400 INVALID_REQUEST, and an empty body answers 400 NO_CHANGES. To change two things, send two requests, each with the ETag of the answer before it.

Field Value
enabled true or false. For the domain itself, use the settings switch instead.
profile The id of a profile from the catalog, or null for no profile
disabled_rules The whole list of rules that are off: at most 1024 entries, none twice
exceptions The whole list of exceptions: at most 512, no id twice
curl -X PATCH "$DWAF/dwaf-scopes/Sb3hG6dF9aK2jL5_P8oI1uY4/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $ETAG" \
-d '{ "profile": "balanced" }'

An entry of disabled_rules is the id of a rule, * for every rule, or a prefix that ends in *, such as sqli-*.

An exception has an id, the rule_ids it covers (1 to 256) and its conditions, and optionally a name and enabled. It applies to a request that matches every condition it has.

Condition Value
ips IPv4 and IPv6 addresses, each whole or a network in CIDR form
methods A list, such as ["GET"]
uri_prefixes A list, such as ["/search"]
uri_contains A list of values
arg_names A list of values
user_agents A list of values
headers An object: the name of a header and what it holds

Each condition except headers is a list of 1 to 256 values, with none twice. No other condition is accepted.

curl -X PATCH "$DWAF/dwaf-scopes/Sb3hG6dF9aK2jL5_P8oI1uY4/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "Content-Type: application/json" \
-H "If-Match: $ETAG" \
-d '{
"exceptions": [
{
"id": "public-search",
"name": "Public search",
"enabled": true,
"rule_ids": ["sqli-001"],
"conditions": { "methods": ["GET"], "uri_prefixes": ["/search"] }
},
{
"id": "office-network",
"name": "Office network",
"enabled": true,
"rule_ids": ["sqli-001"],
"conditions": { "ips": ["192.0.2.0/24", "2001:db8::1"] }
}
]
}'

The ids in your list decide what happens:

  • An id the scope does not have yet is a new exception.
  • An id of the scope that your list leaves out is removed.
  • An id the scope already has is edited.

The whole body holds at most 32768 bytes of JSON.

Deleting the scope of a subdomain sends that host back to the configuration of the domain. The request has no body.

curl -X DELETE "$DWAF/dwaf-scopes/Sb3hG6dF9aK2jL5_P8oI1uY4/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY" \
-H "If-Match: $ETAG"

The answer has operation with the id that was deleted, and no data. The root scope cannot be deleted: the request answers 405 METHOD_NOT_ALLOWED.

The catalogs are read-only lists of the ids you can use in a scope.

Catalog Call Its ids go in
Profiles GET .../references/dwaf-profiles/ profile
Rules GET .../references/dwaf-rules/ disabled_rules and the rule_ids of an exception
curl "$DWAF/references/dwaf-profiles/" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"
{
"data": {
"state": "resolved",
"items": [
{ "id": "balanced", "name": "Balanced", "description": "Illustrative balanced profile" },
{ "id": "strict", "name": "Strict", "description": "" }
],
"page": { "limit": 50, "next_cursor": null, "total": 2 }
}
}

The profiles above are examples. Read the catalog of your domain for the real ids.

curl "$DWAF/references/dwaf-rules/?limit=100" \
-H "Authorization: Api-Key $DIAMWALL_API_KEY"

Each rule has id, name, description, category, tags and targets. These describe the rule. They do not say how it detects a request.

Both catalogs behave the same way:

  • limit goes from 1 to 100, and 50 without it. Page with cursor as for the scopes. A catalog that changes between two pages answers 409 CURSOR_STALE.
  • data.state is always answered. Only under resolved are there items and page. Under any other state the catalog is unavailable: the answer is still 200, with no items and no page. Show it as unavailable, never as an empty catalog.
  • There is no ETag and nothing to send in If-Match.

Credits. Each domain has a budget of 3000 credits a minute, shared by everyone who calls the API for that domain. A call that runs out answers 429 TOO_MANY_REQUESTS, with the wait in details.retry_after_seconds.

Call Credits
Read or switch the settings 8
List, read, create, edit or delete a scope 8
Edit the exceptions of a scope 16
Create or edit a scope in a way that adds exceptions 46
List the profiles or the rules 25

Exception limit. DWAF exceptions count toward the waf_rules limit of the plan: 25 on Pro, 100 on Business, 200 on Enterprise. The limit is shared with the firewall rules, the access rules and the exceptions of WAF rules. A write that adds exceptions beyond it answers 400 PLAN_LIMIT_EXCEEDED, with details.limit, details.current, details.plan and details.feature. A write that only changes or removes exceptions is never counted.

Permissions. DWAF uses the waf permissions on the domain.

You want to Permission
Read the settings, the scopes or the catalogs waf.view
Switch DWAF, or edit a scope waf.edit
Create a scope, or add an exception to one waf.create
Delete a scope, remove an exception, or set profile to null waf.delete

waf.create and waf.delete each include waf.edit. waf.edit includes neither.

Status Code What happened
400 INVALID_REQUEST A field is wrong, or the profile or rule does not exist. The answer names the field in fields when it can.
400 NO_CHANGES A scope edit was sent with an empty body.
400 PLAN_LIMIT_EXCEEDED The new exceptions go over the waf_rules limit of the plan.
403 PERMISSION_DENIED You lack the permission this body needs, such as waf.create to add an exception.
404 RESOURCE_ITEM_NOT_FOUND No scope has that id. Read the list again.
404 REFERENCE_NOT_FOUND The catalog does not exist for this domain.
405 METHOD_NOT_ALLOWED You tried to delete the root scope.
409 CURSOR_STALE The list changed while you were paging. Start from the first page.
409 RESOURCE_CONFLICT The subdomain already has a scope.
409 PROFILE_OVERRIDE_CONFLICT The profile change conflicts with an override of the scope. Nothing was changed.
409 LEGACY_EXCEPTION_CONDITIONS The change is not allowed on an exception with conditions_withheld.
409 INVALID_STATE The change is refused in the current state of the domain. Read again to see what is published.
412 REVISION_MISMATCH The settings or the scopes changed since your read. Read again and retry.
428 The If-Match header is missing.
429 TOO_MANY_REQUESTS The domain is out of credits for now.
429 RATE_LIMIT_EXCEEDED The domain is refused for a while. Wait details.retry_after_seconds.
503 CLIENT_CONFIG_NOT_WIRED, CLIENT_CONFIG_PATH_FOREIGN, CLIENT_CONFIG_WIRING_AMBIGUOUS DWAF cannot be written for this domain. Nothing was changed and no retry helps. Quote request_id to support.
503 PUBLICATION_FAILED The switch could not be published and verified. Read the settings again before trying anything else.

The errors that come from the key itself, such as API_KEY_IP_NOT_ALLOWED, are on the Errors page.

Each row opens the endpoint in the API reference, with every parameter, rule and response.

Loading the endpoints...