Skip to content

fix(wrangler): improve R2 CORS validation and error messaging#12456

Merged
petebacondarwin merged 5 commits intocloudflare:mainfrom
venkatnikhilm:fix/r2-cors-validation
Apr 15, 2026
Merged

fix(wrangler): improve R2 CORS validation and error messaging#12456
petebacondarwin merged 5 commits intocloudflare:mainfrom
venkatnikhilm:fix/r2-cors-validation

Conversation

@venkatnikhilm
Copy link
Copy Markdown
Contributor

@venkatnikhilm venkatnikhilm commented Feb 6, 2026

This PR addresses #8486 by adding local validation to the r2 bucket cors set command.

Previously, users providing AWS S3-formatted CORS files (using CORSRules or PascalCase keys like AllowedOrigins) would receive a generic 10040 API error from the server. This PR intercepts these common formatting mistakes locally, providing a descriptive error message and a link to the correct Cloudflare R2 documentation.

Validation conducted:

  • Manual Test (AWS Format): Verified that a file containing CORSRules or AllowedOrigins triggers the new custom error message.
  • Manual Test (R2 Format): Verified that a correctly formatted R2 CORS file passes validation and proceeds to the API call.
  • Linting/Types: Successfully ran pnpm run check --filter wrangler in the project root with 0 errors.

Changes:

  • Modified packages/wrangler/src/r2/cors.ts to include a validation layer using parseJSON.

  • Added detection for AWS-specific top-level keys and PascalCase property keys.

  • Included an official documentation link in the error output.

  • Tests

    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation

    • Cloudflare docs PR(s):
    • Documentation not necessary because: this change improves error messaging by providing a direct link to the existing official Cloudflare R2 CORS documentation within the CLI output itself.

Open with Devin

@venkatnikhilm venkatnikhilm requested a review from a team as a code owner February 6, 2026 23:14
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Feb 6, 2026

🦋 Changeset detected

Latest commit: a960018

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

devin-ai-integration[bot]

This comment was marked as resolved.

@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/r2/bucket.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/r2/cors.ts: [@cloudflare/wrangler]

@workers-devprod
Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • @cloudflare/wrangler
Show detailed file reviewers
  • packages/wrangler/src/tests/r2/bucket.test.ts: [@cloudflare/wrangler]
  • packages/wrangler/src/r2/cors.ts: [@cloudflare/wrangler]

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Mar 23, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12456

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12456

miniflare

npm i https://pkg.pr.new/miniflare@12456

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12456

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12456

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12456

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12456

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12456

wrangler

npm i https://pkg.pr.new/wrangler@12456

commit: a960018

@venkatnikhilm venkatnikhilm changed the title [wrangler] fix: improve R2 CORS validation and error messaging fix(wrangler): improve R2 CORS validation and error messaging Mar 26, 2026
@workers-devprod
Copy link
Copy Markdown
Contributor

workers-devprod commented Apr 15, 2026

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@petebacondarwin petebacondarwin requested review from a team and petebacondarwin and removed request for a team April 15, 2026 06:52
Copy link
Copy Markdown
Contributor

@workers-devprod workers-devprod left a comment

Choose a reason for hiding this comment

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

Codeowners reviews satisfied

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Apr 15, 2026
@petebacondarwin petebacondarwin merged commit 59eec63 into cloudflare:main Apr 15, 2026
60 of 62 checks passed
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Apr 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants