Conversation
📝 WalkthroughWalkthroughThis pull request refactors the CORS hostname validation mechanism in Appwrite. The primary change replaces a direct array membership check (in_array) against allowedHosts with a validator-based approach using Utopia\Validator\Hostname. The hostname validator is instantiated with the allowed hosts list and validates incoming hosts against this list. A new unit test verifies that wildcard subdomain patterns (*.example.com) correctly allow subdomains (foo.example.com) and return the appropriate Allow-Origin header value. The change maintains existing lowercasing and wildcard-origin logic throughout the validation process. Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Security Scan Results for PRDocker Image Scan Results
Source Code Scan Results🎉 No vulnerabilities found! |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/Appwrite/Network/Cors.php(2 hunks)tests/unit/Network/CorsTest.php(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
tests/unit/Network/CorsTest.php (1)
src/Appwrite/Network/Cors.php (2)
Cors(14-91)headers(53-90)
src/Appwrite/Network/Cors.php (1)
src/Appwrite/Network/Validator/Origin.php (1)
isValid(31-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Benchmark
- GitHub Check: Setup & Build Appwrite Image
- GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Network/Cors.php (1)
5-5: LGTM: Adding Hostname validator import.The import is correctly added to support the new validator-based hostname matching logic.
tests/unit/Network/CorsTest.php (1)
39-52: The test appropriately validates subdomain wildcard matching. The Hostname validator usesfnmatch()withFNM_CASEFOLDfor pattern matching, which already handles the edge cases correctly:
- Base domain (
example.com) correctly does NOT match*.example.com- Non-matching domains are properly rejected (verified by
testUnlistedOriginReturnsStaticHeadersOnly)- Single-level subdomains (
foo.example.com) match*.example.comas expectedExisting test coverage comprehensively validates CORS behavior including exact domain matches, unlisted origins, invalid URLs, and wildcard patterns. No additional edge-case tests are required.
✨ Benchmark results
⚡ Benchmark Comparison
|
No description provided.