Skip to content

Commit 1be83de

Browse files
authored
Merge pull request #1846
* chore: Set X-Frame options and CSP. Thanks to @lengochoa7112000 !! * chore: Update dependencies. * chore: Bump version number.
1 parent 0ea0a13 commit 1be83de

File tree

3 files changed

+74
-47
lines changed

3 files changed

+74
-47
lines changed

composer.lock

+30-29
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/SP/Bootstrap.php

+42-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?php
2-
/**
2+
/*
33
* sysPass
44
*
5-
* @author nuxsmin
6-
* @link https://syspass.org
7-
* @copyright 2012-2019, Rubén Domínguez nuxsmin@$syspass.org
5+
* @author nuxsmin
6+
* @link https://syspass.org
7+
* @copyright 2012-2022, Rubén Domínguez nuxsmin@$syspass.org
88
*
99
* This file is part of sysPass.
1010
*
@@ -19,7 +19,7 @@
1919
* GNU General Public License for more details.
2020
*
2121
* You should have received a copy of the GNU General Public License
22-
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
22+
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
2323
*/
2424

2525
namespace SP;
@@ -91,10 +91,6 @@ final class Bootstrap
9191
* @var Klein
9292
*/
9393
private $router;
94-
/**
95-
* @var Language
96-
*/
97-
private $language;
9894
/**
9995
* @var Request
10096
*/
@@ -127,7 +123,6 @@ private final function __construct(Container $container)
127123
$this->configData = $this->config->getConfigData();
128124
$this->router = $container->get(Klein::class);
129125
$this->request = $container->get(Request::class);
130-
$this->language = $container->get(Language::class);
131126

132127
$this->initRouter();
133128
}
@@ -161,22 +156,31 @@ function ($request, $response, $service) use ($oops) {
161156
list($controller, $action) = explode('/', $apiRequest->getMethod());
162157

163158
$controllerClass = 'SP\\Modules\\' . ucfirst(APP_MODULE) . '\\Controllers\\' . ucfirst($controller) . 'Controller';
164-
$method = $action . 'Action';
159+
$method = $action.'Action';
165160

166161
if (!method_exists($controllerClass, $method)) {
167-
logger($controllerClass . '::' . $method);
162+
logger($controllerClass.'::'.$method);
168163

169164
/** @var Response $response */
170165
$response->headers()->set('Content-type', 'application/json; charset=utf-8');
171-
return $response->body(JsonRpcResponse::getResponseError($oops, JsonRpcResponse::METHOD_NOT_FOUND, $apiRequest->getId()));
166+
167+
return $response->body(
168+
JsonRpcResponse::getResponseError(
169+
$oops,
170+
JsonRpcResponse::METHOD_NOT_FOUND,
171+
$apiRequest->getId()
172+
)
173+
);
172174
}
173175

176+
$this->setCors($response);
177+
174178
$this->initializeCommon();
175179

176180
self::$container->get(InitApi::class)
177181
->initialize($controller);
178182

179-
logger('Routing call: ' . $controllerClass . '::' . $method);
183+
logger('Routing call: '.$controllerClass.'::'.$method);
180184

181185
return call_user_func([new $controllerClass(self::$container, $method, $apiRequest), $method]);
182186
} catch (\Exception $e) {
@@ -216,14 +220,17 @@ function ($request, $response, $service) use ($oops) {
216220
$this->initializePluginClasses();
217221

218222
if (!method_exists($controllerClass, $methodName)) {
219-
logger($controllerClass . '::' . $methodName);
223+
logger($controllerClass.'::'.$methodName);
220224

221225
/** @var Response $response */
222226
$response->code(404);
223227

224228
throw new RuntimeException($oops);
225229
}
226230

231+
$this->setCors($response);
232+
$this->setXFrame($response);
233+
227234
$this->initializeCommon();
228235

229236
switch (APP_MODULE) {
@@ -291,7 +298,7 @@ protected function initializeCommon()
291298
if (!self::$checkPhpVersion) {
292299
throw new InitializationException(
293300
sprintf(__('Required PHP version >= %s <= %s'), '7.3', '7.4'),
294-
InitializationException::ERROR,
301+
Core\Exceptions\SPException::ERROR,
295302
__u('Please update the PHP version to run sysPass')
296303
);
297304
}
@@ -473,4 +480,23 @@ public static function run(Container $container, $module = APP_MODULE)
473480
throw new InitializationException('Unknown module');
474481
}
475482
}
483+
484+
protected function setCors(Response $response): void
485+
{
486+
$response->header(
487+
'Access-Control-Allow-Origin',
488+
$this->configData->getApplicationUrl() ?? $this->request->getHttpHost()
489+
);
490+
$response->header(
491+
'Access-Control-Allow-Headers',
492+
'X-Requested-With, Content-Type, Accept, Origin, Authorization'
493+
);
494+
$response->header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS');
495+
}
496+
497+
protected function setXFrame(Response $response): void
498+
{
499+
$response->header('X-FRAME-OPTIONS', 'DENY');
500+
$response->header('Content-Security-Policy', 'frame-ancestors \'none\'');
501+
}
476502
}

lib/SP/Services/Install/Installer.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ final class Installer extends Service
6060
/**
6161
* sysPass' version and build number
6262
*/
63-
const VERSION = [3, 2, 8];
63+
const VERSION = [3, 2, 9];
6464
const VERSION_TEXT = '3.2';
65-
const BUILD = 22061802;
65+
const BUILD = 22062501;
6666

6767
/**
6868
* @var DatabaseSetupInterface

0 commit comments

Comments
 (0)