Repository navigation
Description
π Bug Report: S3 storage device signs content-length on bodyless GET/HEAD β breaks Cloudflare R2 reads (403 SignatureDoesNotMatch)
Current Behavior
On Appwrite 2.4.0 with the Storage S3 device pointed at Cloudflare R2, uploads succeed (the object lands in the bucket) but every read fails: file download/preview in Console, and the Functions/Sites build-source fetch (download failed with status 403). Server logs show S3 SignatureDoesNotMatch (403).
Repro Steps
- Configure the instance for R2 (Appwrite 1.7.0+ endpoint override):
β_APP_STORAGE_DEVICE=s3,β_APP_STORAGE_S3_REGION=auto,
β_APP_STORAGE_S3_BUCKET=<bucket>,
β_APP_STORAGE_S3_ENDPOINT=<account-id>.r2.cloudflarestorage.com
(host only, nohttps://), plus the R2 token's access/secret key. - Upload an image via Console β Storage (succeeds; object visible in the R2 bucket).
- Download or preview the same file β fails with 403
SignatureDoesNotMatch
(Internal server error/download failed with status 403in the UI).
Why the credentials are not at fault
The identical endpoint/region/bucket/keys work when signed by aws CLI / boto3.
Only requests signed by Appwrite's bundled driver fail, and only reads β
the PUT succeeds while the follow-up GET/HEAD does not.
Root cause
packages/storage/src/Device/S3.php, call() sets and signs these on every
request, including bodyless GET/HEAD:
$headers['content-md5'] = $md5;
$headers['content-length'] = (string) $length; // "0" on GET/HEADR2 rejects a signed content-length on a GET with 403 SignatureDoesNotMatch.
(AWS-style signers, e.g. botocore, don't sign these headers on bodyless requests.)
Expected Behavior
GET/HEAD (and any other bodyless request) should not carry a signed
content-length (nor a content-md5 of the empty body). PUT/POST behavior
must stay as-is β the explicit signed Content-Length exists so S3-compatible
services such as GCS don't reject requests with HTTP 411.
Proposed fix
Gate the header so it only applies to requests that carry a body:
if ($method !== Method::GET && $method !== Method::HEAD) {
$headers['content-length'] = (string) $length;
}I have this running on a self-hosted 2.4.0 instance (patched inside the
appwrite container + docker compose restart appwrite): upload β download /
preview round-trips pass against R2, and PUT/POST paths are untouched.
Environment
- Appwrite 2.4.0, self-hosted Docker (
appwrite/appwrite:2.4.0) - Storage backend: Cloudflare R2 (S3-compatible, region
auto), private bucket - Client: Console Storage UI + Functions/Sites build fetch
Activity
ridhotamma commentedon Oct 10, 2026
I would like to work on this β please assign it to me. I have a tested fix ready (gate the signed content-length so it only applies to requests with a body, keeping PUT/POST behavior for GCS 411 compat).