You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(storage): sign content-length only on S3 requests with a body - #14523
The S3 device has signed a content-length header on every request since the GCS 411 fix, including bodyless GET/HEAD/DELETE. Cloudflare R2 rejects a GET carrying a signed content-length with 403 SignatureDoesNotMatch, so uploads worked but every read failed. The header is now set (and signed) only on PUT and POST, which keeps the explicit length GCS needs, including on empty multipart-initiation POSTs and copy PUTs. AWS, Backblaze, DOSpaces, Linode and Wasabi extend S3 without overriding call(), so they get the same behaviour.
storage unit suite (phpunit -c packages/storage/phpunit.xml --testsuite unit): 133 tests pass
Captured the outgoing requests with a stub client: PUT/POST send and sign content-length; GET, HEAD and DELETE send neither. Not tested against a live R2 bucket.
🟢 Add a test locking bodyless GET without content-length (ContentLengthTest.php:84) — The new guard sends content-length only on PUT and POST, motivated by Cloudflare R2 rejecting a signed content-length on GET with 403 (packages/storage/src/Device/S3.php:910-919).
The change narrows S3 device request signing to include the content-length header only for methods that carry a body (PUT/POST), keeping the signed header set in sync with what the transport actually sends so R2-compatible providers no longer reject bodyless reads. A new unit test locks the empty-body POST case; the bodyless GET case has no equivalent coverage yet.
Files
Change
packages/storage/src/Device/S3.php
Conditionally sign and send content-length only on PUT/POST requests.
The S3 request builder now adds the explicit signed Content-Length only for PUT and POST, retaining the length needed for S3-compatible writes while omitting it on GET, HEAD, and DELETE. The existing test documentation is updated to describe the PUT/POST scope of the HTTP 411 regression coverage.
Verdict
New comments
Fixed
Still open
✅ Approved
0
0
0
📂 Walkthrough · 2
File
Change
packages/storage/src/Device/S3.php
Gate the explicit Content-Length header to PUT and POST requests.
Update the regression test description to reflect PUT/POST coverage.
Merged main (0f1e945); no changes to this PR's code since d762b9b · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The S3 device has signed a
content-lengthheader on every request since the GCS 411 fix, including bodyless GET/HEAD/DELETE. Cloudflare R2 rejects a GET carrying a signedcontent-lengthwith 403SignatureDoesNotMatch, so uploads worked but every read failed. The header is now set (and signed) only on PUT and POST, which keeps the explicit length GCS needs, including on empty multipart-initiation POSTs and copy PUTs. AWS, Backblaze, DOSpaces, Linode and Wasabi extendS3without overridingcall(), so they get the same behaviour.Verified:
bin/monorepo check storage(Rector, Pint, PHPStan): passesphpunit -c packages/storage/phpunit.xml --testsuite unit): 133 tests passcontent-length; GET, HEAD and DELETE send neither. Not tested against a live R2 bucket.Closes #14326