Membrane API Gateway returns 500 Internal Server Error with the detail Error inspecting body! when the xmlProtection plugin fails unexpectedly while it inspects a request body. In most cases the Content-Type header of the request triggers it.
The response contains the status 500 Internal Server Error, the detail Error inspecting body!, the problem type https://membrane-api.io/problems/internal and a link to this page. In development mode, the reason field contains the exception message. The type internal means that the gateway could not complete the processing of the message. In production mode, the title is replaced by Internal Server Error and the details are left out.
The xmlProtection plugin protects backends against XML attacks by limiting the size, depth and structure of XML requests. Violations of these limits are not reported here: they, malformed XML and unprocessable multipart bodies get a 400, disallowed content types a 415, and unreadable bodies a separate body read error.
The Content-Type header is malformed, so Membrane cannot decide whether the body is multipart.
The charset parameter of the Content-Type header, or of the header of a multipart part, names an illegal or unsupported charset, for example text/xml; charset=foo.
The XML declaration may name an encoding that the XML parser accepts but Java cannot load as a charset. This cause has not been reproduced; in many cases the parser rejects such an encoding first.
The same link also appears when the xmlProtection plugin throws an exception that it does not turn into an error response itself. Membrane then aborts the exchange with 500 Internal Server Error, and the detail reads Aborting! Exception caused in xml-protection during … flow. with the request URI and the flow. Membrane logs every occurrence with the full stack trace. Unless the exception points to your configuration or to the message content, this usually indicates a bug in Membrane.
Content-Type header with a standard charset name such as UTF-8, or omit the charset.info level as Could not inspect the XML body: …, the stack trace at debug level.By default, Membrane runs in development mode and adds details to error responses that help you find the problem. These details may reveal information about your setup. In production, turn them off:
configuration:
production: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---. The title then reads Internal Server Error, and the details and the link to this page are left out. If the response contains a log key, search the gateway log for it to find the full error message.
If the plugin is nested inside a request, response or abort element and fails with an unexpected exception there, the exception message, the stack trace and the link to this page are currently sent even in production mode. Fix the failing plugin rather than relying on production mode to hide them.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.