fix(s3): compare conditional GET dates at second precision (#5598)

A client revalidating with the Last-Modified it was given now gets 304
for If-Modified-Since and 200 for If-Unmodified-Since on GetObject and
HeadObject, as S3 answers.

Objects are stamped to the millisecond while Last-Modified and HTTP
dates carry whole seconds, so at an object's own Last-Modified the
stored time was up to 999 ms later than the header and compared as
modified. checkPreconditions now truncates the stored time to seconds
before the date comparisons, as checkCopySourcePreconditions and
ByteRange.rangeApplies already do.

Tests: a stubbed object stamped .456Z covers both headers at LM-1s, LM
and LM+1s on GET and HEAD, with a .000Z control; the at-LM .456Z cases
fail without the fix. HTTP round-trip tests cover the real write path.
This commit is contained in:
TiM authored and GitHub committed 2026-10-13 20:43:14 -04:00
1 parent 9ab820d7f7
commit ca1d74c49e
3 files changed
+182 -1

No files matched your search

@@ -68,6 +68,7 @@ import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Base64;
@@ -3568,7 +3569,8 @@ public class S3Controller {
private Response checkPreconditions(S3Object obj, String ifMatch, String ifNoneMatch,
String ifModifiedSince, String ifUnmodifiedSince) {
String eTag = obj.getETag();
Instant lastModified = obj.getLastModified();
// Dates compare at second precision, the resolution of an HTTP date and of Last-Modified.
Instant lastModified = obj.getLastModified().truncatedTo(ChronoUnit.SECONDS);
if (ifMatch != null && !eTagMatches(ifMatch, eTag)) {
return preconditionFailedResponse();