Skip to content

Commit b6920bd

Browse files
authored
Fix Access-Control-Allow-Origin null bug (#86)
1 parent 8d8f88b commit b6920bd

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Bug with `Access-Control-Allow-Origin` header is `null` then `allowedOrigins` is `['*']`, `supportsCredentials` is `true` and `Origin` header doesn't set (#85)
13+
1014
## [2.0.0] - 2020-05-11
1115

1216
### Added

src/CorsService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private function configureAllowedOrigin(Response $response, Request $request)
146146
$response->headers->set('Access-Control-Allow-Origin', array_values($this->options['allowedOrigins'])[0]);
147147
} else {
148148
// For dynamic headers, check the origin first
149-
if ($this->isOriginAllowed($request)) {
149+
if ($request->headers->has('Origin') && $this->isOriginAllowed($request)) {
150150
$response->headers->set('Access-Control-Allow-Origin', $request->headers->get('Origin'));
151151
}
152152

tests/CorsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,21 @@ public function it_skips_empty_access_control_request_header()
518518
$this->assertEquals(204, $response->getStatusCode());
519519
}
520520

521+
/**
522+
* @test
523+
*/
524+
public function it_doesnt_set_access_control_allow_origin_without_origin()
525+
{
526+
$app = $this->createStackedApp([
527+
'allowedOrigins' => ['*'],
528+
'supportsCredentials' => true,
529+
]);
530+
531+
$response = $app->handle(new Request);
532+
533+
$this->assertFalse($response->headers->has('Access-Control-Allow-Origin'));
534+
}
535+
521536
private function createValidActualRequest()
522537
{
523538
$request = new Request();

0 commit comments

Comments
 (0)