fix(dynamodb): reject a too deep transact value before the transaction runs (#5483)

* fix(dynamodb): reject a too deep transact value before the transaction runs

* fix(dynamodb): report a too deep transact result on every member
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-12 06:51:47 -04:00
1 parent 1aabc8b4fe
commit 6e38c080fb
3 files changed
+151 -42

No files matched your search

@@ -1821,9 +1821,10 @@ public class DynamoDbService {
List<TransactionCanceledException.CancellationReason> cancellationReasons = new ArrayList<>();
boolean hasFailed = false;
for (JsonNode transactItem : transactItems) {
var failReason = transactUpdateValueTooDeep(transactItem);
TransactionCanceledException.CancellationReason failReason =
evaluateTransactCondition(transactItem, region, staged);
if (failReason == null) {
failReason = evaluateTransactCondition(transactItem, region, staged);
failReason = transactItemValidationFailure(transactItem, region, staged);
}
if (failReason != null) {
hasFailed = true;
@@ -1835,15 +1836,6 @@ public class DynamoDbService {
if (hasFailed) {
throw new TransactionCanceledException(cancellationReasons);
}
for (int i = 0; i < transactItems.size(); i++) {
try {
validateTransactItem(transactItems.get(i), region, staged);
} catch (KeySchemaMismatchException | ItemNestingExceededException
| UpdatedItemTooLargeException e) {
throw cancelledByMember(transactItems.size(), i, e.getMessage());
}
}
List<JsonNode> oldImages = stagedImages(memberParticipants, staged);
for (JsonNode transactItem : transactItems) {
if (transactItem.has("Put")) {
@@ -1974,17 +1966,6 @@ public class DynamoDbService {
return new TransactParticipant(storageKey, itemKey, tableName);
}
// AWS checks the depth of a transact Update's values as part of that member, so a too
// deep value cancels the transaction instead of failing the request up front.
private TransactionCanceledException.CancellationReason transactUpdateValueTooDeep(JsonNode transactItem) {
var values = transactItem.path("Update").get("ExpressionAttributeValues");
if (DynamoDbAttributeValueValidator.nestingWithinLimit(values)) {
return null;
}
return new TransactionCanceledException.CancellationReason("ValidationError", null,
"Nesting Levels have exceeded supported limits");
}
// AWS checks every member's key against the table schema, in order, before it looks for
// duplicate items or evaluates a condition. The first mismatch cancels with that member's
// reason alone. An empty key value still fails the whole request.
@@ -2043,6 +2024,17 @@ public class DynamoDbService {
return new TransactionCanceledException(reasons);
}
private TransactionCanceledException.CancellationReason transactItemValidationFailure(
JsonNode transactItem, String region,
Map<String, ConcurrentSkipListMap<String, JsonNode>> staged) {
try {
validateTransactItem(transactItem, region, staged);
return null;
} catch (KeySchemaMismatchException | ItemNestingExceededException | UpdatedItemTooLargeException e) {
return new TransactionCanceledException.CancellationReason("ValidationError", null, e.getMessage());
}
}
private TransactionCanceledException.CancellationReason evaluateTransactCondition(JsonNode transactItem, String region) {
return evaluateTransactCondition(transactItem, region, null);
}
@@ -1904,6 +1904,11 @@ public class NativeDynamoDbJsonHandler {
? op.get("UpdateExpression").asText() : null;
JsonNode opExprAttrNames = op.get("ExpressionAttributeNames");
JsonNode opExprAttrValues = op.get("ExpressionAttributeValues");
// AWS checks the depth of every value of a member before anything else,
// so even an unused or condition-only value fails the request.
DynamoDbAttributeValueValidator.requireNestingWithinLimit(op.get("Item"), false);
DynamoDbAttributeValueValidator.requireNestingWithinLimit(op.get("Key"), false);
DynamoDbAttributeValueValidator.requireNestingWithinLimit(opExprAttrValues, false);
DynamoDbExpressionSize.checkRead(op.path("UpdateExpression").textValue(), "UpdateExpression");
DynamoDbExpressionSize.checkReadWithSize(conditionExpression, "ConditionExpression");
ExpressionEvaluator.validateSyntax(conditionExpression, "ConditionExpression");
@@ -1913,7 +1918,6 @@ public class NativeDynamoDbJsonHandler {
requireDefinedTokens(conditionExpression, "ConditionExpression", opExprAttrNames, opExprAttrValues);
ExpressionEvaluator.validateSemantics(conditionExpression, "ConditionExpression",
opExprAttrNames, opExprAttrValues);
DynamoDbAttributeValueValidator.requireNestingWithinLimit(op.get("Item"), false);
dynamoDbService.requireAddOrDeleteOperandTypes(op.path("UpdateExpression").textValue(),
opExprAttrValues, false);
}