Appearance
Schema enforcement Since v0.1
Schema enforcement refuses API requests that are malformed, too large or deeply nested, and requests that do not match your OpenAPI description. Start with the body limits, then add a description with every check in log mode and tighten it from the events.
Before you begin
- Role:
operatorfor the application. - An OpenAPI 3.0 or 3.1 description in JSON or YAML. Convert Swagger 2.0 first. External
$refs are refused because nothing is fetched. - Check it first with
waap api check -f shop.yaml.
Turn on API protection
text
1. Open Applications > All applications, and select the application.
2. In the application menu, open Request checks > API protection.
3. On the Limits tab, set Protection mode to detect.
4. Select Preview changes, add a comment and select Apply.sh
waap api set -app shop -m "API protection" mode=detect
waap api get -app shopyaml
# applications[].policy.api in the configuration
applications:
- name: shop
policy:
api:
mode: detectwaap api get lists every setting with its value, default, whether it is set and the allowed range. KEY= with an empty value returns a setting to its default. -dry-run shows the changes only.
Change a body limit
text
1. Open the application's API protection page, Limits tab.
2. In the JSON bodies or XML bodies group, change the value.
3. Select Preview changes, then Apply.sh
waap api set -app shop -m "larger orders" limits.json.depth=16 limits.xml.value_length=128KiByaml
# applications[].policy.api
limits:
json:
depth: 16
xml:
value_length: 128KiBSome rules cannot be relaxed
Duplicate JSON member names (api.json.duplicate_key) and XML document type declarations that declare entities or an external DTD (api.xml.dtd, an XXE guard) are always refused.
Enforce an OpenAPI description
text
1. Open the application's API protection page, Descriptions (OpenAPI) tab.
2. Under Add or replace a description, enter a Name such as shop-v1.
3. Leave Base path empty to use the description's server URL, or enter a prefix.
4. Select the OpenAPI file and review the operations it found.
5. Apply. New descriptions start with every check logging only.
6. After the events look clean, set each check (Unknown paths, Unknown methods,
Parameters, Request bodies) to block on the description's card.sh
waap api check -f shop.yaml
waap api spec set -app shop -name shop-v1 -f shop.yaml -check unknown_paths=log,unknown_methods=log,parameters=log,request_bodies=log -m "shop v1"
# later, when the events are clean
waap api spec set -app shop -name shop-v1 -check parameters=block -m "enforce parameters"yaml
# applications[].policy.api.specs
- name: shop-v1
file: shop-openapi.yaml
base_path: /api/v1
unknown_paths: log
unknown_methods: log
parameters: log
request_bodies: logWithout -f, spec set changes only the settings. Requests outside every base path are not checked. A CORS preflight is never checked.
Replace or remove a description
For a new API version, upload the new file under the same name to replace it, or under a new name with its own base path. Remove one with:
sh
waap api spec remove -app shop -name shop-v1 -m "retire v1"Every change is a version, so waap config rollback restores the previous description.
See what is enforced
waap api describe -app shop lists the operations each description enforces. In the console the Descriptions tab shows the operations table with a filter and Deprecated only.
Settings reference
Module settings
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
API protection (enabled) | Checks API request bodies. Off keeps the settings. | true when the section exists | true, false | all |
Protection mode (mode) | Whether violations refuse the request or only log. | empty (same as the application) | detect, block, empty | detect wins over the application's block |
JSON bodies
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Nesting depth (limits.json.depth) | Objects and arrays inside each other. | 32 | 1 to 512 | all |
Members per object (limits.json.keys) | Names in one object. | 1000 | 1 to 1000000 | all |
Member name length (limits.json.key_length) | Bytes in one member name, decoded. | 256 bytes | 1 to 64KiB | all |
String length (limits.json.string_length) | Bytes in one string value, decoded; also the digits of a number. | 64KiB | 1 up to the request body limit | all |
Array elements (limits.json.array_length) | Elements in one array. | 10000 | 1 to 1000000 | all |
XML bodies
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Nesting depth (limits.xml.depth) | Elements inside each other. | 32 | 1 to 512 | all |
Elements (limits.xml.elements) | Elements in the document. | 10000 | 1 to 1000000 | all |
Attributes per element (limits.xml.attributes) | Attributes on one element. | 64 | 1 to 1000 | all |
Name length (limits.xml.name_length) | Bytes in an element or attribute name. | 256 bytes | 1 to 64KiB | all |
Value length (limits.xml.value_length) | Bytes in an attribute value or the text of one element. | 64KiB | 1 up to the request body limit | all |
Description
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the description. | none (required) | lowercase letters, digits, dashes | all |
File (file) | The OpenAPI file, stored with the version. | none (required) | up to 8 MiB; 32 MiB for all descriptions | all |
Base path (base_path) | URL prefix the description covers. | the path of the first server URL, or / | path | all |
Unknown paths (unknown_paths) | A path under the base path that matches no operation. | block | block, log, allow | block mode refuses |
Unknown methods (unknown_methods) | A method the path does not declare. | block | block, log, allow | block mode refuses |
Parameters (parameters) | A missing required parameter, or a value that breaks its schema. | block | block, log, allow | block mode refuses |
Request bodies (request_bodies) | A missing required body, undeclared media type or a body that breaks its schema. | block | block, log, allow | block mode refuses |
Skip unsupported patterns (unsupported_patterns) | Whether schema patterns that RE2 cannot run refuse the description or are skipped. | error | error, ignore | all |
The rules are api.schema.unknown_path, api.schema.method, api.schema.parameter and api.schema.body. Undeclared extra query parameters are accepted. Literal path segments win over templates, and HEAD is accepted where GET is declared.
Examples
Tighter limits for a small JSON API:
yaml
mode: block
limits:
json:
depth: 8
keys: 200Limits
| Limit | Value |
|---|---|
| Descriptions per application | 16 |
| One description file | 8 MiB |
| All description files in one configuration | 32 MiB |
| List settings (entries) | 32 |
Troubleshooting
A legitimate request is refused by an api.* rule
- Cause: a limit is too low for a real client, or the description is out of date.
- Check: open the event. It names the rule, the JSON pointer or element path and the value.
- Fix: raise the limit, fix the description, or use False positive (
waap except EVENT) for an exception limited to that path, method, rule and field.
Preview refuses a description
- Cause: the file does not validate, uses Swagger 2.0, has an external
$ref, or has a pattern RE2 cannot run. - Check:
waap api check -f shop.yaml. - Fix: correct the file, or pass
-ignore-patternsto skip such patterns.