Skip to content

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

Merged
skjnldsv merged 2 commits into
masterfrom
fix/s3-content-md5-deleteobjects
May 12, 2026
Merged

fix(s3): Add Content-MD5 header for DeleteObjects to fix AWS SDK v3.339.0+ compatibility#60195
skjnldsv merged 2 commits into
masterfrom
fix/s3-content-md5-deleteobjects

Conversation

@skjnldsv

@skjnldsvskjnldsv commented May 6, 2026

Copy link
Copy Markdown
Member

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 ownerMay 6, 2026 17:27
@skjnldsv
skjnldsv requested review from ArtificialOwl, icewind1991, leftybournes and salmart-dev and removed request for a teamMay 6, 2026 17:27
@skjnldsv
skjnldsv marked this pull request as draft May 6, 2026 17:28
@skjnldsvskjnldsv self-assigned this May 6, 2026
@skjnldsv
skjnldsvforce-pushed the fix/s3-content-md5-deleteobjects branch 2 times, most recently from f702ac8 to 54efa19CompareMay 6, 2026 17:36
@skjnldsv

Copy link
Copy Markdown
MemberAuthor

Tested locally on S3, it works.

@skjnldsv
skjnldsvforce-pushed the fix/s3-content-md5-deleteobjects branch from 54efa19 to 9fb8218CompareMay 6, 2026 18:54
@skjnldsvskjnldsv 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

Copy link
Copy Markdown
MemberAuthor

/backport to stable33 please

@skjnldsv

Copy link
Copy Markdown
MemberAuthor

/backport to stable32 please

@provokateurin
provokateurin removed their request for review May 7, 2026 08:00
Comment threadlib/private/Files/ObjectStore/S3ConnectionTrait.php Outdated
@skjnldsv
skjnldsvforce-pushed the fix/s3-content-md5-deleteobjects branch 2 times, most recently from ba36081 to c33cdc4CompareMay 7, 2026 08:46
Comment threadlib/private/Files/ObjectStore/S3ConnectionTrait.php Outdated
@skjnldsv
skjnldsv requested a review from artongeMay 7, 2026 08:54
Comment threadtests/lib/Files/ObjectStore/S3ContentMd5MiddlewareTest.php
@skjnldsv
skjnldsvforce-pushed the fix/s3-content-md5-deleteobjects branch from 5ecb17c to 5de4accCompareMay 7, 2026 12:17
@skjnldsvskjnldsv added 4. to release Ready to be released and/or waiting for tests to finish and removed 3. to review Waiting for reviews labels May 7, 2026
skjnldsvand others added 2 commits May 12, 2026 09:07
…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>
Co-authored-by: Louis <louis@chmn.me>
Signed-off-by: John Molakvoæ <skjnldsv@users.noreply.github.com>
@skjnldsv
skjnldsvforce-pushed the fix/s3-content-md5-deleteobjects branch from 5de4acc to ee602dcCompareMay 12, 2026 07:07
@skjnldsv
skjnldsv merged commit 15db84f into masterMay 12, 2026
198 of 206 checks passed
@skjnldsv
skjnldsv deleted the fix/s3-content-md5-deleteobjects branch May 12, 2026 09:36
This was referenced May 12, 2026
@nextcloud-botnextcloud-bot mentioned this pull request May 20, 2026
@nextcloud-botnextcloud-bot mentioned this pull request May 27, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

4. to releaseReady to be released and/or waiting for tests to finishbugfeature: external storagefeature: object storage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@skjnldsv@artonge@CarlSchwan