Skip to content

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

Closed

Description

@ridhotamma

πŸ› 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

  1. 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, no https://), plus the R2 token's access/secret key.
  2. Upload an image via Console β†’ Storage (succeeds; object visible in the R2 bucket).
  3. Download or preview the same file β†’ fails with 403 SignatureDoesNotMatch
    (Internal server error / download failed with status 403 in 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/HEAD

R2 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

  1. ridhotamma commented on Oct 10, 2026

    @ridhotamma
    Author

    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).

  2. added
    product / self-hosted
    product / storage
    on Oct 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    product / self-hostedproduct / storage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions