Skip to content

Commit 2c1c621

Browse files
tangixchriskacerguis
authored andcommitted
Add config to force CORS pre-flight headers to be included (chriskacerguis#886)
* Added config option to force setting of CORS pre-flight headers. * Updated the setting to be empty by default and updated the comment.
1 parent 579885a commit 2c1c621

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

application/config/rest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,3 +604,24 @@
604604
|
605605
*/
606606
$config['allowed_cors_origins'] = [];
607+
608+
/*
609+
|--------------------------------------------------------------------------
610+
| CORS Forced Headers
611+
|--------------------------------------------------------------------------
612+
|
613+
| If using CORS checks, always include the headers and values specified here
614+
| in the OPTIONS client preflight.
615+
| Example:
616+
| $config['forced_cors_headers'] = [
617+
| 'Access-Control-Allow-Credentials' => 'true'
618+
| ];
619+
|
620+
| Added because of how Sencha Ext JS framework requires the header
621+
| Access-Control-Allow-Credentials to be set to true to allow the use of
622+
| credentials in the REST Proxy.
623+
| See documentation here:
624+
| http://docs.sencha.com/extjs/6.5.2/classic/Ext.data.proxy.Rest.html#cfg-withCredentials
625+
|
626+
*/
627+
$config['forced_cors_headers'] = [];

application/libraries/REST_Controller.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,15 @@ protected function _check_cors()
23332333
}
23342334
}
23352335

2336+
// If there are headers that should be forced in the CORS check, add them now
2337+
if (is_array($this->config->item('forced_cors_headers')))
2338+
{
2339+
foreach ($this->config->item('forced_cors_headers') as $header => $value)
2340+
{
2341+
header($header . ': ' . $value);
2342+
}
2343+
}
2344+
23362345
// If the request HTTP method is 'OPTIONS', kill the response and send it to the client
23372346
if ($this->input->method() === 'options')
23382347
{

0 commit comments

Comments
 (0)