Appearance
XML and SOAP contracts Since v0.2
A contract is the schema your XML or SOAP service publishes. Requests on the contract's paths are refused when they name an unknown operation, use another operation's SOAPAction or the wrong SOAP version, miss or add elements, use wrong types, break value facets, or break an uploaded DTD. The checks run after the XML body limits (depth, element counts, DTD refusal) on the same body. For the limits, see Schema enforcement.
Before you begin
- Role:
operatorfor the application. - The contract files: a WSDL 1.1 (SOAP 1.1 and 1.2, document/literal or rpc/literal; rpc/encoded is refused), an XSD, or a DTD. Files refer to each other by file name only, and nothing is fetched from the network.
- The
waap-xmlcheckhelper installed next to thewaapbinary on the control plane's node and on inspection nodes. It validates in a separate process, so a parser crash costs a helper restart, never the inspection service. - Check the files first:
waap api xml check -kind wsdl -f orders.wsdl -import types.xsd.
Add a contract
text
1. Open Applications > All applications > the application > Request checks > API protection.
2. Open the XML contracts tab and select Add a contract.
3. Enter Name, Kind and Paths. For a WSDL, set SOAPAction and Allowed operations.
4. Choose the main file first, then the files it imports. The page shows the
operations found, or why the files do not load.
5. Select Preview changes, add a comment and select Apply.sh
waap api xml check -kind wsdl -f orders.wsdl -import types.xsd
waap api xml contract set -app shop -name orders-soap -kind wsdl -path /soap/orders -f orders.wsdl -import types.xsd -m "orders contract"
waap api xml contracts -app shopyaml
# applications[].policy.api.xml
xml:
contracts:
- name: orders-soap
paths: [/soap/orders]
kind: wsdl
file: orders.wsdl
imports: [types.xsd]
soap_action: check
operations: [PlaceOrder]
on_violation: blockA new contract follows the application's mode. Upload it in detect, watch waap events list -app shop -rule api.xml.schema (and api.soap.) for a few days, fix the contract or the client, then set the application or Contract mode to block. Set On violation to log to keep one contract logging while others block.
Files that need the helper
An apply that names files is refused when waap-xmlcheck is not installed on the control plane's node, or when it cannot load the contract. Without -f, contract set changes only the settings.
Edit or remove a contract
text
1. Open the XML contracts tab and select Edit on the contract's row.
2. Change paths, allowed operations, SOAPAction handling, root or On violation.
Leave the files empty to keep the stored ones.
3. To remove it, select Remove, then preview and apply.sh
waap api xml contract remove -app shop -name orders-soap -m "retire contract"Requests to a removed contract's paths are no longer checked.
How a request is checked
Only requests with a body on a contract path are checked; GET /soap/orders?wsdl passes.
- The body must be XML (
text/xml,application/xml,application/soap+xml,*+xml) and at most Largest document validated. - A document with its own document type declaration is refused before parsing, as is one over the XML limits.
- For a WSDL, the envelope must be SOAP 1.1 or 1.2 with exactly one non-empty Body. Its first element names the operation. With SOAPAction set to
check, a SOAPAction header (1.1) oractionparameter (1.2) naming another operation is refused; an empty or absent action is accepted. - The document (for a WSDL, the Body element) is validated by the helper.
Settings reference
Module settings
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Contract mode (xml.mode) | Whether violations refuse or only log. | empty (same as API protection) | detect, block, empty | detect wins over the application's block |
Validation time budget (xml.budget) | Longest a document may take to validate. | 100ms | 5ms to 2s | all |
Largest document validated (xml.max_document) | Bigger documents on a contract path are refused as too large. | 1MiB | 1 up to the request body limit | all |
When the helper cannot answer (xml.on_unavailable) | What happens when the helper is missing, restarting or too slow. | inherit | inherit (the failure policy), open (log and pass), closed (refuse with 503) | all |
Contract
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Name (name) | Identifies the contract in events and configuration. | none (required) | lowercase letters, digits, dashes | all |
Kind (kind) | The kind of contract. | none (required) | wsdl, xsd, dtd | all |
Paths (paths) | Request paths the contract covers. | none (required) | exact, or a prefix ending in *; a path belongs to one contract | all |
Main file and imports (file, imports) | The contract files, stored with the version. | none (required) | up to 32 files, 8 MiB together | all |
Root element (root) | The expected root element. | none (any global element) | {namespace}local | kind xsd only |
SOAPAction (soap_action) | Whether the SOAPAction must match the operation. | check | check, ignore | kind wsdl only |
Allowed operations (operations) | Operations clients may call. | none (all) | operation names from the WSDL | kind wsdl only |
On violation (on_violation) | What a violation does. | block | block, log | block refuses only in block mode |
Helper settings
Administrators set these under System > Helpers, with waap settings set helpers, or in the configuration (helpers.xmlcheck).
| Setting | What it does | Default | Allowed values | Applies in |
|---|---|---|---|---|
Run waap-xmlcheck (xmlcheck.enabled) | Runs the helper while an application has contracts. | true | true, false | off: checks report the helper unavailable |
Binary (xmlcheck.binary) | Path of the helper on the nodes. | empty (next to the waap binary) | absolute path | all |
Workers (xmlcheck.workers) | Documents validated at once. | 2 | 1 to 64 | all |
Memory (xmlcheck.memory) | Memory the helper may use. A document needing more is refused as too complex. | 512MiB | 64MiB to 16GiB | all |
CPU time (xmlcheck.cpu_seconds) | CPU time after which the helper is recycled. | 3600 | 60 to 604800 | all |
Rules
| Rule | Meaning |
|---|---|
api.xml.schema | The document breaks the schema; also not XML, too large, own DTD, or wrong root. |
api.xml.dtd_mismatch | The document breaks the uploaded DTD. |
api.soap.operation | The operation is not in the contract, or not allowed. |
api.soap.action_mismatch | The SOAPAction names another operation. |
api.soap.envelope | Not a SOAP envelope, missing or duplicate Body, or the wrong SOAP version. |
api.xml.check_unavailable | The helper could not answer. |
api.xml.check_timeout | Validation took longer than the time budget. |
Events carry the element path and the value, with at most five problems per document. The event page shows the SOAP operation, and the endpoint inventory names SOAP calls POST /soap/orders#PlaceOrder. All rule IDs work in exceptions by prefix (api.soap., api.xml.).
Some pattern facets are not enforced
xs:pattern facets run with Go's linear-time regular expressions. Character class subtraction ([a-z-[aeiou]]), \I, \C, negated blocks inside a class and unknown Unicode blocks cannot be translated. Such a pattern is not enforced; the upload shows a warning that names it. Rewrite the pattern to have it enforced.
Limits
| Limit | Value |
|---|---|
| Contracts per application | 32 |
| Files per contract | 32 (one main file and 31 imports) |
| Size of one contract's files | 8 MiB together |
| Problems reported per document | 5 |
Helper check time (waap-xmlcheck check) | 10 seconds, 512 MiB |
Troubleshooting
Apply is refused: XML contract checks need waap-xmlcheck
- Cause: the helper is not installed on the control plane's node.
- Check:
waap api xml helpers, or System > Helpers. - Fix: install it next to the
waapbinary, or set Binary.
Requests on a contract path fail with api.xml.check_unavailable
- Cause: the helper is not running or is restarting. It restarts with a delay that grows from 100 ms to 10 s.
- Fix: check the helper state. Set When the helper cannot answer to
opento pass requests meanwhile.
A valid request breaks api.xml.schema
- Cause: the contract is older than the client, or a facet is stricter than the client.
- Check: the event shows the element path, the value and the parser's message with its line.
- Fix: update the contract, or use False positive for that path and rule.