fix(dynamodb): refuse an empty attribute name in a TransactWriteItems item, key or value (#7389)

This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-03 08:20:20 -04:00
1 parent 886f626b4d
commit 121dc22563
4 files changed
+75 -1

No files matched your search

@@ -210,6 +210,43 @@ final class DynamoDbAttributeValueValidator {
return true;
}
static final String EMPTY_ATTRIBUTE_NAME = "Empty attribute name";
static void requireNonEmptyNames(JsonNode attributes) {
if (attributes != null && attributes.has("")) {
throw validationEx(EMPTY_ATTRIBUTE_NAME);
}
}
static void requireNonEmptyMemberNames(JsonNode values) {
if (values == null) {
return;
}
for (JsonNode value : values) {
if (hasEmptyMemberName(value)) {
throw validationEx(EMPTY_ATTRIBUTE_NAME);
}
}
}
private static boolean hasEmptyMemberName(JsonNode value) {
JsonNode members = value.path("M");
if (members.has("")) {
return true;
}
for (JsonNode member : members) {
if (hasEmptyMemberName(member)) {
return true;
}
}
for (JsonNode element : value.path("L")) {
if (hasEmptyMemberName(element)) {
return true;
}
}
return false;
}
private static int depthOf(JsonNode value) {
if (!value.isObject()) {
return 1;
@@ -2794,9 +2794,14 @@ public class NativeDynamoDbJsonHandler {
private static void requireTransactItemOrKey(TransactAction action) {
JsonNode op = action.op();
JsonNode values = op.get("Put".equals(action.type()) ? "Item" : "Key");
// In a request too deep for the newer validator, DynamoDB checks the top-level names before the depth
// and the names inside a map after it.
DynamoDbAttributeValueValidator.requireNonEmptyNames(values);
DynamoDbAttributeValueValidator.requireNestingWithinLimit(op.get("Item"), false);
DynamoDbAttributeValueValidator.requireNestingWithinLimit(op.get("Key"), false);
requireReadableValues(op.get("Put".equals(action.type()) ? "Item" : "Key"), "");
requireReadableValues(values, "");
DynamoDbAttributeValueValidator.requireNonEmptyMemberNames(values);
}
private void requireValidTransactExpressions(JsonNode op, boolean older) {
@@ -2812,6 +2817,7 @@ public class NativeDynamoDbJsonHandler {
requireNamedExpressionValues(exprAttrValues);
} else {
requireReadableValues(exprAttrValues, "");
DynamoDbAttributeValueValidator.requireNonEmptyMemberNames(exprAttrValues);
}
requireNonEmptyExpression(conditionExpression, "ConditionExpression");
@@ -2847,6 +2853,7 @@ public class NativeDynamoDbJsonHandler {
try {
DynamoDbAttributeValueValidator.requireNestingWithinLimit(value, false);
requireReadableValues(value, "");
DynamoDbAttributeValueValidator.requireNonEmptyMemberNames(value);
} catch (AwsException e) {
throw new AwsException("ValidationException", "ExpressionAttributeValues contains invalid value: "
+ e.getMessage() + " for key " + entry.getKey(), 400);