Loading…
Loading…
Technical documentation on the payload size limiting filter, which rejects HTTP requests with bodies larger than the configured maximum size.
The PayloadLimitFilter is a servlet filter that intercepts all incoming API requests to enforce a maximum payload size. Its primary purpose is to protect the platform from resource exhaustion caused by excessively large request bodies. It acts as a safeguard at the entry point of the request processing pipeline.
For every request, the filter checks the payload size against a configurable limit. If the request body is too large, the filter rejects it immediately with an HTTP 413 Payload Too Large status and terminates processing. If the size is within the limit, the request is passed to the next component in the processing chain.
This component is crucial for maintaining platform stability and ensuring fair resource allocation among all tenants and services.
The filter employs a two-pronged strategy to enforce the payload limit, efficiently handling both requests with a declared content length and those using chunked transfer encoding where the size is not known in advance.
flowchart TD
subgraph "PayloadLimitFilter Logic"
A[Incoming HTTP Request] --> B{Has `Content-Length` header?};
B -- Yes --> C{Is `Content-Length` > Limit?};
C -- Yes --> D[Reject with HTTP 413];
C -- No --> E[Pass request to next filter];
B -- No (e.g., Chunked Encoding) --> F[Wrap request in a counting stream];
F --> G[Pass wrapped request to next filter];
G -- "Downstream component reads body" --> H{Bytes read > Limit?};
H -- No --> G;
H -- Yes --> I[Write and commit HTTP 413 response];
I --> J[Throw exception to stop processing];
endFast-Path Rejection: For requests that include a Content-Length header, the filter performs an immediate check. If the declared length exceeds the configured maximum (maxBytes), the request is rejected instantly without reading any of the request body. This is a highly efficient check for the common case of non-chunked requests.
Streaming Byte Counting: If a request does not have a Content-Length header (indicated by a value of -1), it typically uses chunked transfer encoding. To handle this, the filter wraps the request's input stream in a CountingServletInputStream. This special stream does not buffer the body, but rather counts the bytes as they are read by downstream components (e.g., a request body deserializer).
Streaming Rejection: As the body is being streamed, if the total number of bytes read surpasses the limit, the counting stream triggers a rejection. It immediately writes and commits the HTTP 413 response. Committing the response at this stage is critical, as it prevents other framework components from overwriting this specific error with a more generic 400 or 500 status code. After sending the response, the stream throws a PayloadTooLargeException to halt further processing of the request. The filter catches and swallows this exception, as the response has already been finalized.
The filter includes a defensive guard for multipart requests (e.g., file uploads). Container-level multipart parsing can potentially bypass the filter's counting stream. To prevent this:
getParts() or getPart() on a chunked-encoded request are blocked, resulting in a PayloadTooLargeException.Content-Length that has already passed the fast-path check, multipart parsing is allowed to proceed safely.When a request is rejected, the rejectOversized method is invoked to generate a standardized error response.
RuntimeLogRepository with the error code S2R-RUN-0413.Authorization have their values replaced with a placeholder.CONSUME and GATEWAY paths, which are SOAP-inbound, a SOAP Fault XML envelope is returned to comply with SOAP client expectations.PUBLISH), a standard JSON error object is returned.X-Correlation-Id header is included in the response.The payload limit is determined by the following order of precedence:
max_sync_payload_mb in the RuntimeSettingRepository. This value is checked and refreshed every 60 seconds.S2R_MAX_SYNC_PAYLOAD_MB environment variable, used as a fallback if the database setting is absent.The effective limit is always at least 1 MB, regardless of the configured value.
The payload limit can be configured via an environment variable or a database setting. The database setting takes precedence and is refreshed dynamically at runtime.
| Name | Type | Default | Required | Description |
|---|---|---|---|---|
S2R_MAX_SYNC_PAYLOAD_MB | Integer | 30 | No | Environment variable setting the default maximum payload size in megabytes (MB). This is used as a fallback when the database setting is not available. The minimum effective value is 1. |
max_sync_payload_mb | Integer | — | No | Database setting key. If a value for this key exists in the settings repository, it overrides the environment variable. The filter polls for changes to this value every 60 seconds. |
When a request payload exceeds the configured limit, the filter responds with an HTTP 413 Payload Too Large status. The body of the response varies based on the request path.
For most API paths, such as PUBLISH, the filter returns a JSON error object.
{
"error": {
"code": "S2R-RUN-0413",
"message": "Payload too large",
"details": {
"maxPayloadMb": 30
},
"correlationId": "a1b2c3d4-e5f6-7890-1234-567890abcdef"
}
}
For SOAP-inbound paths, specifically CONSUME and GATEWAY, the filter returns a SOAP 1.1 Fault envelope to maintain protocol correctness.
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Payload exceeds limit (S2R-RUN-0413)</faultstring>
<detail>
<errorCode>S2R-RUN-0413</errorCode>
<maxPayloadMb>30</maxPayloadMb>
<correlationId>a1b2c3d4-e5f6-7890-1234-567890abcdef</correlationId>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
max_sync_payload_mb limit.faultcode of soap:Client in the SOAP response indicates the issue originates from the client-side request.maxPayloadMb field of the error response body. API publishers can adjust this limit via the max_sync_payload_mb runtime setting.