mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
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:
1 parent
76c1907214
commit
9f9a828439
3 files changed
+104
-2
No files matched your search
@@ -276,10 +276,18 @@ public class AwsJson11Controller {
|
||||
|
||||
JsonNode request;
|
||||
try {
|
||||
request = strictBodyReader.readTree(body);
|
||||
// No payload is how an operation without input goes over the wire, so it reads as {}.
|
||||
request = body == null || body.isBlank()
|
||||
? objectMapper.createObjectNode()
|
||||
: strictBodyReader.readTree(body);
|
||||
} catch (JsonProcessingException e) {
|
||||
return JsonErrorResponseUtils.createSerializationErrorResponse();
|
||||
}
|
||||
// Input is always a structure: a bare null, array or scalar parses but is still a
|
||||
// client serialization error rather than something every handler must guard against.
|
||||
if (!request.isObject()) {
|
||||
return JsonErrorResponseUtils.createSerializationErrorResponse();
|
||||
}
|
||||
|
||||
try {
|
||||
String region = regionResolver.resolveRegion(httpHeaders);
|
||||
|
||||
@@ -111,10 +111,18 @@ public class AwsJsonController {
|
||||
|
||||
JsonNode request;
|
||||
try {
|
||||
request = strictBodyReader.readTree(body);
|
||||
// No payload is how an operation without input goes over the wire, so it reads as {}.
|
||||
request = body == null || body.isBlank()
|
||||
? objectMapper.createObjectNode()
|
||||
: strictBodyReader.readTree(body);
|
||||
} catch (JsonProcessingException e) {
|
||||
return JsonErrorResponseUtils.createSerializationErrorResponse();
|
||||
}
|
||||
// Input is always a structure: a bare null, array or scalar parses but is still a
|
||||
// client serialization error rather than something every handler must guard against.
|
||||
if (!request.isObject()) {
|
||||
return JsonErrorResponseUtils.createSerializationErrorResponse();
|
||||
}
|
||||
|
||||
Response response;
|
||||
try {
|
||||
|
||||
+86
@@ -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
|
||||
|
||||
Reference in new issue
Block a user