Membrane API Gateway returns 400 Bad Request with the title Request path contains an invalid character. when it cannot parse the request URI. Membrane checks the URI before it routes the request and rejects URIs that contain characters not allowed by RFC 3986.
The response contains the status 400 Bad Request, the title Request path contains an invalid character., a detail that names the invalid character and its position in the URI, the problem type https://membrane-api.io/problems/user and a link to this page. The type user means that the request or the configuration caused the problem, not an internal failure of the gateway.
Before Membrane forwards a request, it parses the request URI to determine where to send it. Characters outside the allowed set must be percent-encoded by the client. Common examples:
| Character | Encoded |
|---|---|
| Space | %20 |
" | %22 |
< and > | %3C and %3E |
{ and } | %7B and %7D |
| | %7C |
^ | %5E |
% as a literal character | %25 |
The client sends characters such as spaces, {, }, |, ^, <, >, " or control characters without encoding them. For example, /products?name=red apple must be sent as /products?name=red%20apple.
A % must be followed by two hexadecimal digits. A request like /discounts/50% or /search?q=%zz is rejected. Encode a literal percent sign as %25.
Some clients and proxies send the full URL in the request line, for example GET http://example.com:8080/shop HTTP/1.1. If the scheme, user info, host or port of that URL is invalid, for example an empty host, a non-numeric port or an unclosed IPv6 bracket, the URI cannot be parsed.
Less often, the cause is in the configuration. If the url of the API's target has a host or port that cannot be parsed, this is reported as an invalid request path, too. In that case, the detail names the host or port instead of a character in the path.
target url of the API in your apis.yaml.If you have to accept legacy clients that cannot be changed, you can relax the check. This weakens input validation, so use it only if you must:
configuration:
uriFactory:
allowIllegalCharacters: true
autoEscapeBackslashes: true
configuration:
uriFactory:
allowIllegalCharacters: true
autoEscapeBackslashes: true
autoEscapeBackslashes escapes backslashes in the URI instead of rejecting them.
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 ---.
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.