- Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: improve CORS validation with AWS S3 format detection #10111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: improve CORS validation with AWS S3 format detection #10111
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
🦋 Changeset detectedLatest commit: 728ae1d The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
| Failed to automatically backport this PR's changes to Wrangler v3. Please manually create a PR targeting the Depending on your changes, running Notes:
|
packages/wrangler/package.json Outdated
| "unenv": "2.0.0-rc.19", | ||
| "workerd": "1.20250726.0" | ||
| "workerd": "1.20250726.0", | ||
| "zod": "^4.0.13" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment: zod is used in miniflare so maybe we should add & use a catalog version - miniflare uses 3.22.3
| Please can you rebase and fix the conflicts on this PR. |
20a9f68 to ad0336e Compare | Please can you rebase and fix the conflicts on this PR. |
- Add comprehensive validation for R2 CORS configuration files - Detect AWS S3 format and provide conversion example - Validate rule structure with specific error messages - Add tests for various validation scenarios Fixes #8486 Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
- Add missing import for 'join' from 'node:path' in r2.test.ts - Fix unused parameter linting issue in validateCORSRules function - All linting and type checks now pass Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
- Change AWS S3 format detection test regex from '/AWS S3 format.*Cloudflare R2 format/' to '/in AWS S3 format.*Cloudflare R2 expects/' - Test now passes locally and matches the actual error message format Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
…or messages to template literals - Move runInTempDir() call to describe level following established patterns - Convert concatenated error messages to single template literals for better readability - Remove unused 'join' import from path module - Fix all syntax errors in test implementation - All 107 R2 tests now pass locally Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
…detection - Replace custom validation logic with zod schemas for better type safety - Maintain AWS S3 format detection and helpful conversion examples - Update test expectations to match zod's error message formats - All 107 R2 tests passing locally Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
- Add changeset for zod refactoring (patch version bump) - Fix test formatting issues identified by prettier Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
Address GitHub comment feedback to focus on user benefits rather than implementation details Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
…n to use schema-based approach - Update zod dependency from ^4.0.13 to 3.22.3 to match miniflare version - Fix naming inconsistency: AwsS3CorsSchema -> AwsS3CORSSchema - Refactor manual 'rules' property validation to use zod .refine() method - Update test expectations to match zod 3.22.3 error message formats - All 107 R2 tests pass with the aligned zod version Addresses GitHub comments from vicb about naming consistency and schema-based validation. Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
Co-Authored-By: eshen@cloudflare.com <emilyshen2k@gmail.com>
ad0336e to 728ae1d Compare
feat: implement comprehensive CORS validation with AWS S3 format detection using zod
Summary
This PR implements comprehensive validation for the
wrangler r2 bucket cors setcommand to address GitHub issue #8486. The key improvements include:The validation function detects AWS S3 format by checking for fields like
AllowedOrigins,AllowedMethods, etc., and provides a converted example in the error message. It also validates rule structure, data types (ensuringmaxAgeSecondsis a non-negative integer), and array contents (ensuring all items are strings).Review & Testing Checklist for Human
wrangler r2 bucket cors setcommand with various CORS configuration files (AWS S3 format, valid R2 format, invalid formats) to ensure validation works correctly in practiceRecommended test plan: Create sample CORS files in AWS S3 format, valid R2 format, and various invalid formats, then run
wrangler r2 bucket cors set test-bucket --file <cors-file>to verify the validation behavior matches expectations.Diagram
%%{ init : { "theme" : "default" }}%% graph TD CLI["wrangler r2 bucket cors set"] CorsCommand["packages/wrangler/src/r2/cors.ts<br/>r2BucketCORSSetCommand"]:::major-edit ValidateFunc["packages/wrangler/src/r2/helpers.ts<br/>validateCORSRules()"]:::major-edit Tests["packages/wrangler/src/__tests__/r2.test.ts<br/>CORS validation tests"]:::major-edit API["Cloudflare R2 API"]:::context CLI --> CorsCommand CorsCommand --> ValidateFunc ValidateFunc --> API Tests -.-> ValidateFunc CorsCommand --> |"reads JSON file<br/>calls validation"| ValidateFunc ValidateFunc --> |"throws UserError<br/>if invalid"| CorsCommand ValidateFunc --> |"returns validated<br/>rules if valid"| API subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
Session details: Requested by @emily-shen
Link to Devin run: https://app.devin.ai/sessions/4a61736e21ab4a3f9a708d833a99ff6c