fix: return 400 MalformedXML for unparseable PutObjectRetention RetainUntilDate (#1631)

PutObjectRetention crashed with an uncaught DateTimeParseException when
RetainUntilDate could not be parsed, leaking as an HTTP 500 HTML page.
Wrap the Instant.parse call and throw an AwsException mapped to HTTP 400
MalformedXML, matching real AWS S3 behavior.

Fixes #1614
This commit is contained in:
Matt Van Horn authored and GitHub committed 2026-07-22 08:58:12 -04:00
1 parent ac8a3d7c82
commit 526a62317f
2 files changed
+82 -2

No files matched your search

@@ -46,6 +46,7 @@ import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
@@ -1753,7 +1754,13 @@ public class S3Controller {
String xml = new String(body, StandardCharsets.UTF_8);
String mode = XmlParser.extractFirst(xml, "Mode", null);
String dateStr = XmlParser.extractFirst(xml, "RetainUntilDate", null);
Instant retainUntil = dateStr != null ? Instant.parse(dateStr) : null;
Instant retainUntil;
try {
retainUntil = dateStr != null ? Instant.parse(dateStr) : null;
} catch (DateTimeParseException | IllegalArgumentException e) {
throw new AwsException("MalformedXML",
"The XML you provided was not well-formed.", 400);
}
boolean bypass = "true".equalsIgnoreCase(
httpHeaders.getHeaderString("x-amz-bypass-governance-retention"));
s3Service.putObjectRetention(bucket, key, versionId, mode, retainUntil, bypass);