fix(dynamodb): reject every mix of expression and non-expression parameters in Query and Scan (#5619)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-14 14:09:10 -04:00
1 parent 988991033f
commit 804335d071
3 files changed
+76 -35

No files matched your search

@@ -1098,26 +1098,12 @@ public class NativeDynamoDbJsonHandler {
+ "Member must satisfy enum value set: [INDEXES, TOTAL, NONE]", 400);
}
if (keyConditionExpr != null && keyConditions != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {KeyConditions} Expression parameters: {KeyConditionExpression}", 400);
}
if (keyConditionExpr != null && queryFilter != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}", 400);
}
if (filterExpr != null && queryFilter != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {QueryFilter} Expression parameters: {FilterExpression}", 400);
}
if (attributesToGet != null && projectionExpression != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}", 400);
}
// DynamoDB counts KeyConditions as a non-expression parameter only next to a KeyConditionExpression.
rejectMixedParameters(request,
keyConditionExpr == null
? List.of("AttributesToGet", "QueryFilter", "ConditionalOperator")
: List.of("AttributesToGet", "QueryFilter", "ConditionalOperator", "KeyConditions"),
List.of("ProjectionExpression", "FilterExpression", "KeyConditionExpression"));
if (keyConditionExpr == null && keyConditions == null) {
throw new AwsException("ValidationException",
@@ -1254,12 +1240,6 @@ public class NativeDynamoDbJsonHandler {
Integer segment = request.has("Segment") ? request.get("Segment").asInt() : null;
Integer totalSegments = request.has("TotalSegments") ? request.get("TotalSegments").asInt() : null;
if (filterExpr != null && scanFilter != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {ScanFilter} Expression parameters: {FilterExpression}", 400);
}
List<String> rangeErrors = new ArrayList<>();
if (limit != null && limit < 1) {
rangeErrors.add("Value at 'Limit' failed to satisfy constraint: "
@@ -1279,6 +1259,10 @@ public class NativeDynamoDbJsonHandler {
}
throwValidationErrors(rangeErrors);
rejectMixedParameters(request,
List.of("AttributesToGet", "ScanFilter", "ConditionalOperator"),
List.of("ProjectionExpression", "FilterExpression"));
if (segment != null && totalSegments == null) {
throw new AwsException("ValidationException",
"The TotalSegments parameter is required but was not present in the request when Segment parameter is present", 400);
@@ -1311,11 +1295,6 @@ public class NativeDynamoDbJsonHandler {
"1 validation error detected: Value '" + select + "' at 'select' failed to satisfy constraint: "
+ "Member must satisfy enum value set: [SPECIFIC_ATTRIBUTES, COUNT, ALL_ATTRIBUTES, ALL_PROJECTED_ATTRIBUTES]", 400);
}
if (projectionExpressionScan != null && attributesToGetScan != null) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {AttributesToGet} Expression parameters: {ProjectionExpression}", 400);
}
boolean hasAttributesToGetScan = attributesToGetScan != null && attributesToGetScan.size() > 0;
if ("SPECIFIC_ATTRIBUTES".equals(select)
&& projectionExpressionScan == null && !hasAttributesToGetScan) {
@@ -2040,6 +2019,18 @@ public class NativeDynamoDbJsonHandler {
throwValidationErrors(validationErrors);
}
private static void rejectMixedParameters(JsonNode request, List<String> nonExpressionNames,
List<String> expressionNames) {
List<String> nonExpression = nonExpressionNames.stream().filter(request::has).toList();
List<String> expression = expressionNames.stream().filter(request::has).toList();
if (!nonExpression.isEmpty() && !expression.isEmpty()) {
throw new AwsException("ValidationException",
"Can not use both expression and non-expression parameters in the same request: "
+ "Non-expression parameters: {" + String.join(", ", nonExpression)
+ "} Expression parameters: {" + String.join(", ", expression) + "}", 400);
}
}
private static void throwValidationErrors(List<String> validationErrors) {
if (validationErrors.isEmpty()) {
return;