Skip to content

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: operator for 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 shop
yaml
# applications[].policy.api in the configuration
applications:
  - name: shop
    policy:
      api:
        mode: detect

waap 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=128KiB
yaml
# applications[].policy.api
limits:
  json:
    depth: 16
  xml:
    value_length: 128KiB

Some 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: log

Without -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 ​

SettingWhat it doesDefaultAllowed valuesApplies in
API protection (enabled)Checks API request bodies. Off keeps the settings.true when the section existstrue, falseall
Protection mode (mode)Whether violations refuse the request or only log.empty (same as the application)detect, block, emptydetect wins over the application's block

JSON bodies ​

SettingWhat it doesDefaultAllowed valuesApplies in
Nesting depth (limits.json.depth)Objects and arrays inside each other.321 to 512all
Members per object (limits.json.keys)Names in one object.10001 to 1000000all
Member name length (limits.json.key_length)Bytes in one member name, decoded.256 bytes1 to 64KiBall
String length (limits.json.string_length)Bytes in one string value, decoded; also the digits of a number.64KiB1 up to the request body limitall
Array elements (limits.json.array_length)Elements in one array.100001 to 1000000all

XML bodies ​

SettingWhat it doesDefaultAllowed valuesApplies in
Nesting depth (limits.xml.depth)Elements inside each other.321 to 512all
Elements (limits.xml.elements)Elements in the document.100001 to 1000000all
Attributes per element (limits.xml.attributes)Attributes on one element.641 to 1000all
Name length (limits.xml.name_length)Bytes in an element or attribute name.256 bytes1 to 64KiBall
Value length (limits.xml.value_length)Bytes in an attribute value or the text of one element.64KiB1 up to the request body limitall

Description ​

SettingWhat it doesDefaultAllowed valuesApplies in
Name (name)Identifies the description.none (required)lowercase letters, digits, dashesall
File (file)The OpenAPI file, stored with the version.none (required)up to 8 MiB; 32 MiB for all descriptionsall
Base path (base_path)URL prefix the description covers.the path of the first server URL, or /pathall
Unknown paths (unknown_paths)A path under the base path that matches no operation.blockblock, log, allowblock mode refuses
Unknown methods (unknown_methods)A method the path does not declare.blockblock, log, allowblock mode refuses
Parameters (parameters)A missing required parameter, or a value that breaks its schema.blockblock, log, allowblock mode refuses
Request bodies (request_bodies)A missing required body, undeclared media type or a body that breaks its schema.blockblock, log, allowblock mode refuses
Skip unsupported patterns (unsupported_patterns)Whether schema patterns that RE2 cannot run refuse the description or are skipped.errorerror, ignoreall

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: 200

Limits ​

LimitValue
Descriptions per application16
One description file8 MiB
All description files in one configuration32 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-patterns to skip such patterns.