Skip to content

fix(storage): sign content-length only on S3 requests with a body - #14523

Merged
HarshMN2345 merged 3 commits into
mainfrom
fix-s3-bodyless-content-length
Oct 29, 2026
Merged

HarshMN2345 merged 3 commits into
mainfrom
fix-s3-bodyless-content-length

Conversation

@HarshMN2345

Copy link
Copy Markdown
Member

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.

Verified:

  • bin/monorepo check storage (Rector, Pint, PHPStan): passes
  • 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.

Closes #14326

@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. No blocking issues — approved ✅; 1 nitpick below.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 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.
packages/storage/tests/Device/S3/ContentLengthTest.php Add tests covering streamed PUT and empty-body POST content-length handling.

Reviewed commit: 9e5be45

@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

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.
packages/storage/tests/Device/S3/ContentLengthTest.php 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.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

6 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (3)
  • php.appwrite.secret-compare-timing (1)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-s3-bodyless-content-length (after).

Metric Before After Change
🚀 Requests/sec 189.62 178.59 🔴 -5.8%
⏱️ Latency P50 90.21 ms 97.31 ms 🔴 +7.9%
⏱️ Latency P95 212.5 ms 224.16 ms 🔴 +5.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 97.31 224.16 11,400 178.59 +11.66
Account 189.53 331.04 600 10.02 +7.95
TablesDB 94.38 173.6 6,200 99.7 +11.38
Storage 89.53 204.16 3,000 49.94 -1.54
Functions 139.29 260.37 1,600 27.3 +21.11

Top API waits (after)

API request Max wait (ms)
storage.buckets.create 498.02
account.name.update 446.7
functions.delete 411.24
functions.variables.update 391.11
account.prefs.update 385.07

@HarshMN2345
HarshMN2345 merged commit b92b699 into main Oct 29, 2026
68 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: S3 device signs content-length on bodyless GET/HEAD, breaks R2 reads (403 SignatureDoesNotMatch)

1 participant