Skip to content

Commit f65263c

Browse files
committed
exposed headers
1 parent 3d2d44b commit f65263c

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

src/Config/RestFul.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ class RestFul extends BaseConfig
206206
* Set to TRUE to enable Cross-Origin Resource Sharing (CORS) from any
207207
* source domain
208208
*/
209-
public bool $allowAnyCorsDomain = true;
209+
public bool $allowAnyCorsDomain = false;
210210

211211
/**
212212
* --------------------------------------------------------------------------
@@ -261,7 +261,7 @@ class RestFul extends BaseConfig
261261
| http://docs.sencha.com/extjs/6.5.2/classic/Ext.data.proxy.Rest.html#cfg-withCredentials
262262
|
263263
*/
264-
public array $forcedCorsHeaders = [ 'Access-Control-Allow-Credentials' => 'true' ];
264+
public bool $supportsCredentials = false;
265265

266266
/**
267267
* --------------------------------------------------------------------------

src/Validators/Cors.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public static function check(ResponseInterface &$response)
4040
$response->setHeader('Access-Control-Allow-Headers', $allowedCorsHeaders);
4141
$response->setHeader('Access-Control-Allow-Methods', $allowedCorsMethods);
4242

43-
$forcedheaders = service('settings')->get('RestFul.forcedCorsHeaders');
44-
// If there are headers that should be forced in the CORS check, add them now
45-
if (is_array($forcedheaders)) {
46-
foreach ($forcedheaders as $header => $value) {
47-
$response->setHeader($header, $value);
48-
}
43+
$response->setHeader('Access-Control-Expose-Headers', implode(', ', service('settings')->get('RestFul.exposedCorsHeaders')));
44+
45+
if (service('settings')->get('RestFul.corsMaxAge') !== null) {
46+
$response = $response->setHeader('Access-Control-Max-Age', (string) service('settings')->get('RestFul.corsMaxAge'));
47+
}
48+
49+
if (service('settings')->get('RestFul.supportsCredentials')) {
50+
$response = $response->setHeader('Access-Control-Allow-Credentials', 'true');
4951
}
5052

5153
}

tests/Validators/CorsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testCorsAllowCustomDomainError(): void
7070
$result = $this->call('get', 'example');
7171

7272
$result->assertHeaderMissing('Access-Control-Allow-Origin');
73-
$result->assertHeader('Access-Control-Allow-Credentials');
73+
$result->assertHeaderMissing('Access-Control-Allow-Credentials');
7474
}
7575

7676
public function testCorsOptionsMethodError(): void

0 commit comments

Comments
 (0)