|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace luya\web; |
|
4
|
|
|
|
|
5
|
|
|
use Yii; |
|
6
|
|
|
use luya\traits\ApplicationTrait; |
|
7
|
|
|
use yii\web\ForbiddenHttpException; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* LUYA Web Application. |
|
11
|
|
|
* |
|
12
|
|
|
* @property \luya\cms\Menu $menu Menu component in order to build navigation from CMS module. |
|
13
|
|
|
* @property \luya\admin\storage\BaseFileSystemStorage $storage Storage component for reading, saving and holding files from the Admin module. |
|
14
|
|
|
* @property \luya\web\Composition $composition Composition component. |
|
15
|
|
|
* @property \luya\web\Element $element The element component. |
|
16
|
|
|
* @property \luya\web\View $view The view component. |
|
17
|
|
|
* @property \luya\web\Request $request The request component. |
|
18
|
|
|
* @property \luya\web\ErrorHandler $errorHandler The error handler component. |
|
19
|
|
|
* @property \luya\admin\components\Jwt $jwt The admin JWT handler component, if enabled in the Admin module. |
|
20
|
|
|
* @property \yii\queue\db\Queue $adminqueue The yii queue component configured for the Admin module. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Basil Suter <[email protected]> |
|
23
|
|
|
* @since 1.0.0 |
|
24
|
|
|
*/ |
|
25
|
|
|
class Application extends \yii\web\Application |
|
26
|
|
|
{ |
|
27
|
|
|
use ApplicationTrait; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @inheritdoc |
|
31
|
|
|
*/ |
|
32
|
|
|
public function handleRequest($request) |
|
33
|
|
|
{ |
|
34
|
|
|
if ($this->ensureSecureConnection && !$request->isSecureConnection) { |
|
35
|
|
|
throw new ForbiddenHttpException("Insecure connection is not allowed."); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
if ($this->ensureSecureConnection) { |
|
39
|
|
|
// add secure flag to cookie |
|
40
|
|
|
Yii::$app->request->csrfCookie = ['httpOnly' => true, 'secure' => true]; |
|
41
|
|
|
Yii::$app->session->cookieParams = ['httpOnly' => true, 'secure' => true]; |
|
42
|
|
|
// apply strict, hsts and x-* headers |
|
43
|
|
|
Yii::$app->response->headers->set('Strict-Transport-Security', 'max-age=31536000'); |
|
44
|
|
|
Yii::$app->response->headers->set('X-XSS-Protection', "1; mode=block"); |
|
45
|
|
|
Yii::$app->response->headers->set('X-Frame-Options', "SAMEORIGIN"); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
return parent::handleRequest($request); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @inheritdoc |
|
53
|
|
|
*/ |
|
54
|
|
|
public function coreComponents() |
|
55
|
|
|
{ |
|
56
|
|
|
return array_merge($this->luyaCoreComponents(), [ |
|
|
|
|
|
|
57
|
|
|
'request' => ['class' => 'luya\web\Request'], |
|
58
|
|
|
'errorHandler' => ['class' => 'luya\web\ErrorHandler'], |
|
59
|
|
|
'urlManager' => ['class' => 'luya\web\UrlManager'], |
|
60
|
|
|
'view' => ['class' => 'luya\web\View'], |
|
61
|
|
|
'element' => ['class' => 'luya\web\Element'], |
|
62
|
|
|
'composition' => ['class' => 'luya\web\Composition'], |
|
63
|
|
|
'assetManager' => [ |
|
64
|
|
|
'class' => 'luya\web\AssetManager', |
|
65
|
|
|
'forceCopy' => YII_DEBUG, |
|
66
|
|
|
'appendTimestamp' => !YII_DEBUG, |
|
67
|
|
|
], |
|
68
|
|
|
]); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.