fix(core): accept only JSON objects as JSON protocol request bodies (#3509)

The JSON 1.0 and 1.1 dispatchers handed whatever Jackson parsed straight
to the handlers, so a body of null, [] or a scalar reached code that
expects an object and failed with an unhelpful 500 instead of the
SerializationException AWS returns. Both dispatchers now reject any body
that is not a JSON object with the standard 400 SerializationException.

An empty or whitespace only body is still read as {}. The awsJson1_1
protocol requires services to accept no payload for operations that
define no input, and clients rely on that for calls such as Organizations
DescribeOrganization.
This commit is contained in:
Niels Kootstra authored and GitHub committed 2026-09-13 00:03:31 -04:00
1 parent 76c1907214
commit 9f9a828439
3 files changed
+104 -2

No files matched your search

@@ -97,6 +97,92 @@ class JsonMalformedInputIntegrationTest {
.statusCode(200);
}
// ── Dispatcher: the body must be a JSON object; no body at all is the wire form of "no input" ──
@Test
void emptyBodyOnJson11IsReadAsEmptyInput() {
req(JSON_1_1, "TrentService.ListKeys", "")
.when().post("/")
.then()
.statusCode(200);
}
@Test
void whitespaceOnlyBodyOnJson11IsReadAsEmptyInput() {
req(JSON_1_1, "TrentService.ListKeys", " \n ")
.when().post("/")
.then()
.statusCode(200);
}
@Test
void emptyBodyOnJson11NoInputOperationBehavesLikeEmptyObject() {
// The awsJson1_1 protocol requires services to accept no payload for operations that
// define no input, so an empty body must be answered exactly like {}.
int statusWithEmptyObject = req(JSON_1_1, "AWSOrganizationsV20161128.DescribeOrganization", "{}")
.when().post("/")
.then().extract().statusCode();
req(JSON_1_1, "AWSOrganizationsV20161128.DescribeOrganization", "")
.when().post("/")
.then()
.statusCode(statusWithEmptyObject)
.body("__type", not(equalTo("SerializationException")));
}
@Test
void emptyBodyOnJson10IsReadAsEmptyInput() {
req(JSON_1_0, "DynamoDB_20120810.ListTables", "")
.when().post("/")
.then()
.statusCode(200);
}
@Test
void jsonNullBodyOnJson11IsSerializationException() {
req(JSON_1_1, "TrentService.ListKeys", "null")
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void arrayBodyOnJson11IsSerializationException() {
req(JSON_1_1, "TrentService.ListKeys", "[]")
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void scalarBodyOnJson11IsSerializationException() {
req(JSON_1_1, "TrentService.ListKeys", "\"ListKeys\"")
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void jsonNullBodyOnJson10IsSerializationException() {
req(JSON_1_0, "DynamoDB_20120810.ListTables", "null")
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
@Test
void arrayBodyOnJson10IsSerializationException() {
req(JSON_1_0, "DynamoDB_20120810.ListTables", "[]")
.when().post("/")
.then()
.statusCode(400)
.body("__type", equalTo("SerializationException"));
}
// ── KMS: base64 blob fields ──
@Test