Fix/lambda incorrect size limit (#674)

* fix(http): remove 8 KB per-attribute limit on form-encoded request bodies

Vert.x 4.x defaults HttpServerOptions.maxFormAttributeSize to a small
value (effectively 8 KB via the Netty AbstractHttpData limit). This
causes any request with Content-Type: application/x-www-form-urlencoded
that carries a single attribute larger than the limit to be rejected with
"Size exceed allowed maximum capacity".

Two places fixed:

- HttpOptionsCustomizer (new CDI bean): sets maxFormAttributeSize=-1 on
  the main Quarkus HTTP server so large form-encoded AWS Query Protocol
  requests (CloudFormation templates, EC2 UserData in base64, large IAM
  policies, etc.) are accepted. The overall body size is still bounded
  by quarkus.http.limits.max-body-size (512 MB).

- RuntimeApiServer: passes HttpServerOptions with maxFormAttributeSize=-1
  when creating the per-container Vert.x HTTP server. This fixes the case
  where the Lambda runtime posts a large synchronous response body (e.g.
  a 5 MB base64 payload) back to the Runtime API endpoint and the body
  is incorrectly decoded through the form attribute path.

* fix(lambda): enforce AWS invoke payload size limits (sync 6 MB, async 1 MB)

Rejects oversized invocation requests with HTTP 413 RequestTooLargeException
before dispatching to the container, matching the AWS Lambda API contract.
Also enforces the 6 MB sync response limit after the function returns.

* test(lambda): add tests for invoke payload size limits

Unit/integration tests (LambdaIntegrationTest) cover sync >6 MB and async >1 MB
request rejections plus boundary-at-limit acceptance. Compat test
(LambdaPayloadSizeLimitTest) uses the Java SDK to verify RequestTooLargeException
is surfaced correctly, including a Docker-gated test for the 6 MB response limit.

* test(lambda): add regression test for 5 MB response via RuntimeApiServer

Verifies that a sync invocation returning a 5 MB body (within the 6 MB AWS
limit) succeeds end-to-end. Without the maxFormAttributeSize fix on the
RuntimeApiServer, the Lambda runtime's POST of the large response body was
rejected by Netty's 8 KB form-attribute cap, crashing the request with
"Size exceed allowed maximum capacity".
This commit is contained in:
Yorí authored and GitHub committed 2026-04-30 18:08:36 -05:00
1 parent c2b635019b
commit 3f4865b949
6 files changed
+300 -1

No files matched your search

@@ -0,0 +1,34 @@
package io.github.hectorvent.floci.config;
import io.quarkus.vertx.http.HttpServerOptionsCustomizer;
import io.vertx.core.http.HttpServerOptions;
import jakarta.enterprise.context.ApplicationScoped;
/**
* Removes the 8 KB per-attribute limit imposed by Vert.x's default
* {@code HttpServerOptions.maxFormAttributeSize}.
*
* Without this, any request that arrives with
* {@code Content-Type: application/x-www-form-urlencoded} and a single
* attribute value larger than ~8 KB is rejected by Netty's form decoder
* with "Size exceed allowed maximum capacity". This hits real AWS APIs
* that use the Query Protocol: CloudFormation templates, EC2 UserData
* (base64-encoded), large IAM policies, etc.
*
* The overall request body size is still bounded by
* {@code quarkus.http.limits.max-body-size} (default 512 MB), so raising
* the per-attribute limit to unlimited is safe.
*/
@ApplicationScoped
public class HttpOptionsCustomizer implements HttpServerOptionsCustomizer {
@Override
public void customizeHttpServer(HttpServerOptions options) {
options.setMaxFormAttributeSize(-1);
}
@Override
public void customizeHttpsServer(HttpServerOptions options) {
options.setMaxFormAttributeSize(-1);
}
}
@@ -195,6 +195,10 @@ public class LambdaController {
// ──────────────────────────── Invoke ────────────────────────────
private static final int SYNC_REQUEST_LIMIT = 6 * 1024 * 1024;
private static final int ASYNC_REQUEST_LIMIT = 1 * 1024 * 1024;
private static final int SYNC_RESPONSE_LIMIT = 6 * 1024 * 1024;
@POST
@Path("/functions/{functionName}/invocations")
@Consumes(MediaType.WILDCARD)
@@ -205,8 +209,31 @@ public class LambdaController {
String invocationTypeHeader = headers.getHeaderString("X-Amz-Invocation-Type");
InvocationType type = InvocationType.parse(invocationTypeHeader);
int payloadSize = payload != null ? payload.length : 0;
if (type == InvocationType.Event && payloadSize > ASYNC_REQUEST_LIMIT) {
return Response.status(413)
.type(MediaType.APPLICATION_JSON)
.entity("{\"__type\":\"RequestTooLargeException\",\"message\":\"The request payload exceeded the Invoke request body JSON input quota.\"}")
.build();
}
if (type != InvocationType.Event && payloadSize > SYNC_REQUEST_LIMIT) {
return Response.status(413)
.type(MediaType.APPLICATION_JSON)
.entity("{\"__type\":\"RequestTooLargeException\",\"message\":\"The request payload exceeded the Invoke request body JSON input quota.\"}")
.build();
}
InvokeResult result = lambdaService.invoke(region, functionName, payload, type);
if (type != InvocationType.Event
&& result.getPayload() != null
&& result.getPayload().length > SYNC_RESPONSE_LIMIT) {
return Response.status(413)
.type(MediaType.APPLICATION_JSON)
.entity("{\"__type\":\"RequestTooLargeException\",\"message\":\"The response payload exceeded the maximum allowed payload size (6 MB).\"}")
.build();
}
Response.ResponseBuilder builder = Response.status(result.getStatusCode());
if (result.getFunctionError() != null) {
@@ -4,6 +4,7 @@ import io.github.hectorvent.floci.services.lambda.model.InvokeResult;
import io.github.hectorvent.floci.services.lambda.model.PendingInvocation;
import io.vertx.core.Vertx;
import io.vertx.core.http.HttpServer;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.BodyHandler;
@@ -131,7 +132,8 @@ public class RuntimeApiServer {
ctx.response().setStatusCode(202).end();
});
httpServer = vertx.createHttpServer();
httpServer = vertx.createHttpServer(new HttpServerOptions()
.setMaxFormAttributeSize(-1));
httpServer.requestHandler(router).listen(port, "0.0.0.0", result -> {
if (result.succeeded()) {
LOG.debugv("RuntimeApiServer started on port {0}", port);