fix: add WAF rule for CORS preflight OPTIONS requests#41
Merged
takaokouji merged 1 commit intomainfrom Jan 18, 2026
Merged
Conversation
- Added AllowPreflightOptions rule (priority: 0) to allow OPTIONS requests - Fixed SingleHeader property name (name → Name) - Fixed TextTransformationType (UPPERCASE → NONE for method matching) - Ensures AppSync can return CORS headers for preflight requests This fixes the CORS error reported on Chromebook when connecting to production mesh v2 API (https://graphql.api.smalruby.app/graphql). WAF rules now properly handle: 1. Preflight OPTIONS requests from allowed origins (priority 0) 2. Regular POST requests from allowed origins (priority 1) 3. Block all other requests (default action) Tested on stg2 environment: - OPTIONS from https://smalruby.app → 200 + CORS headers ✅ - POST from https://smalruby.app → 200 + data ✅ - POST from https://example.com → 403 (blocked) ✅ Fixes #30 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ChromebookでmeshV2に接続する際のCORSエラーを修正しました。WAFにpreflight OPTIONSリクエスト用のルールを追加しています。
Changes
WAF Rule Addition (
infra/mesh-v2/lib/mesh-v2-stack.ts)AllowPreflightOptions (priority: 0) - NEW
OPTIONShttps://smalruby.appまたはhttps://smalruby.jpAllowSpecificOrigins (priority: 1) - UPDATED
name→Name(CloudFormation仕様に準拠)Implementation Details
Fixed Issues
SingleHeaderプロパティ名をNameに修正(CloudFormation仕様)TextTransformationTypeをNONEに変更(メソッドマッチング用)WAF Rule Behavior
Note: AppSyncはOPTIONSリクエストに対して
access-control-allow-origin: *を返しますが、実際のPOSTリクエストはWAFでOriginチェックされます。Test Results (stg2 environment)
✅ preflight OPTIONS from
https://smalruby.app✅ POST request from
https://smalruby.app✅ POST request from unauthorized origin
Deployment
この変更は本番環境 (prod) のみに適用されます(
if (stage === 'prod'))。Deployment Command
cd infra/mesh-v2 npx cdk deploy --context stage=prodPost-Deployment Verification
Related Issue
Fixes #30
🤖 Generated with Claude Code