Skip to content

fix(s3): Add Content-MD5 header for DeleteObjects to fix AWS SDK v3.339.0+ compatibility#60195

Open
skjnldsv wants to merge 1 commit intomasterfrom
fix/s3-content-md5-deleteobjects
Open

fix(s3): Add Content-MD5 header for DeleteObjects to fix AWS SDK v3.339.0+ compatibility#60195
skjnldsv wants to merge 1 commit intomasterfrom
fix/s3-content-md5-deleteobjects

Conversation

@skjnldsv
Copy link
Copy Markdown
Member

@skjnldsv skjnldsv commented May 6, 2026

Issue

AWS SDK PHP v3.339.0+ introduced a breaking change requiring the Content-MD5 header for DeleteObjects operations. This causes MissingContentMD5 errors (HTTP 400) when using S3-compatible services like MinIO or when strict compliance is enforced.

Related: aws/aws-sdk-php#3068

Solution

Add middleware to the S3Client handler list that automatically calculates and injects the Content-MD5 header on all DeleteObjects requests. This fix:

  • Applies universally at the S3ConnectionTrait level, covering both external storage (AmazonS3) and core ObjectStore (S3) classes
  • Uses AWS SDK's built-in Middleware API and Utils::hash() for MD5 calculation
  • Checks for existing headers to avoid double-hashing (defensive)
  • Only applies to DeleteObjects operations (query parameter = delete)

Changes

Modified files:

  • lib/private/Files/ObjectStore/S3ConnectionTrait.php
    • Added imports: Aws\Middleware, GuzzleHttp\Psr7\Utils
    • Added addDeleteObjectsContentMd5Middleware() private method that appends middleware to calculate and inject the header
    • Called this method in getConnection() after S3Client instantiation, before bucket verification

New test file:

  • tests/lib/Files/ObjectStore/S3ContentMd5MiddlewareTest.php
    • 7 unit tests covering:
      • Content-MD5 injection on DeleteObjects requests
      • Selective application (no injection for GET, PUT, HEAD, etc.)
      • Existing header preservation (idempotency)
      • MD5 calculation with various payload sizes
      • Base64 encoding validation
      • Empty body edge case
      • Middleware idempotency (no double-hashing)

@skjnldsv skjnldsv requested a review from a team as a code owner May 6, 2026 17:27
@skjnldsv skjnldsv requested review from ArtificialOwl, icewind1991, leftybournes and salmart-dev and removed request for a team May 6, 2026 17:27
@skjnldsv skjnldsv marked this pull request as draft May 6, 2026 17:28
@skjnldsv skjnldsv self-assigned this May 6, 2026
@skjnldsv skjnldsv force-pushed the fix/s3-content-md5-deleteobjects branch 2 times, most recently from f702ac8 to 54efa19 Compare May 6, 2026 17:36
@skjnldsv
Copy link
Copy Markdown
Member Author

skjnldsv commented May 6, 2026

Tested locally on S3, it works.

…39.0+ compatibility

AWS SDK PHP v3.339.0+ introduced a breaking change requiring the Content-MD5
header for DeleteObjects operations. This causes 'MissingContentMD5' errors when
using S3-compatible services like MinIO.

Add middleware to automatically calculate and inject the Content-MD5 header on
all DeleteObjects requests. This is applied universally at the S3ConnectionTrait
level, fixing both external storage (AmazonS3) and core ObjectStore (S3) classes.

Fixes: aws/aws-sdk-php#3068
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
@skjnldsv skjnldsv force-pushed the fix/s3-content-md5-deleteobjects branch from 54efa19 to 9fb8218 Compare May 6, 2026 18:54
@skjnldsv skjnldsv added 3. to review Waiting for reviews and removed 2. developing Work in progress labels May 6, 2026
@skjnldsv skjnldsv marked this pull request as ready for review May 6, 2026 18:55
@skjnldsv skjnldsv requested review from artonge and provokateurin May 6, 2026 18:55
@skjnldsv
Copy link
Copy Markdown
Member Author

skjnldsv commented May 6, 2026

/backport to stable33 please

@skjnldsv
Copy link
Copy Markdown
Member Author

skjnldsv commented May 6, 2026

/backport to stable32 please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant