fix(apigatewayv2): raise Vert.x WebSocket frame size limit to 256 KB (#938)

Vert.x defaults maxWebSocketFrameSize to 64 KB. The Node.js ws library
sends messages as a single frame (no fragmentation), so payloads at or
above 128 KB are silently rejected at the transport level before reaching
the application-level size check in WebSocketHandler.

This caused the sdk-test-node compatibility tests for payload size limits
to timeout waiting for the 'Message too long' error response that never
arrived.

Raise both maxWebSocketFrameSize and maxWebSocketMessageSize to 256 KB
so that oversized frames reach the handler, which then enforces the AWS
128 KB limit and returns a proper error frame.

Co-authored-by: Dixit R Jain <dixitrjain@Mac-1086.lan>
This commit is contained in:
Dixit R JainandDixit R Jain authored and GitHub committed 2026-05-19 17:58:04 -05:00
1 parent 43332cef77
commit c0d6b71eb1
1 file changed
+33 -10
@@ -5,30 +5,53 @@ 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}.
* Customizes Vert.x HTTP server options for Floci's requirements.
*
* 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.
* <ul>
* <li>Removes the 8 KB per-attribute limit imposed by Vert.x's default
* {@code HttpServerOptions.maxFormAttributeSize}. Without this, any request
* 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.
* This hits real AWS APIs that use the Query Protocol: CloudFormation templates,
* EC2 UserData (base64-encoded), large IAM policies, etc.</li>
* <li>Raises the WebSocket frame and message size limits to accommodate payloads
* up to 128 KB, matching the AWS API Gateway WebSocket payload limit. Vert.x
* defaults to 64 KB per frame, which causes Netty to silently reject larger
* frames before the application-level size check in
* {@code WebSocketHandler} can fire.</li>
* </ul>
*
* 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.
* {@code quarkus.http.limits.max-body-size} (default 512 MB).
*/
@ApplicationScoped
public class HttpOptionsCustomizer implements HttpServerOptionsCustomizer {
/**
* Maximum WebSocket frame size: 256 KB.
* AWS API Gateway allows up to 128 KB payloads. We set the transport limit higher
* so that oversized frames (e.g. 128 KB + 1 byte) still reach the application-level
* handler in {@code WebSocketHandler}, which sends back a proper error response.
*/
private static final int MAX_WS_FRAME_SIZE = 256 * 1024;
/**
* Maximum WebSocket message size (reassembled from multiple frames).
* Set to the same value as the frame limit.
*/
private static final int MAX_WS_MESSAGE_SIZE = 256 * 1024;
@Override
public void customizeHttpServer(HttpServerOptions options) {
options.setMaxFormAttributeSize(-1);
options.setMaxWebSocketFrameSize(MAX_WS_FRAME_SIZE);
options.setMaxWebSocketMessageSize(MAX_WS_MESSAGE_SIZE);
}
@Override
public void customizeHttpsServer(HttpServerOptions options) {
options.setMaxFormAttributeSize(-1);
options.setMaxWebSocketFrameSize(MAX_WS_FRAME_SIZE);
options.setMaxWebSocketMessageSize(MAX_WS_MESSAGE_SIZE);
}
}