mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(dynamodb): refuse a repeated section in an UpdateExpression (#8167)
This commit is contained in:
1 parent
438e01a225
commit
891c0cd58f
3 files changed
+109
-2
No files matched your search
@@ -3541,6 +3541,7 @@ public class DynamoDbService {
|
||||
// name as a bare identifier instead.
|
||||
String remaining = expression.trim().replaceAll("\\s+", " ");
|
||||
DynamoDbReservedWords.check(remaining, "UpdateExpression");
|
||||
requireSectionsUsedOnce(remaining);
|
||||
|
||||
while (!remaining.isEmpty()) {
|
||||
String upper = remaining.toUpperCase();
|
||||
@@ -4454,10 +4455,24 @@ public class DynamoDbService {
|
||||
}
|
||||
}
|
||||
|
||||
static void requireSectionsUsedOnce(String expression) {
|
||||
Set<String> seen = new HashSet<>();
|
||||
for (ExpressionEvaluator.Token token : ExpressionEvaluator.tokenize(expression)) {
|
||||
String word = token.value().toUpperCase(Locale.ROOT);
|
||||
if (token.type() == ExpressionEvaluator.TokenType.IDENTIFIER && UPDATE_SECTIONS.contains(word)
|
||||
&& !seen.add(word)) {
|
||||
throw new AwsException("ValidationException", "Invalid UpdateExpression: The \"" + word
|
||||
+ "\" section can only be used once in an update expression;", 400);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isUpdatePunctuation(char c) {
|
||||
return "()[],.=+-".indexOf(c) >= 0;
|
||||
}
|
||||
|
||||
private static final Set<String> UPDATE_SECTIONS = Set.of("SET", "REMOVE", "ADD", "DELETE");
|
||||
|
||||
// DynamoDB reads a SET target path up to "=", so a comma before it fails on the comma.
|
||||
static void requireAssignmentAfterSetTarget(String expression) {
|
||||
List<ExpressionEvaluator.Token> tokens = ExpressionEvaluator.tokenize(expression);
|
||||
@@ -4491,7 +4506,7 @@ public class DynamoDbService {
|
||||
case COMMA -> target = inSet && depth == 0 ? i + 1 : -1;
|
||||
case IDENTIFIER -> {
|
||||
String word = token.value().toUpperCase(Locale.ROOT);
|
||||
if (depth == 0 && List.of("SET", "REMOVE", "ADD", "DELETE").contains(word)) {
|
||||
if (depth == 0 && UPDATE_SECTIONS.contains(word)) {
|
||||
inSet = word.equals("SET");
|
||||
target = inSet ? i + 1 : -1;
|
||||
}
|
||||
|
||||
@@ -1061,11 +1061,12 @@ public class NativeDynamoDbJsonHandler {
|
||||
ExpressionEvaluator.validateSemantics(conditionExpression, "ConditionExpression", exprAttrNames, exprAttrValues);
|
||||
requireNonEmptyExpression(updateExpression, "UpdateExpression");
|
||||
DynamoDbReservedWords.check(ue, "UpdateExpression");
|
||||
dynamoDbService.requireAddOrDeleteOperandTypes(updateExpression, exprAttrValues, true);
|
||||
DynamoDbService.requireSectionsUsedOnce(updateExpression);
|
||||
Set<String> hashTokens = extractHashTokens(updateExpression, conditionExpression);
|
||||
checkUnusedEan(exprAttrNames, hashTokens);
|
||||
Set<String> colonTokensAll = extractColonTokens(updateExpression, conditionExpression);
|
||||
checkUnusedEav(exprAttrValues, colonTokensAll);
|
||||
dynamoDbService.requireAddOrDeleteOperandTypes(updateExpression, exprAttrValues, true);
|
||||
} else {
|
||||
ExpressionEvaluator.validateSemantics(conditionExpression, "ConditionExpression", exprAttrNames, exprAttrValues);
|
||||
}
|
||||
@@ -3162,6 +3163,9 @@ public class NativeDynamoDbJsonHandler {
|
||||
DynamoDbExpressionSize.checkRead(updateExpression, "UpdateExpression");
|
||||
requireDefinedTokens(updateExpression, "UpdateExpression", exprAttrNames, exprAttrValues);
|
||||
dynamoDbService.requireAddOrDeleteOperandTypes(updateExpression, exprAttrValues, false);
|
||||
if (updateExpression != null) {
|
||||
DynamoDbService.requireSectionsUsedOnce(updateExpression);
|
||||
}
|
||||
|
||||
checkUnusedEan(exprAttrNames, extractHashTokens(conditionExpression, updateExpression));
|
||||
checkUnusedEav(exprAttrValues, extractColonTokens(conditionExpression, updateExpression));
|
||||
|
||||
Reference in new issue
Block a user