mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(dynamodb): reject out-of-bound query cursors (#3389)
Signed-off-by: 7487 <1042653432@qq.com>
This commit is contained in:
1 parent
ce073930b9
commit
862e4a1c77
2 files changed
+64
No files matched your search
@@ -944,6 +944,8 @@ public class DynamoDbService implements ResourceProvider {
|
||||
String partitionKeyValuePlaceholder = DynamoDbAccessPathValidator.validateQuery(
|
||||
table, accessPath, keyConditions, keyConditionExpression, filterExpression,
|
||||
null, exprAttrNames, expressionAttrValues);
|
||||
validateExclusiveStartKeyWithinQuery(exclusiveStartKey, table, accessPath, keyConditions,
|
||||
keyConditionExpression, expressionAttrValues, exprAttrNames);
|
||||
String pkName = accessPath.partitionKeyName();
|
||||
List<String> pkNames = accessPath.partitionKeyNames();
|
||||
String skName = accessPath.sortKeyName();
|
||||
@@ -3371,6 +3373,26 @@ public class DynamoDbService implements ResourceProvider {
|
||||
};
|
||||
}
|
||||
|
||||
private void validateExclusiveStartKeyWithinQuery(JsonNode exclusiveStartKey, TableDefinition table,
|
||||
DynamoDbAccessPath accessPath, JsonNode keyConditions,
|
||||
String keyConditionExpression, JsonNode expressionAttrValues,
|
||||
JsonNode expressionAttrNames) {
|
||||
if (exclusiveStartKey == null || exclusiveStartKey.isNull()) {
|
||||
return;
|
||||
}
|
||||
DynamoDbAccessPathValidator.validateExclusiveStartKey(exclusiveStartKey, table, accessPath, false);
|
||||
|
||||
boolean withinBounds = keyConditionExpression != null
|
||||
? ExpressionEvaluator.matches(keyConditionExpression, exclusiveStartKey,
|
||||
expressionAttrNames, expressionAttrValues)
|
||||
: keyConditions.properties().stream().allMatch(entry ->
|
||||
matchesKeyCondition(exclusiveStartKey.get(entry.getKey()), entry.getValue()));
|
||||
if (!withinBounds) {
|
||||
throw new AwsException("ValidationException",
|
||||
"The provided starting key is outside query boundaries based on provided condition", 400);
|
||||
}
|
||||
}
|
||||
|
||||
private List<JsonNode> queryWithExpression(ConcurrentSkipListMap<String, JsonNode> items,
|
||||
String partitionKeyName,
|
||||
String partitionKeyValuePlaceholder,
|
||||
|
||||
+42
@@ -366,6 +366,48 @@ class DynamoDbAccessPathIntegrationTest {
|
||||
.body("__type", equalTo("ValidationException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryRejectsExclusiveStartKeyOutsideKeyCondition() {
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk",
|
||||
"ExpressionAttributeValues":{":pk":{"S":"p2"}},
|
||||
"ExclusiveStartKey":{"pk":{"S":"p1"},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(
|
||||
"The provided starting key is outside query boundaries based on provided condition"));
|
||||
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditions":{
|
||||
"pk":{"ComparisonOperator":"EQ","AttributeValueList":[{"S":"p2"}]}
|
||||
},
|
||||
"ExclusiveStartKey":{"pk":{"S":"p1"},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(400)
|
||||
.body("__type", equalTo("ValidationException"))
|
||||
.body("message", equalTo(
|
||||
"The provided starting key is outside query boundaries based on provided condition"));
|
||||
|
||||
request("DynamoDB_20120810.Query", """
|
||||
{
|
||||
"TableName":"%s",
|
||||
"KeyConditionExpression":"pk = :pk",
|
||||
"ExpressionAttributeValues":{":pk":{"S":"p1"}},
|
||||
"ExclusiveStartKey":{"pk":{"S":"p1"},"sk":{"S":"s1"}}
|
||||
}
|
||||
""".formatted(TABLE))
|
||||
.statusCode(200)
|
||||
.body("Count", equalTo(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(10)
|
||||
void queryRejectsMalformedNumericExclusiveStartKey() {
|
||||
|
||||
Reference in new issue
Block a user