Fix CORS allow-all middleware - #27
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes CorsAllowAllMiddleware to produce CORS headers that comply with the Fetch/CORS protocol (especially when credentials are involved) and adds optional preflight short-circuiting via a PSR-17 response factory, with accompanying docs, tests, and changelog entry.
Changes:
- Reflect request origin when credentials are enabled and avoid invalid
Allow-Origin: *+Allow-Credentials: truecombinations. - Add optional preflight (
OPTIONS+Access-Control-Request-Method) short-circuiting with a PSR-17ResponseFactoryInterface. - Update documentation, changelog, and tests for both constructor compatibility paths.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/CorsAllowAllMiddleware.php | Updates CORS header logic and introduces optional preflight short-circuiting via PSR-17 response factory. |
| tests/CorsAllowAllMiddlewareTest.php | Adds tests for credentialed requests, preflight behavior, and constructor compatibility. |
| docs/guide/en/cors-allow-all-middleware.md | Documents the optional response factory for preflight short-circuiting. |
| CHANGELOG.md | Records the bugfix and preflight-handling change under the upcoming release. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #27 +/- ##
===========================================
Coverage 100.00% 100.00%
- Complexity 100 112 +12
===========================================
Files 23 23
Lines 253 274 +21
===========================================
+ Hits 253 274 +21 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Suppressed comments (1)
src/CorsAllowAllMiddleware.php:52
$exposedHeadersis computed for every request, but it’s only used when a singleOriginis present. For the common$origin === ''path (no/invalid Origin), this loop does unnecessary work before returning wildcard headers.
$exposedHeaders = [];
/** @var array<string, string[]> $headers */
$headers = $response->getHeaders();
foreach ($headers as $name => $_) {
if (strtolower($name) !== 'set-cookie') {
Fixes #24.
Checks: