Skip to content

R2 local S3 endpoint: "Cross-origin requests are always allowed" only after the /cdn-cgi host gate #35249

Open

Description

@mynk-tmr

Page: https://developers.cloudflare.com/r2/local-development/ — "Serve buckets over the S3 API"

The docs say cross-origin requests to the local S3 endpoint are always allowed, as if the bucket had a permissive CORS policy. In practice (wrangler 4.159.0):

  • An OPTIONS preflight with Origin: http://localhost:<port> returns 204 with Access-Control-Allow-Origin: *.
  • The same preflight with any non-localhost Origin (e.g. https://your-app.example.com, even behind a reverse proxy) returns 403 "Invalid Origin header" from Miniflare's /cdn-cgi/* host validation (validateCdnCgiRequest), before the S3 endpoint's permissive CORS is ever reached.

So the "always allowed" statement is true of the S3 layer, but the outer gate makes browser use impossible unless the app itself runs on localhost. Suggest documenting the gate (and pointing to workers-sdk#16423) so developers testing browser uploads against the local endpoint are not surprised by the 403.

Metadata

Metadata

Labels

effort:mediumproduct:r2R2 object storage: https://developers.cloudflare.com/r2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions