mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -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 {
|
||||
|
||||
Reference in new issue
Block a user